Anaconda Kickstart

MBR(Master Boot Record)

最大只支持 2 TB 的盘,最多只支持 4 个主分区
信息只存储在一个区域
GPT(GUID partition table)
是 MBR 的替代,属于 UEFI,磁盘的每一个分区都有唯一的识别号,支持更大的盘和更多的分区
信息存储在多个区域,当一部分受损后可修复
当 GPT 分区的盘在老的只支持 mbr 的工具下查看时,也会读到分区信息,只不过看到的是只有一个分区,这是为了防止用户误认为盘是空盘。
当大于 2TB 盘安装安装 CentOS 7 时报错
Your BIOS-based system needs a special partition to boot from a GPT disk label. To continue, please create a 1MiB 'biosboot' type partition
对于这个问题,解决办法是在 kickstart 文件中添加
part biosboot --fstype=biosboot --size=1


#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$f2etWUfU$Xgse1ND3iAsfiFI87pjsy/
# System timezone
timezone Asia/Shanghai
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Reboot after installation
reboot

%include /tmp/part-include

%packages
@^minimal
@core
net-tools
vim-enhanced
docker-engine
python-docker-py
gcc
python-devel
python-pip
libffi-devel
openssl-devel
python-openstackclient
python-neutronclient
python2-heatclient
python2-ironicclient
wget
hdparm
sdparm
qemu-img
ntpdate
ntp
dstat
git
sshpass
sysstat
nethogs
iperf
iperf3
tcpdump
ipmitool
MySQL-python
mariadb                                                                                                                                                                  
telnet
python2-shaker
screen
tmux                                                                                                                                                                     
python-tooz
python2-PyMySQL
# %end
%pre
#!/bin/sh
u=$(blkid | grep Ocata | cut -d: -f1)
for i in `ls /sys/block/ | grep -P "(vd|sd|hd)"`; do
    [[ $u =~ $i ]] && continue
    devices="$devices $i"
done
set $devices
if [[ $# -eq 1 ]]; then
    device=$1
fi
exec < /dev/tty3 > /dev/tty3 2>&1
chvt 3
if [[ -z $devices ]]; then
    echo "No disk found, install failed."
    echo ""
    read -p "Click keyboard to reboot:"
    reboot
fi
while [[ -z $device ]]; do
    clear
    echo "Detect multiple disks:$devices"
    read -p "Which disk do you want to install system: " device
    for i in $devices; do
        if [[ $device = $i ]]; then
            break 2
        fi
    done
done
devicesize=$(cat "/sys/block/$device/size")
if [[ $devicesize -lt 419430400 ]]; then
    clear
    echo "Selected disk $device is less then 200G, install failed. "
    echo ""
    read -p "Click keyboard to reboot: "
    reboot
fi
chvt 1
btrfs=$(grep btrfs /proc/cmdline)
cat > /tmp/part-include << EOF
ignoredisk --only-use=$device
bootloader --location=mbr --driveorder=$device
zerombr
clearpart --all --drives=$device
part /boot --fstype="ext4" --size=200 
part /boot/efi
part biosboot --fstype=biosboot --size=1
EOF
if [[ -z $btrfs ]]; then
    echo "part pv.01 --grow" >> /tmp/part-include
    echo "volgroup centos pv.01" >> /tmp/part-include
    echo "logvol / --vgname=centos --size=90000 --name=root" >> /tmp/part-include
    echo "logvol none --vgname=centos --size=90000 --thinpool --name=docker --metadatasize=512 --chunksize=512" >> /tmp/part-include
else
    echo "part btrfs.99 --size=90000 --fstype=btrfs" >> /tmp/part-include
    echo "btrfs none --label=c7 btrfs.99" >> /tmp/part-include
    echo "btrfs / --subvol --name=root LABEL=c7" >> /tmp/part-include
fi
cobbler=$(grep cobbler /proc/cmdline)
nic=$(printf $(ip -o link | cut -d: -f2 | grep -v lo))
eth0=$(for i in $(cat /proc/cmdline); do [[ $i =~ "ipaddr" ]] && echo $i; done)
[ -z $eth0 ] && exit 0
echo "network --bootproto static --device $nic --gateway $(echo $eth0 | cut -d: -f3)  --hostname $(echo $eth0 | cut -d: -f4) --ip $(echo $eth0 | cut -d: -f1 | cut -d= -f2)  --netmask $(echo $eth0 | cut -d: -f2) --onboot yes" >> /tmp/part-include
%end
%post
cobbler=$(grep cobbler /proc/cmdline)
if [[ -n $cobbler ]]; then
echo "/root/init.sh" >> /etc/rc.d/rc.local && chmod +x /etc/rc.d/rc.local
mkdir /root/.ssh
ssh-keygen -q -t rsa -f /root/.ssh/id_rsa -N ""; cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
tee /root/.ssh/config <<-'EOF'
host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
EOF
fi
eth0=$(for i in $(cat /proc/cmdline); do [[ $i =~ "ipaddr" ]] && echo $i; done)
echo "$(echo $eth0 | cut -d: -f1 | cut -d= -f2) $(echo $eth0 | cut -d: -f4)" >> /etc/hosts
btrfs=$(grep btrfs /proc/cmdline)
mkdir -p /etc/systemd/system/docker.service.d
tee /etc/systemd/system/docker.service.d/kolla.conf <<-'EOF'
[Service]
MountFlags=shared
EOF
mkdir /etc/docker
if [[ -z $btrfs ]]; then
tee /etc/docker/daemon.json <<-'EOF'
{
  "insecure-registries": ["0.0.0.0/0"],
  "storage-driver": "devicemapper",
  "storage-opts": [
    "dm.thinpooldev=/dev/mapper/centos-docker",
    "dm.use_deferred_removal=true",
    "dm.use_deferred_deletion=true"
  ],
  "log-opts": {
    "max-size": "20m",
    "max-file": "5"
  }
}
EOF
tee /etc/lvm/profile/docker-thinpool.profile <<-'EOF'
activation {
    thin_pool_autoextend_threshold=80
    thin_pool_autoextend_percent=20
}
EOF
lvchange --metadataprofile docker-thinpool centos/docker
echo "ExecStartPre=/usr/sbin/lvchange -ay /dev/centos/docker" >> /etc/systemd/system/docker.service.d/kolla.conf
else
tee /etc/docker/daemon.json <<-'EOF'
{
  "insecure-registries": ["0.0.0.0/0"],
  "log-opts": {
    "max-size": "20m",
    "max-file": "5"
  }
}
EOF
fi
systemctl disable postfix
systemctl disable NetworkManager
systemctl disable chronyd
systemctl enable docker
echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
echo -e "* soft nofile 65535\n* hard nofile 65535" >> /etc/security/limits.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
echo "UseDNS no" >> /etc/ssh/sshd_config
rm -f /tmp/*
%end
%post --nochroot
cobbler=$(grep cobbler /proc/cmdline)
[[ -z $cobbler ]] && exit 0
cp /run/install/repo/extras/init.sh /mnt/sysimage/root/
cp /run/install/repo/extras/cobbler.tar /mnt/sysimage/root/
#cp /run/install/repo/extras/CentOS-7.3-x86_64.ks /mnt/sysimage/var/lib/cobbler/kickstarts/CentOS-7.3-x86_64.ks
mkdir /mnt/sysimage/var/lib/cobbler/webui_sessions && chown 48.root /mnt/sysimage/var/lib/cobbler/webui_sessions && chmod 700 /mnt/sysimage/var/lib/cobbler/webui_sessions
cp /run/install/repo/extras/docker-registry.tar.gz /mnt/sysimage/root/
cp /run/install/repo/extras/registry.tar /mnt/sysimage/root/
cp /run/install/repo/extras/kolla-ansible-4.0.3.dev36.tar.gz /mnt/sysimage/root/
cp /run/install/repo/extras/dep.tar.gz /mnt/sysimage/root/
rsync -a /run/install/repo/extras/loaders/ /mnt/sysimage/var/lib/cobbler/loaders/
rsync -a --exclude extras/ /run/install/repo/ /mnt/sysimage/repo/
echo "cobbler_interface: $(printf $(ip -o link | cut -d: -f2 | grep -v lo))" > /mnt/sysimage/repo/config.yml
%end


参考资料: https://fedoraproject.org/wiki/Anaconda/Kickstart/zh-cn

                      http://blog.51cto.com/xiaogongju/2060951


Kickstart 资料: https://fedoraproject.org/wiki/Anaconda/Kickstart/zh-cn

                     http://blog.51cto.com/xiaogongju/2060951

猜你喜欢

转载自blog.csdn.net/qq_42006894/article/details/81025727
今日推荐