前文回顾:
我们上一章《系统裁剪之旅(4)——启动克隆后的系统》中完成了使用克隆盘启动系统的操作,本章将会把之前全部的操作囊括到自动化安装脚本当中。以方便后续制作安装盘是使用。
本章内容:
以脚本的方式实现系统自动化安装。
安装脚本:
install_system.sh
#!/bin/sh
HD="sda"
IType=2
cdrom=hdc
echo -e "\v\tStart The Installation Of OS7.9 X86_64"
echo ""
IType=""
if [ "$IType" = "2" ]
then
echo ""
echo -e "\v\tStart The Installation Of OS7.9 X86_64"
sleep 3
echo ""
Hname=1
echo "Re-partition the disk..."
#disk fenqu
if [ "$Hname" = "1" -o "$Hname" = "2" ]
then
sfdisk -uS --force /dev/${HD} > /dev/null 2>&1 <<EOF
2048,2097152,L
2099200,4194304,S
6293504,,L
EOF
fi
echo "Format the disk..."
if [ "$Hname" = "1" -o "$Hname" = "2" ]
then
mkfs.xfs -f /dev/${HD}1
mkfs.xfs -f /dev/${HD}3
#mkfs.xfs -b 4096 -i 8192 -m 2 -O ^has_journal /dev/${HD}1 >/dev/null 2>&1
#mkfs.xfs -b 4096 -i 8192 -m 2 -O ^has_journal /dev/${HD}3 >/dev/null 2>&1
mkswap /dev/${HD}2 > /dev/null 2>&1
swapon /dev/${HD}2
fi
echo "Mount the disk..."
mkdir -p /mnt/linux
mount -t xfs -o defaults /dev/${HD}3 /mnt/linux
#mkdir -p /mnt/linux/usr
echo "Uncompress topos.tar.gz ...."
CDROM=/mnt/cdrom
mkdir -p ${CDROM}
#cdrom=`ls -l /dev/|grep ^b|grep cdrom|awk '{print $9}'`
mount /dev/$cdrom ${CDROM}
cd ${CDROM}/IMAGES/
tar -xzvf topos.tar.gz -C /mnt/linux
sync
if [ "$Hname" = "1" ]; then
# it is the Top-IRS
cat >/mnt/linux/etc/sysconfig/network << EOF
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost
EOF
cat > /mnt/linux/etc/hosts << EOF
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost localhost
EOF
fi
if [ "$Hname" = "2" ]; then
# it is the Top-ERS
cat >/mnt/linux/etc/sysconfig/network << EOF
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost
EOF
cat >/mnt/linux/etc/hosts << EOF
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost localhost
EOF
fi
############################################
echo "Uncompress topos.tar.gz ...."
mkdir -p /mnt/linux/boot
mount -t xfs -o defaults /dev/${HD}1 /mnt/linux/boot
cd ${CDROM}/IMAGES/
tar -xzvf boot.tar.gz -C /mnt/linux/boot
echo "grub2-install ${HD} ...."
grub2-install --boot-directory=/mnt/linux/boot/ /dev/${HD}
echo "Unmount ${HD} ...."
umount /dev/${HD}1
if [ "$Hname" != "1" -o "$Hname" != "2" ]
then
umount /dev/${HD}3
fi
cd / > /dev/null 2>&1
sync
else
IType=""
fi
第5行“cdrom=hdc”的hdc为存放上一章中“boot.tar.gz”和“rootfs.tar.gz”的磁盘,我这里的“hdc”指向的是光驱。“boot.tar.gz”和“rootfs.tar.gz”这两个压缩包需要放到“/dev/hdc/IMAGES/”目录下。