Metonymical Deflection

ゆるく日々のコト・たまにITインフラ

CentOS8 kickstartによるインストール

kickstartによるインストールのサンプルファイルをいくつかピックアップしてみたいと思います。

サンプルとしては以下の通り。*1

  • KVM(CentOS7.6)上にCentOS8をServerGUIでインストール
  • DL360G8上にCentOS8をServerGUIでインストール
  • KVM(CentOS7.6)上にCentOS8をminimalでインストール

2019/10/14追記*2

  • KVM(CentOS8.0)上にCentOS8をServerGUIでインストール
  • KVM(CentOS8.0)上にCentOS8をminimalでインストール


これ以外にも応用はいくらでもできると思います。

1.KVM(CentOS7.6)上にCentOS8をServerGUIでインストール

1-1.kickstartファイルの作成
vi c80gui.ks

# Network information
network  --bootproto=static --device=eth0 --onboot=on --ip=192.168.0.100 --gateway=192.168.0.1 --netmask=255.255.255.0 --nameserver=192.168.0.1 --noipv6
network  --bootproto=dhcp --device=eth1 --onboot=off --noipv6
network  --hostname=c80mas.md.jp

# Root password
rootpw --plaintext TESTPASSWD
user --groups=wheel --name=rsadmin --password=TESTPASSWD --plaintext

# System services
services --disabled="bolt,colord,cups,fwupd,ModemManager,packagekit,smartd,sssd-kcm,sssd,wpa_supplicant" --enabled="chronyd"
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled

# Disk partitioning information
part /boot --fstype="ext4" --ondisk=vda --size=1024
part pv.1 --fstype="lvmpv" --ondisk=vda --size=1024 --grow
volgroup cl --pesize=4096 pv.1
logvol swap --fstype="swap" --recommended --name=swap --vgname=cl
logvol / --fstype="xfs" --grow --size=1024 --name=root --vgname=cl

cmdline
install
eula --agreed
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# System timezone
timezone Asia/Tokyo --isUtc --nontp
# X Window System configuration information
xconfig  --startxonboot
zerombr
bootloader --location=mbr --boot-drive=vda --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --none --initlabel

# repo
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
ignoredisk --only-use=vda

%packages
@^graphical-server-environment
@container-management
@development
@virtualization-client
@virtualization-hypervisor
@virtualization-tools
kexec-tools
%end

%post
dnf -y install cockpit-machines
systemctl enable --now cockpit.socket
systemctl start --now cockpit.socket
dnf -y install epel-release
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
dnf -y install https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm
sed -i -e "s/#options kvm_intel nested=1/options kvm_intel nested=1/g" /etc/modprobe.d/kvm.conf
sed -i -e '/^pool/a server 192.168.0.1 iburst' /etc/chrony.conf
sed -i -e 's/^pool/#pool/g' /etc/chrony.conf
dnf -y install tigervnc-server
cp -a /usr/lib/systemd/user/vncserver@.service /etc/systemd/system/vncserver@:1.service
sed -i -e '/^Type/a PIDFile=/root/.vnc/%H%i.pid' /etc/systemd/system/vncserver@:1.service
sed -i -e 's/ExecStart=/#ExecStart=/g' /etc/systemd/system/vncserver@:1.service
sed -i -e '/^#ExecStart=/a ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"' /etc/systemd/system/vncserver@:1.service
sed -i -e '/$geometry/s/1024x768/1600x1200/g' /usr/bin/vncserver
systemctl set-default multi-user.target

#dnf update -y

%end
reboot --eject

<補足1>

  1. NW, Credential, Service, Diskなど環境によって変更する頻度が多いパラメータを上位に記載しています。
  2. Serviceのうちdisabledは、私が不要ものを記載しているため、素の状態で使用したい場合はコメントアウトしてください。
  3. eulaが効かず、OSインストール&Reboot後に手動でContinueしないとダメな場合があります。
  4. %packagesのうち、"@^graphical-server-environment"以下は、私が必要なものを記載しているため、素の状態で使用したい場合はコメントアウトしてください。
  5. %postには、私が必要なものを記載しているため、素の状態で使用したい場合はコメントアウトしてください。
1-2.qcow2ファイルの作成
qemu-img create -f qcow2 /var/lib/libvirt/images/c80mas.qcow2 20G
1-3.virt-installの実行
virt-install --connect=qemu:///system \
 --name=c80mas \
 --disk /var/lib/libvirt/images/c80mas.qcow2,format=qcow2,bus=virtio \
 --network bridge=br0,model=virtio \
 --network bridge=br0,model=virtio \
 --initrd-inject=./c80gui.ks \
 --extra-args='ks=file:/c80gui.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
 --vcpus=2 \
 --ram=2048 \
 --accelerate \
 --hvm \
 --location='/var/lib/libvirt/images/CentOS-8-x86_64-1905-dvd1.iso' \
 --nographics \
 --os-type=linux \
 --os-variant=centos7.0 \
 --arch=x86_64

<補足2>
"--network"にPortGroupを使用したい場合は、過去記事を参照してください。

2.DL360G8上にCentOS8をServerGUIでインストール

2-1.kickstartファイルの作成
# Network information
network  --bootproto=static --device=eno1 --ip=192.168.0.240 --netmask=255.255.255.0 --gateway=192.168.0.1 --nameserver=192.168.0.1 --noipv6 --activate
network  --hostname=c80mas.md.jp
#network  --bootproto=dhcp --device=eno2 --onboot=off --ipv6=auto
#network  --bootproto=dhcp --device=eno3 --onboot=off --ipv6=auto
#network  --bootproto=dhcp --device=eno4 --onboot=off --ipv6=auto
#network  --bootproto=dhcp --device=ens1f0 --onboot=off --ipv6=auto
#network  --bootproto=dhcp --device=ens1f1 --onboot=off --ipv6=auto

# Root password
rootpw --plaintext TESTPASSWD
user --groups=wheel --name=rsadmin --password=TESTPASSWD

# System services
services --disabled="bolt,colord,cups,fwupd,ModemManager,packagekit,smartd,sssd-kcm,sssd,wpa_supplicant" --enabled="chronyd"
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled

# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Disk partitioning information
part /boot --fstype="xfs"   --ondisk=sda --size=1024
part pv.1  --fstype="lvmpv" --ondisk=sda --size=1    --grow
volgroup cl --pesize=4096 pv.1
logvol /    --fstype="xfs"  --name=root --vgname=cl --size=1 --grow
logvol swap --fstype="swap" --name=swap --vgname=cl --recommended

# X Window System configuration information
xconfig  --startxonboot
# License agreement
eula --agreed
# Use CDROM installation media
cdrom
# Use graphical install
#graphical
text
# Run the Setup Agent on first boot
firstboot --enable
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# System timezone
timezone Asia/Tokyo --isUtc --nontp
# repo
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
ignoredisk --only-use=sda

%packages
@^graphical-server-environment
@container-management
@development
@virtualization-client
@virtualization-hypervisor
@virtualization-tools
kexec-tools
%end

%addon com_redhat_kdump --enable --reserve-mb=auto
%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
# Reboot after installation
reboot --eject

<補足3>

  1. 基本的には補足2に記載した内容と同様です。
  2. "reboot --eject"のうち、ejectオプションが効かないときがあるようなので、手動でejectしてください。

あとの操作方法は過去記事と同様です。
<補足4>
以下の起動オプションを入力する際、DL360G8pとDL360G8eで挙動が少し異なりました。

inst.ks=hd:sdb:/ks.cfg

DL360G8pの場合

inst.ks=hd:sdb:/ks.cfg

DL360G8eの場合

inst.ks=hd:sda:/ks.cfg

上記に伴いDL360G8eの場合にはkickstartファイルにおいても、"sda"を"sdb"に置換してください。

3.KVM(CentOS7.6)上にCentOS8をminimalでインストール

3-1.kickstartファイルの作成

さほど検証していないため、参考程度として記載します。

vi c80cui.ks


cmdline
install
eula --agreed
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable

# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=static --device=eth0 --onboot=on --ip=192.168.0.100 --gateway=192.168.0.1 --netmask=255.255.255.0 --nameserver=192.168.0.1 --noipv6
network  --bootproto=dhcp --device=eth1 --onboot=off --noipv6
network  --hostname=c80mas.md.jp

# System services
#services --enabled=chronyd
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled

# repo
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
ignoredisk --only-use=vda

zerombr
bootloader --location=mbr --boot-drive=vda --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --none --initlabel

# Disk partitioning information
part /boot --fstype="ext4" --ondisk=vda --size=1024
part pv.1 --fstype="lvmpv" --ondisk=vda --size=1024 --grow
volgroup cl --pesize=4096 pv.1
logvol swap --fstype="swap" --recommended --name=swap --vgname=cl
logvol / --fstype="xfs" --grow --size=1024 --name=root --vgname=cl

# Root password
rootpw --plaintext TESTPASSWD
# System timezone
timezone Asia/Tokyo --isUtc --nontp
user --groups=wheel --name=rsadmin --password=TESTPASSWD --plaintext
# X Window System configuration information
xconfig  --startxonboot

%packages
@^minimal-environment
kexec-tools
%end

%post

%end
reboot --eject
3-2.qcow2ファイルの作成
qemu-img create -f qcow2 /var/lib/libvirt/images/c80mas.qcow2 20G
3-3.virt-installの実行
virt-install --connect=qemu:///system \
 --name=c80mas \
 --disk /var/lib/libvirt/images/c80mas.qcow2,format=qcow2,bus=virtio \
 --network bridge=br0,model=virtio \
 --network bridge=br0,model=virtio \
 --initrd-inject=./c80cui.ks \
 --extra-args='ks=file:/c80cui.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
 --vcpus=2 \
 --ram=2048 \
 --accelerate \
 --hvm \
 --location='/var/lib/libvirt/images/CentOS-8-x86_64-1905-dvd1.iso' \
 --nographics \
 --os-type=linux \
 --os-variant=centos7.0 \
 --arch=x86_64

以下、2019/10/14に追記しました。
NWインターフェース名を変更していますが、それに伴い「--append」や「--extra-args」の設定も変更しています。

4.KVM(CentOS8.0)上にCentOS8をServerGUIでインストール

4-1.kickstartファイルの作成
vi c80gui.ks

# Network information
network  --bootproto=static --device=enp1s0 --onboot=on --ip=192.168.0.100 --gateway=192.168.0.1 --netmask=255.255.255.0 --nameserver=192.168.0.1 --noipv6
network  --bootproto=dhcp --device=enp2s0 --onboot=off --noipv6
network  --hostname=c80mas.md.jp

# Root password
rootpw --plaintext TESTPASSWD
user --groups=wheel --name=rsadmin --password=TESTPASSWD --plaintext

# System services
services --disabled="bolt,colord,cups,fwupd,ModemManager,packagekit,smartd,sssd-kcm,sssd,wpa_supplicant" --enabled="chronyd"
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled

# Disk partitioning information
part /boot --fstype="ext4" --ondisk=vda --size=1024
part pv.1 --fstype="lvmpv" --ondisk=vda --size=1024 --grow
volgroup cl --pesize=4096 pv.1
logvol swap --fstype="swap" --recommended --name=swap --vgname=cl
logvol / --fstype="xfs" --grow --size=1024 --name=root --vgname=cl


cmdline
install
eula --agreed
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# System timezone
timezone Asia/Tokyo --isUtc --nontp
# X Window System configuration information
xconfig  --startxonboot
zerombr
bootloader --location=mbr --boot-drive=vda --append="crashkernel=auto console=tty0 console=ttyS0,115200n8"
clearpart --none --initlabel

# repo
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
ignoredisk --only-use=vda

%packages
@^graphical-server-environment
@container-management
@development
@virtualization-client
@virtualization-hypervisor
@virtualization-tools
kexec-tools
%end

%post
dnf -y install cockpit-machines
systemctl enable --now cockpit.socket
systemctl start --now cockpit.socket
dnf -y install epel-release
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
dnf -y install https://www.elrepo.org/elrepo-release-8.0-2.el8.elrepo.noarch.rpm
sed -i -e "s/#options kvm_intel nested=1/options kvm_intel nested=1/g" /etc/modprobe.d/kvm.conf
sed -i -e '/^pool/a server 192.168.0.1 iburst' /etc/chrony.conf
sed -i -e 's/^pool/#pool/g' /etc/chrony.conf
dnf -y install tigervnc-server
cp -a /usr/lib/systemd/user/vncserver@.service /etc/systemd/system/vncserver@:1.service
sed -i -e '/^Type/a PIDFile=/root/.vnc/%H%i.pid' /etc/systemd/system/vncserver@:1.service
sed -i -e 's/ExecStart=/#ExecStart=/g' /etc/systemd/system/vncserver@:1.service
sed -i -e '/^#ExecStart=/a ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"' /etc/systemd/system/vncserver@:1.service
sed -i -e '/$geometry/s/1024x768/1600x1200/g' /usr/bin/vncserver
systemctl set-default multi-user.target

#dnf update -y

%end
reboot --eject
4-2.qcow2ファイルの作成
qemu-img create -f qcow2 /var/lib/libvirt/images/c80mas.qcow2 20G
4-3.virt-installの実行
virt-install --connect=qemu:///system \
 --name=c80mas \
 --disk /var/lib/libvirt/images/c80mas.qcow2,format=qcow2,bus=virtio \
 --network bridge=br0,model=virtio \
 --network bridge=br0,model=virtio \
 --initrd-inject=./c80gui.ks \
 --extra-args='ks=file:/c80gui.ks console=tty0 console=ttyS0,115200n8' \
 --vcpus=2 \
 --ram=2048 \
 --accelerate \
 --hvm \
 --location='/var/lib/libvirt/images/CentOS-8-x86_64-1905-dvd1.iso' \
 --nographics \
 --os-type=linux \
 --os-variant=rhel8.0 \
 --arch=x86_64

5.KVM(CentOS8.0)上にCentOS8をminimalでインストール

5-1.kickstartファイルの作成
vi c80cui.ks

# Network information
network  --bootproto=static --device=enp1s0 --onboot=on --ip=192.168.0.100 --gateway=192.168.0.1 --netmask=255.255.255.0 --nameserver=192.168.0.1 --noipv6
network  --bootproto=dhcp --device=enp2s0 --onboot=off --noipv6
network  --hostname=c80mas.md.jp

# Root password
rootpw --plaintext TESTPASSWD
user --groups=wheel --name=rsadmin --password=TESTPASSWD --plaintext

# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled

# Disk partitioning information
part /boot --fstype="ext4" --ondisk=vda --size=1024
part pv.1 --fstype="lvmpv" --ondisk=vda --size=1024 --grow
volgroup cl --pesize=4096 pv.1
logvol swap --fstype="swap" --recommended --name=swap --vgname=cl
logvol / --fstype="xfs" --grow --size=1024 --name=root --vgname=cl

cmdline
install
eula --agreed
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# System timezone
timezone Asia/Tokyo --isUtc --nontp
# X Window System configuration information
xconfig  --startxonboot
zerombr
bootloader --location=mbr --boot-drive=vda --append="crashkernel=auto console=tty0 console=ttyS0,115200n8"
clearpart --none --initlabel

# repo
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
ignoredisk --only-use=vda

%packages
@^minimal-environment
kexec-tools
%end

%post

%end
reboot --eject
5-2.qcow2ファイルの作成
qemu-img create -f qcow2 /var/lib/libvirt/images/c80mas.qcow2 20G
5-3.virt-installの実行
virt-install --connect=qemu:///system \
 --name=c80mas \
 --disk /var/lib/libvirt/images/c80mas.qcow2,format=qcow2,bus=virtio \
 --network bridge=br0,model=virtio \
 --network bridge=br0,model=virtio \
 --initrd-inject=./c80cui.ks \
 --extra-args='ks=file:/c80cui.ks console=tty0 console=ttyS0,115200n8' \
 --vcpus=2 \
 --ram=2048 \
 --accelerate \
 --hvm \
 --location='/var/lib/libvirt/images/CentOS-8-x86_64-1905-dvd1.iso' \
 --nographics \
 --os-type=linux \
 --os-variant=rhel8.0 \
 --arch=x86_64


以上です。

10.最後に

以下のサイトを参考にさせて頂きました。
virt-install で KVM に CentOS8 を無人インストール - Qiita

/root/anaconda-ks.cfgを参考にすれば色々試せると思いますので、自分なりにやってみることをおススメします。

*1:minimalはもうあまり使わないかなと思ったので重要度下げてます。

*2:libvirtdなどのVersionの違いにより、インターフェース名の指定方法が変わっているため追記しました。NW周りは重要度高いので。