没有多大技术含量,就是将之前的这篇文章http://shanker.blog.51cto.com/1189689/815403写成shell了。

 
  
  1. #!/bin/bash 
  2. #CentOS6.2+PXE+Apache+DHCP+tftp+kickstart 
  3. #Author:shanker 
  4. #Date:2012/05/12 
  5. if [ "$UID"  -ne 0 ] 
  6. then 
  7.     echo "you must be root to run it" 
  8.     exit 0 
  9. fi 
  10. yum -y install httpd* tftp-server system-config-kickstart dhcp syslinux 
  11. mount /dev/cdrom /mnt 
  12. cp -rf /mnt/* /var/www/html 
  13.  
  14. #configure tftp server 
  15. cat >/etc/xinetd.d/tftp <<EOF 
  16. service tftp  
  17. {  
  18.         socket_type             = dgram  
  19.         protocol                = udp  
  20.         wait                    = yes  
  21.         user                    = root  
  22.         server                  = /usr/sbin/in.tftpd  
  23.         server_args             = -s /tftpboot  
  24.         disable                 = no  
  25.         per_source              = 11  
  26.         cps                     = 100 2  
  27.         flags                   = IPv4  
  28. }  
  29. EOF 
  30.  
  31. service xinetd restart 
  32.  
  33. mkdir /tftpboot  
  34. cp /usr/share/syslinux/pxelinux.0 /tftpboot  
  35. cd /var/www/html/p_w_picpath/pxeboot/   
  36. cp initrd.img vmlinux /tftpboot  
  37. cp /var/www/html/isolinux/*.msg /tftpboot  
  38. mkdir /tftpboot/pxelinux.cfg  
  39. cp /var/www/html/isolinux/isolinux.cfg  /tftpboot/pxelinux.cfg/default 
  40.  
  41. #configure dhcp server 
  42.  cat >/etc/dhcp/dhcpd.conf <<EOF 
  43.  option domain-name-servers 10.0.0.1;  
  44. max-lease-time 7200;  
  45. authoritative;  
  46.   
  47.  subnet 10.0.0.0 netmask 255.255.255.0 {  
  48.  range 10.0.0.1 10.0.0.253;  
  49.  next-server 10.0.0.8;  
  50.  filename "pxelinux.0";  
  51.  }  
  52. EOF 
  53. service dhcpd start 
  54.  
  55. #configure ks.cfg file 
  56.  
  57. cat /var/www/html/ks.cfg <<EOF 
  58. #platform=x86, AMD64, or Intel EM64T 
  59. #version=DEVEL 
  60. # Firewall configuration 
  61. firewall --disabled 
  62. # Install OS instead of upgrade 
  63. install 
  64. # Use network installation 
  65. url --url="http://10.0.0.8/" 
  66. # Root password 
  67. rootpw --iscrypted $1$wi31/rmQ$GUXZKNwj/I2.JZ81uRLHk0 
  68. # System authorization information 
  69. auth  --useshadow  --passalgo=sha512 
  70. # Use graphical install 
  71. graphical 
  72. firstboot --disable 
  73. # System keyboard 
  74. keyboard us 
  75. # System language 
  76. lang en_US 
  77. # SELinux configuration 
  78. selinux --disabled 
  79. # Installation logging level 
  80. logging --level=info 
  81.  
  82. # System timezone 
  83. timezone  Asia/Shanghai 
  84. # Network information 
  85. network  --bootproto=dhcp --device=eth0 --onboot=on 
  86. # System bootloader configuration 
  87. bootloader --location=mbr 
  88. # Clear the Master Boot Record 
  89. zerombr 
  90. # Partition clearing information 
  91. clearpart --all --initlabel  
  92. # Disk partitioning information 
  93. part /boot --fstype="ext4" --size=100 
  94. part swap --fstype="swap" --size=512 
  95. part /home --fstype="ext4" --size=5000 
  96. part / --fstype="ext4" --grow --size=1 
  97.  
  98. %packages 
  99. @basic-desktop 
  100.  
  101. %end 
  102.  
  103. EOF 
  104.  
  105. cat /tftpboot/pxelinux.cfg/default <<EOF 
  106. default linux  
  107. prompt 1  
  108. timeout 6 
  109.   
  110. display boot.msg  
  111.   
  112. menu background splash.jpg  
  113. menu title Welcome to CentOS 6.2!  
  114. menu color border 0 #ffffffff #00000000  
  115. menu color sel 7 #ffffffff #ff000000  
  116. menu color title 0 #ffffffff #00000000  
  117. menu color tabmsg 0 #ffffffff #00000000  
  118. menu color unsel 0 #ffffffff #00000000  
  119. menu color hotsel 0 #ff000000 #ffffffff  
  120. menu color hotkey 7 #ffffffff #ff000000  
  121. menu color scrollbar 0 #ffffffff #00000000  
  122.   
  123. label linux  
  124.   menu label ^Install or upgrade an existing system  
  125.   menu default  
  126.   kernel vmlinuz  
  127.   append ks=http://10.0.0.8/ks.cfg initrdinitrdinitrd=initrd.img  
  128. label vesa  
  129.   menu label Install system with ^basic video driver  
  130.   kernel vmlinuz  
  131.   append initrdinitrdinitrd=initrd.img xdriver=vesa nomodeset  
  132. label rescue  
  133.   menu label ^Rescue installed system  
  134.   kernel vmlinuz  
  135.   append initrdinitrdinitrd=initrd.img rescue  
  136. label local  
  137.   menu label Boot from ^local drive  
  138.   localboot 0xffff  
  139.  
  140. EOF