最近研究kickstart启动,来一篇centos装ubuntu12的文档共享给大家,供大家参考。是经过本人反复测试完善的。

centos6.2 with kickstart网络启动自动安装Ubuntu 12.04(vsftpd+DHCP+TFTP)
参考文章
1、http://www.linuxidc.com/Linux/2012-06/62441.htm
2、百度文库《Ubuntu12.04lts的pxe安装及拾遗》
3、http://bbs.linuxtone.org/thread-10957-1-1.html

#在网络启动的centos服务器上安装kickstart所需软件(如果用dnsmasq+httpd的话,会方便很多,且易于管理;因为dnsmasq=dhcp+tftp+xinetd)


yum install dhcp tftp* xinetd vsftpd

yum install -y dnsmasq


vim /etc/dnsmasq.conf把如下行注释去掉并修改

bogus-priv
filterwin2k
dhcp-range=192.168.44.100,192.168.44.120,12h
dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/var/lib/tftpboot
dhcp-authoritative


#以下是使用vsftpd+DHCP+TFTP的情形

#启用tftp
sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

将/var/lib/tftpboot链接到/tftpboot
ln -s /var/lib/tftpboot /tftpboot

挂载光盘镜像并复制网启文件到tftp
mkdir /mnt/cd
mount -o loop -t auto ~/iso/ubuntu-12.04.4-server-amd64.iso /mnt/cd
cp -rv /mnt/cd/install/netboot/* /tftpboot

修改启动菜单
vim /tftpboot/pxelinux.cfg/default
将timeout后的0改成30表示3秒自动选择
vim /tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg
修改label cli上面的那行,改成下面这样


append initrd=ubuntu-installer/amd64/initrd.gz ks=ftp://192.168.44.250/pub/ks/ubuntuserver12/ks.cfg live-installer/net-p_w_picpath=ftp://192.168.44.250/pub/ks/ubuntuserver12/install/filesystem.squashfs


在ftp目录中放上安装源
mkdir -p /var/ftp/pub/ks/ubuntuserver12
cp -rv /mnt/cd/* /var/ftp/pub/ks/ubuntuserver12

配置dhcp
vim /etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
next-server 192.168.44.250;
filename "pxelinux.0";
allow booting;
allow bootp;
subnet 192.168.44.0 netmask 255.255.255.0 {
# — default gateway
option routers 192.168.44.1;
option subnet-mask 255.255.255.0;
# option nis-domain “domain.org”;
option domain-name "chaoxing.com";
option domain-name-servers 202.106.195.68;
option time-offset -18000; # Eastern Standard Time
range 192.168.44.100 192.168.44.120;
}

编写ks.cfg文件
vim /var/ftp/pub/ks/ubuntuserver12/ks.cfg
# ubuntuser kickstart file
install
url --url ftp://192.168.44.250/pub/ks/ubuntuserver12

preseed passwd/root-login boolean true
lang en_US
langsupport --default en_US.UTF-8 en_US.UTF-8

keyboard us
mouse
timezone Asia/Shanghai

rootpw --disabled
user john --fullname "john chu" --password chaoxing54321
reboot
text

#不管是传统分区方式还是自动lvm分区方式,当遇到硬盘本身带有lvm分区的时候依然会需要人为干预,这个问题我至今还没有解决,官方好像没有打算修复这个“bug”。目前我是使用再次创建一个全新的lvm覆盖老lvm的方式强制跳过那交互的。如下
bootloader --location=mbr
zerombr yes
clearpart --drives=sda --initlabel --all
# 不设置swap时安装过程中会提示要不要重新添加swap分区

part swap --size 4096

part /boot --fstype ext4 --size=256

part pv.01 --size=1 --grow

volgroup vg pv.01

logvol / --vgname=vg --size=1 --grow --name=lv



#用以下ubuntu kickstart seed文件的内容,可让live-installer使用默认lvm的分区方式

#d-i partman-auto/disk string /dev/sda

#d-i partman-auto/method string lvm

#d-i partman-auto/purge_lvm_from_device boolean true

#d-i partman-lvm/device_remove_lvm boolean true

#d-i partman-md/device_remove_md boolean true

#d-i partman-md/confirm_nooverwrite boolean true

#d-i partman-lvm/confirm boolean true

#d-i partman-lvm/confirm_nooverwrite boolean true

#d-i partman-auto-lvm/guided_size string max

#d-i partman-auto/choose_recipe select atomic

#d-i partman/default_filesystem string ext4  

#d-i partman-md/confirm boolean true

#d-i partman-partitioning/confirm_write_new_label boolean true

#d-i partman/choose_partition select Finish partitioning and write changes to disk

#d-i partman/confirm boolean true

#d-i partman/confirm_nooverwrite boolean true


#我测试的时候,发现如下这行,不写就会提示无法安装!

d-i live-installer/net-p_w_picpath string ftp://192.168.44.250/pub/ks/ubuntuserver12/install/filesystem.squashfs


auth  --useshadow  --enablemd5
network --bootproto=dhcp --device=eth0
firewall --disabled
skipx

%packages
@ Base
openssh-server
openssh-client
vim
gcc
make


启动各项服务
/etc/init.d/dhcpd restart && /etc/init.d/xinetd restart && /etc/init.d/vsftpd restart

注意
如果使用kickstart方式必须用“ks=”指出ks文件位置,不能用“file=;如果要使用seed文件(就是内容是d-i开头那种),需要使用“preseed/url=”指出seed文件位置,且必须与ks格式文件配合使用不能没有“ks=”只有“preseed/url=”
以下seed文件可供参考也可以没有,是配合ks文件扩展使用的,如果需要追加seed文件,把txt.cfg中append后改成
append initrd=ubuntu-installer/amd64/initrd.gz ks=ftp://192.168.44.250/pub/ks/ubuntuserver12/ks.cfg live-installer/net-p_w_picpath=ftp://192.168.44.250/pub/ks/ubuntuserver12/install/filesystem.squashfs  preseed/url=ftp://192.168.44.250/pub/ks/ubuntuserver12/ks.seed
创建ks.seed文件
vim /var/ftp/pub/ks/ubuntuserver12/ks.seed
# ubuntu preseed file
d-i debian-installer/locale string en_US  
d-i debian-installer/language string en  
d-i debian-installer/country string china
d-i localechooser/supported-locales multiselect en_US.UTF-8, zh_CN.UTF-8  
#keyboard  
d-i console-setup/ask_detect boolean false  
d-i console-configuration/layoutcode string us  
d-i keyboard-configuration/modelcode string SKIP  
#clock  
d-i clock-setup/utc boolean false  
d-i time/zone string Asia/Shanghai  
#network  
d-i netcfg/choose_interface select auto  
d-i netcfg/dhcp_failed note  
d-i netcfg/dhcp_options select Do not configure the network at this time  
d-i netcfg/get_hostname string test  
d-i netcfg/get_domain string test-domain  
d-i netcfg/wireless_wep string  
# Mirror  
d-i mirror/protocol string ftp  
#d-i mirror/country string china  
d-i mirror/http/hostname string  192.168.44.250  
d-i mirror/http/directory string /pub/ks/ubuntuserver12  
d-i mirror/http/proxy string  
#d-i mirror/http/mirror select 192.168.44.250
# clock  
d-i clock-setup/ntp boolean true  
# partition  
d-i partman-auto/disk string /dev/sda  
d-i partman-auto/method string regular  
d-i partman-lvm/device_remove_lvm boolean true  
d-i partman-md/device_remove_md boolean true  
d-i partman-auto/choose_recipe select atomic  
d-i partman/default_filesystem string ext4  
d-i partman/confirm_write_new_label boolean true  
d-i partman/choose_partition  select Finish partitioning and write changes to disk  
d-i partman/confirm boolean true  
#user  
#d-i passwd/root-login boolean true  
#d-i passwd/root-password-crypted password $1$3nGno0$c4rp7NcQRAcJV3AdzKV890  
#d-i passwd/make-user boolean true  
d-i passwd/user-fullname string ubuntu  
d-i passwd/username string ubuntu  
#d-i passwd/user-password-crypted password $1$3nGno0$c4rp7NcQRAcJV3AdzKV890  
d-i passwd/user-password password chaoxing54321
d-i passwd/user-password-again password chaoxing54321
d-i user-setup/allow-password-weak boolean true  
d-i user-setup/encrypt-home boolean false  
#package  
tasksel tasksel/first multiselect none  
d-i pkgsel/include string openssh-server vim gcc make
d-i pkgsel/upgrade select full-upgrade  
d-i pkgsel/install-language-support boolean true  
d-i pkgsel/language-packs multiselect en, zh  
d-i pkgsel/update-policy select none  
# popularity-contest popularity-contest/participate boolean false  
d-i pkgsel/updatedb boolean true  

#grub  
d-i grub-installer/skip boolean false  
d-i lilo-installer/skip boolean true  
d-i grub-installer/grub2_instead_of_grup_legacy boolean true  
d-i grub-installer/only_debian boolean true  
d-i grub-installer/with_other_os boolean true  

# Finish  
d-i finish-install/keep-consoles boolean true  
d-i finish-install/reboot_in_progress note  
d-i cdrom-detect/eject boolean true  
d-i debian-installer/exit/halt boolean false  
d-i debian-installer/exit/poweroff boolean false


注意很多人在kickstart安装ubuntu时候出现这个如图的错误,

centos用kickstart自动部署ubuntu12_自动部署


原因是在pxe启动的menu文件里append这行没有加上live-installer/net-p_w_picpath=ftp://192.168.44.250/pub/ks/ubuntuserver12/install/filesystem.squashfs,且

ks文件里没有写这样一行d-i live-installer/net-p_w_picpath string ftp://192.168.44.250/pub/ks/ubuntuserver12/install/filesystem.squashfs