需求:
1.全自动安装的centos6.5安装镜像,实现非技术人员能够容易安装linux系统的需求
2. 系统自带云知声医疗系统后台服务程序安装包及其依赖程序
解决方案:
1. 安装镜像自带Anaconda-Kickstart配置文件,并指定其配置
2. 自定义Anaconda-Kickstart配置文件指定其所需自动化过程
准备:
1. centos6.5原始ISO文件 (CentOS-6.5-x86_64-bin-DVD1.iso)
2. 使用centos6.5原始ISO文件安装系统后的安装日志(/root/install.log)
3. Anaconda-Kickstart配置文件 (ks.cfg)
4.云知声医疗安装包(yzs)
过程:
挂载centos6.5原始安装镜像
➜ iso mkdir centos6.5
➜ iso mkdir centos6.5_new
➜ iso sudo mount CentOS-6.5-x86_64-bin-DVD1.iso centos6.5_new
➜ iso rsync -a --exclude=Packages/ --exclude=repodata/ centos6.5/ centos6.5_new/
➜ iso sudo mkdir centos6.5_new/{Packages,repodata}
仅将需要安装的软件包集成到镜像
➜ iso cat copy.sh
#!/bin/bash
awk '/Installing/{print $2}' install.log | sed 's/^*://g' >>package.txt
DVD='/home/yunwei/iso/centos6.5/Packages'
PACKDIR='./package.txt'
NEW_DVD='/home/yunwei/iso/centos6.5_new/Packages'
while read LINE
do
cp ${DVD}/${LINE}*.rpm ${NEW_DVD} || echo "$LINE don't cp......."
done < package.txt
rm -f package.txt
➜ iso sudo sh copy.sh #这里可以将想要安装的rpm放到centos6.5_new/Packages,然后在ks配置文件中配置后安装系统时便可自动安装
#可根据实际需求添加相应的软件包
➜ iso sudo cp centos6.5/repodata/b4e0b9342ef85d3059ff095fa7f140f654c2cb492837de689a58c581207d9632-c6-x86_64-comps.xml centos6.5_new/repodata/c6-x86_64-comps.xml
➜ iso declare -x discinfo=`head -1 .discinfo`
➜ iso sudo createrepo -u "media://$discinfo" -g repodata/c6-x86_64-comps.xml centos6.5_new
将ks.conf 集成到initrd.img
➜ iso mkdir initrd-new
➜ iso cp centos6.5_new/isolinux/initrd.img initrd.img.xz
➜ iso xz --format=lzma initrd.img.xz --decompress
➜ iso cd initrd-new
➜ initrd-new cpio -ivdum < ../initrd.img
➜ initrd-new cp ../ks.cfg var/ks.cfg
➜ initrd-new find . -print |cpio -o -H newc | xz --format=lzma > ../initrd-new.img
➜ initrd-new cd ..
➜ iso sudo cp initrd-new.img centos6.5_new/isolinux/initrd.img
修改引导配置,使其读取ks.cfg配置文件
➜ iso vim centos6.5_new/isolinux/isolinux.cfg
18 label linux
19 menu label ^Install or upgrade an existing system
20 menu default
21 kernel vmlinuz
22 append ks=file:/var/ks.cfg initrd=initrd.img text
23 label vesa
将云知声医疗安装包放如镜像
➜ iso sudo cp -r yzs centos6.5_new
生成新的ISO镜像文件
➜ iso sudo xorriso -as mkisofs \
-D -r -J -joliet-long -l -V "Custom Install CD" \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-iso-level 3 -no-emul-boot -partition_offset 0 -boot-load-size 4 -boot-info-table \
-isohybrid-mbr --interval:local_fs:0s-15s:zero_mbrpt:'CentOS-6.5-x86_64-bin-DVD1.iso' \
-o Centos6.5-yzs.iso centos6.5_new
Centos6.5-yzs.iso 即为新的镜像。
ks.cfg 示例:
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T
# System authorization information
#auth --useshadow --enablemd5
authconfig --enableshadow --passalgo=sha512
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
#clearpart --all --drives=sda,sdb
#clearpart --drives=sda --initlabel
# Use text mode install
text
unsupported_hardware
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Use network installation
#url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
#$yum_repo_stanza
# Network information
#$SNIPPET('network_config')
#network --bootproto=dhcp --device=em1
network --bootproto=dhcp
# Reboot after installation
reboot
#Root password
#rootpw --iscrypted $default_password_crypted
rootpw --iscrypted $6$Vnt9F9FdwNdcxApq$WQn/kfMrmNkPGkAMrrt7dTbvZOXtLTsqDU7/RMA8wp9ih6DAKHZfWrQ1OOF3XQUOwneAWJ6E6Z0ltORY4jUyK0
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone --utc Asia/Shanghai
# Install OS instead of upgrade
install
#cdrom
%include /tmp/how-setup-include
# Clear the Master Boot Record
zerombr
%include /tmp/part-include
%pre
#!/bin/sh
devs=`grep 0 /sys/block/*/removable|awk -F'/' '{print $4}'|grep -E '.d.'`
dev_a=`grep 0 /sys/block/*/removable|awk -F'/' '{print $4}'|grep -E '.da'`
echo "clearpart --all --drives=`echo $devs|sed 's/ /,/g'`" >> /tmp/part-include
echo "part /boot --fstype=ext4 --size=2000 --ondisk $dev_a" >> /tmp/part-include
echo "part swap --size=2000 --ondisk $dev_a" >> /tmp/part-include
echo "part / --fstype=ext4 --size 1 --grow --ondisk $dev_a" >> /tmp/part-include
disk_count=0
for disk in $devs
do
if [ "$disk" != "$dev_a" ]
then
echo "part /data$disk_count --fstype=ext4 --size 1 --grow --ondisk $disk" >> /tmp/part-include
let disk_count=$disk_count+1
fi
done
mkdir /mount-test
mount /dev/cdrom /mount-test >/dev/null 2>&1
status=$?
if [ "$status" = 0 ]
then
echo cdrom > /tmp/how-setup-include
else
usb_dev=`grep 1 /sys/block/*/removable|awk -F'/' '{print $4}'|grep -E '.d.'`
if [ "${#usb_dev}" = 3 ]
then
echo "harddrive --partition=/dev/${usb_dev}1 --dir=/" >/tmp/how-setup-include
else
exit
fi
fi
%end
%packages
@base
@console-internet
@core
@debugging
@directory-client
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime
@server-platform
@server-policy
@workstation-policy
pax
oddjob
sgpio
device-mapper-persistent-data
samba-winbind
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
make
man
MySQL-shared-compat
MySQL-devel
MySQL-server
MySQL-client
#glibc-2.12-1.166.el6_7.1.i686
erlang
rabbitmq-server
libstdc++
gcc-c++
mpfr
libgomp
libgcc
cloog-ppl
tcl
gcc
cpp
ppl
libstdc++-devel
redis
%end
#%post --nochroot
#$SNIPPET('log_ks_post_nochroot')
#%end
%post
# set the hostname in the network configuration file
# Show fqdn hostname
sed -i '27a character-set-server=utf8 ' /usr/my.cnf
sed -i '28a collation-server=utf8_general_ci ' /usr/my.cnf
cp /tmp/.mysql_secret /var/.mysql_secret
if mount /dev/cdrom /mnt
then
cp -r /mnt/yzs /
eject /dev/cdrom
else
usb_dev=`grep 1 /sys/block/*/removable|awk -F'/' '{print $4}'|grep -E '.d.'`
for d in $usb_dev
do
mkdir /tmp/$d
if mount /dev/${d}1 /tmp/$d && test -d /tmp/$d/yzs
then
cp -r /tmp/$d/yzs /
fi
done
fi
%end
写入iso到u盘:
#!/bin/bash
xorriso -as mkisofs \
-D -r -J -joliet-long -l -V "YZS Install" \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-iso-level 3 -no-emul-boot -partition_offset 0 -boot-load-size 4 -boot-info-table \
-isohybrid-mbr --interval:local_fs:0s-15s:zero_mbrpt:'CentOS-6.5-x86_64-bin-DVD1.iso' \
-o Centos6.5-yzs.iso Centos6.5