我有一個 CentOS 7 kickstart 文件,大部分工作得很好。該%packages
部分失敗是因為我需要在 /etc/hosts 上新增一個條目以將mirrorlist.centos.org 指向我們的內部公司儲存庫。我可以在該部分添加條目,%post
不用擔心,但這似乎是在包之後運行。我嘗試將其添加到該%pre
部分,但它從未出現在 /etc/hosts 中。從文件來看,前一節是在安裝開始之前運行的,所以我猜檔案系統甚至還不存在。我可以將包移動到該%post
部分並運行,yum install <my package>
但我認為使用包部分會更整潔一些。這是我的完整啟動文件:
install
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp --noipv6 --onboot=on --device=eth0
rootpw --plaintext XXXX
firewall --disabled
selinux --permissive
timezone UTC
unsupported_hardware
bootloader --timeout=1 --location=mbr --append="net.ifnames=0 biosdevname=0"
text
skipx
zerombr
clearpart --all --initlabel
autopart --nohome --nolvm
auth --enableshadow --passalgo=sha512 --kickstart
firstboot --disabled
reboot --eject
user --name=vagrant --plaintext --password XXXX
%packages --nobase --ignoremissing --excludedocs --instLangs=en_US.utf8
# vagrant needs this to copy initial files via scp
openssh-clients
sudo
selinux-policy-devel
wget
nfs-utils
net-tools
tar
bzip2
deltarpm
rsync
qemu-guest-agent
-fprintd-pam
-intltool
# unnecessary firmware
-*firmware
-microcode_ctl
%end
%pre --log=/mnt/ks-pre.log
#!/bin/sh
echo X.X.X.X mirrorlist.centos.org >> /etc/hosts
touch /mnt/hello
touch /root/hello
%end
%post --log=/root/ks-post.log
echo X.X.X.X mirrorlist.centos.org >> /etc/hosts
# sudo
echo 'Defaults:vagrant !requiretty' > /etc/sudoers.d/vagrant
echo '%vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/vagrant
chmod 440 /etc/sudoers.d/vagrant
# Enable hyper-v daemons only if using hyper-v virtualization
if [ $(virt-what) == "hyperv" ]; then
yum -y install hyperv-daemons cifs-utils
systemctl enable hypervvssd
systemctl enable hypervkvpd
fi
# Since we disable consistent network naming, we need to make sure the eth0
# configuration file is in place so it will come up.
# Delete other network configuration first because RHEL/C7 networking will not
# restart successfully if there are configuration files for devices that do not
# exist.
rm -f /etc/sysconfig/network-scripts/ifcfg-e*
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << _EOF_
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
DEVICE=eth0
ONBOOT=yes
_EOF_
#add our SSH key as a login method
mkdir /root/.ssh
chmod 700 /root/.ssh
cat >> /root/.ssh/authorized_keys << _EOF_
ssh-rsa xxxxxx
_EOF_
chmod 600 /root/.ssh/authorized_keys
#cloud init
yum install -y cloud-init
cat > /etc/cloud/cloud.cfg.d/90_dpkg.cfg << _EOF_
datasource_list: [ NoCloud, None ]
_EOF_
systemctl enable cloud-init
cat > /etc/cloud/cloud.cfg << _EOF_
users:
- default
disable_root: 0
ssh_pwauth: 1
mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys: 0
ssh_genkeytypes: ~
syslog_fix_perms: ~
disable_vmware_customization: true
cloud_init_modules:
- disk_setup
- migrator
- bootcmd
- write-files
- growpart
- resizefs
- set_hostname
- update_hostname
- update_etc_hosts
- rsyslog
- users-groups
- ssh
cloud_config_modules:
- mounts
- locale
- set-passwords
- rh_subscription
- yum-add-repo
- package-update-upgrade-install
- timezone
- puppet
- chef
- salt-minion
- mcollective
- disable-ec2-metadata
- runcmd
cloud_final_modules:
- rightscale_userdata
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- phone-home
- final-message
- power-state-change
system_info:
default_user:
name: centos
lock_passwd: true
gecos: Cloud User
groups: [adm, systemd-journal]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
distro: rhel
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshd
# vim:syntax=yaml
_EOF_
echo Complete
%end
答案1
只是根據@HBruijn 的資訊回答我自己的問題。軟體包部分似乎僅設計用於從安裝媒體安裝軟體包。這是有道理的,因為您通常不會在作業系統的安裝階段使用外部儲存庫。通常,您會安裝作業系統,然後安裝其他軟體套件。因此,為此使用帖子部分是有意義的。在那裡可以輕鬆添加條目/etc/hosts
,然後安裝其他軟體包。