리눅스를 설치하다 보면 매번 USB를 굽고, 설치를 하고 repo를 설정하고 방화벽을 끄고 여러 파일의 설정을 하는 등 반복되는 작업을 하게 되는 경우가 있습니다. 이럴 때 이미 설정한 값 그대로 OS를 다시 설치되었으면 좋겠다는 생각을 하곤 합니다.
Kickstart 란?
Red Hat 에서 개발한 Linux 자동 설치 도구입니다. 설치에 필요한 설정(언어, 시간대, 파티션 등)을 미리 구성 파일에 정의하여 설치 과정을 자동화 할 수 있습니다. 지금 부터 그 과정을 살펴보겠습니다.
1. 설치 미디어 준비
rhel 9.4를 기준으로 진행하겠습니다. 먼저 설치 미디어 iso 파일을 준비한 뒤 rufus 파일을 이용해 설치용 USB를 만들어 줍니다.
2. 설정 파일 수정
세팅하고자 하는 값들을 미리 넣어둘 파일을 작성해야 합니다. 이미 설치 된 linux 에 들어가보면 /root/anaconda.cfg 라는 파일이 있는데 보통 이 파일을 수정하여 사용하는게 편합니다.
다음과 같이 구성되어 있습니다.
/root/anaconda.cfg
# Generated by Anaconda 34.25.4.9
# Generated by pykickstart v3.32
#version=RHEL9
# Use graphical install
graphical
repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-hdd-device/AppStream
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
# Keyboard layouts
keyboard --xlayouts='us'
# System language
lang en_US.UTF-8 //원하는 언어 선택
# Use hard drive installation media
harddrive --dir= --partition=LABEL=RHEL-9-4-0-
%packages //설치하고자 하는 pakage 선택, 여기서는 gui, performance, system-tools 만 선택했습니다.
@^graphical-server-environment
@performance
@system-tools
%end
%post //이곳에는 설치 후 실행 될 script 를 넣으시면 됩니다. 예시로 repo 파일을 자동으로 작성하는 script를 넣어 두었습니다.
cat <<EOF | sudo tee /etc/yum.repos.d/local.repo
[local-BaseOS]
name=Local BaseOS
baseurl=file:///localrepo/BaseOS
enabled=1
gpgcheck=0
[local-AppStream]
name=Local AppStream
baseurl=file:///localrepo/AppStream
enabled=1
gpgcheck=0
EOF
%end
# Run the Setup Agent on first boot
firstboot --enable
# Generated using Blivet version 3.6.0
ignoredisk --only-use=sda,sdb
# System bootloader configuration
bootloader --append="crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information //기존에 설정된 anaconda.cfg의 내용, partname, filesystem, size, ondisk, vg, lv를 미리 적용시켜 줄 수 있습니다. 만약 비워둔다면 설치중에 파티션 설정은 수동으로 해주어야 합니다.
part /boot/efi --fstype="efi" --ondisk=sda --size=600 --fsoptions="umask=0077,shortname=winnt"
part pv.589 --fstype="lvmpv" --ondisk=sdb --size=1143453
part /boot --fstype="xfs" --ondisk=sda --size=1024
part pv.240 --fstype="lvmpv" --ondisk=sda --size=569624
volgroup datavg --pesize=4096 pv.589
volgroup rootvg --pesize=4096 pv.240
logvol / --fstype="xfs" --size=536852 --name=lvroot --vgname=rootvg
logvol swap --fstype="swap" --size=32768 --name=lvswap --vgname=rootvg
logvol /data --fstype="xfs" --size=1143452 --name=data --vgname=datavg
# System timezone //시간대 설정
timezone Asia/Seoul --utc
# Root password //root,admin 계정을 생성하고 비밀번호를 root123 으로 설정했습니다. 설치 후 변경 해주어야 합니다.
rootpw --iscrypted --allow-ssh $6$Tv8JQspS3zN5UNAP$5dXSPpNUMpQf6edjIKclpj2h67Ao.5sgz0TNg8EmWr1JEJtBsT5S.jE4HzrrUtBlXbZESlcrq2jK6TWJpM/oW.
user --name=admin --password=$6$3lKIrP7S5P4SxsVc$xxYfpe/VN4tkYQzkGOjSagFUDLFB4I9sjkQZ62VfkMmnkVMEsW8zOGhSUl4k9HrfME1nE6CEUfCOx4auZkz/Z0 --iscrypted --gecos="admin"
이 파일 내용을 만들어둔 부팅 USB 파일로 이동시켜줍니다. 최상위 디렉토리로 이동시켜주면 됩니다.
3. grub 파일 수정
설정파일을 기반으로 설치를 진행하도록 grub 파일을 수정해주어야 합니다.
\efi\boot\grub.cfg
set default="1"
function load_video {
insmod efi_gop
insmod efi_uga
insmod video_bochs
insmod video_cirrus
insmod all_video
}
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
set timeout=60
### END /etc/grub.d/00_header ###
search --no-floppy --set=root -l 'RHEL-9-4-0-'
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Red Hat Enterprise Linux 9.4' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.repo=hd:LABEL=RHEL-9-4-0- quiet
initrdefi /images/pxeboot/initrd.img
}
menuentry 'Test this media & install Red Hat Enterprise Linux 9.4' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.repo=hd:LABEL=RHEL-9-4-0- rd.live.check quiet
initrdefi /images/pxeboot/initrd.img
}
//이 부분만 추가!
menuentry 'Kick Start Install' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.repo=hd:LABEL=RHEL-9-4-0- rd.live.check inst.ks=hd:LABEL=RHEL-9-4-0-:/ks.cfg
initrdefi /images/pxeboot/initrd.img
}
submenu 'Troubleshooting -->' {
menuentry 'Install Red Hat Enterprise Linux 9.4 in text mode' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.repo=hd:LABEL=RHEL-9-4-0- inst.text quiet
initrdefi /images/pxeboot/initrd.img
}
menuentry 'Rescue a Red Hat Enterprise Linux system' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.repo=hd:LABEL=RHEL-9-4-0- inst.rescue quiet
initrdefi /images/pxeboot/initrd.img
}
}
이렇게 수정하면 install 설치화면을 묻는 화면에서 Kick Start Install 이라는 문구가 뜨게 됩니다. 해당 tab 으로 설치를 진행해 주면 kick start 로 linux 설치하기 완료입니다!