环境:Vmare + Linux虚拟机
注意:网卡桥接
操作系统:centos6.4
1、搭建yum安装环境:
[root@server2 ~]# mkdir /mnt/cdrom [root@server2 ~]# mount /dev/cdrom /mnt/cdrom/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@server2 ~]# rm -rf /etc/yum.repos.d/* [root@server2 ~]# vim /etc/yum.repos.d/myyum.repo [myyum] name = myyum gpgcheck = 0 baseurl = file:///mnt/cdrom [root@server2 ~]# yum install httpd tftp-server xinetd system-config-kickstart syslinux -y
2、环境配置:
[root@server2 ~]# vim /etc/xinetd.d/tftp service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no # yes改成no per_source = 11 cps = 100 2 flags = IPv4 } [root@server2 ~]# service xinetd start 正在启动 xinetd: [确定] [root@server2 ~]# chkconfig --list xinetd xinetd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
# cd /var/lib/tftpboot/ # cp -a /mnt/cdrom/isolinux/boot.msg . # cp -a /mnt/cdrom/images/pxeboot/{initrd.img,vmlinuz} . # cp -a /usr/share/syslinux/pxelinux.0 . # mkdir pxelinux.cfg # cd pxelinux.cfg/ # cp -a /mnt/cdrom/isolinux/isolinux.cfg ./default 以上为复制syslinux小型系统和linux内核、驱动以及配置文件。
修改default文件,修改如下:
default ks
prompt 1
timeout 6
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.4!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img
label vesa
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset
label ks
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.2.11/ks.cfg
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
3、搭建dhcp服务器:
[root@server2 dhcp]# yum install dhcp -y [root@server2 dhcp]# cd /etc/dhcp/ [root@server2 dhcp]# cp -a /usr/share/doc/dhcp*/dhcpd.conf.sample ./dhcpd.conf cp:是否覆盖"./dhcpd.conf"? y [root@server2 dhcp]# vim dhcpd.conf # 以下为我环境的地址,请自行修改 subnet 192.168.2.0 netmask 255.255.255.0 { range 192.168.2.10 192.168.2.100; option domain-name-servers 192.168.2.1; option routers 192.168.2.1; default-lease-time 600; max-lease-time 7200; next-server 192.168.2.11; # #TFTP Server 的IP地址,也就是本机 filename "pxelinux.0"; # pxelinux 启动文件位置; } [root@server2 dhcp]# service dhcpd start 正在启动 dhcpd: [确定] [root@server2 dhcp]# chkconfig dhcpd on
4、构建基于HTTP协议的PXE环境:
[root@server2 ~]# cd /var/www/html/ [root@server2 html]# mkdir cdrom [root@server2 html]# umount /dev/cdrom [root@server2 html]# mount /dev/cdrom /var/www/html/cdrom/ mount: block device /dev/sr0 is write-protected, mounting read-only
[root@server2 html]# service httpd start 正在启动 httpd:chkhttpd: apr_sockaddr_info_get() failed for server2 httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName [确定] [root@server2 html]# chkconfig httpd on
关闭防火墙和SELINUX
[root@server2 html]# service iptables stop
iptables:清除防火墙规则: [确定]
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:正在卸载模块: [确定]
[root@server2 html]# getenforce
Disabled
通过本地访问:
这样能够访问到就OK。
4、创建ks.cfg文件
[root@server2 pxelinux.cfg]# system-config-kickstart 该命令是基于桌面环境运行的,需要安装桌面,安装桌面后,可以直接切换到虚拟机内执行。
这样就可以配置了,相关配置网上有。这里贴出来一个我已经配置好的ks.cfg 放置到/var/www/html/ks.cfg
采用LVM 最小化安装
#platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use network installation url --url="http://192.168.2.11/cdrom" # Root password rootpw --iscrypted $1$x1wkiXJv$45UMW./5aUCEkfymzt4WQ/ # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install text # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone --utc Asia/Shanghai # Network information network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="ext4" --size=500 part swap --fstype="swap" --size=1000 part pv.01 --size=1 --grow volgroup vg00 pv.01 logvol / --vgname=vg00 --size=8192 --name=lv_root%packages openssh-clients @core %end
复制以上代码并创建文件ks.cfg到/var/www/html目录下。
到此,kickstart已经配置完成。新建一台虚拟机进行测试:
问题1:
直接复制了我上面的配置 没有修改:url --url="http://192.168.2.11/cdrom" 改为本机IP。
问题2:
继续查你的IP地址写的是否正确,共两个文件:
cat /var/lib/tftpboot/pxelinux.cfg/default
append initrd=initrd.img ks=http://192.168.2.11/ks.cfg # 查看这句是否有 ks=http://xxxx
[ 总结 ] Linux kickstart 无人值守安装系统构建过程
原文:http://www.cnblogs.com/hukey/p/5295008.html