teketeke_55の日記

技術メモとか

PXEブートでCentOSをインストール

環境
CnetOS6.1

必要なパッケージをインストール

  yum install tftp-server tftp xinetd syslinux dhcp

configの設定

 vim /etc/xinetd.d/tftp
 service tftp                                                           
 {                                                                      
        socket_type             = dgram                                 
        protocol                = udp                                   
        wait                    = yes                                   
        user                    = root                                  
        server                  = /usr/sbin/in.tftpd                    
        server_args             = -s -v /var/lib/tftpboot    #-vを追加  
        disable                 = no                         #yesからno 
        per_source              = 11                                    
        cps                     = 100 2                                 
        flags                   = IPv4                                  
 }

CentOSのイメージファイルをマウント

imageはどっかから取得

 mount -t iso9660 -o loop /mnt/iso/CentOS-5.5-i386-bin-1of7.iso /mnt/iso

イメージファイルなどをtftboot下へコピーする

 cp -p  /mnt/iso/isolinux/initrd.img /var/lib/tftpboot/linux-install/
 cp -p /mnt/iso/isolinux/vmlinuz /var/lib/tftpboot/linux-install/ 
 cp -p /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/linux-install/ 
 cp -p /usr/share/syslinux/menu.c32 /var/lib/tftpboot/linux-install/

dhcpサーバの設定

 vim /etc/dhcp/dhcpd.conf
 # dhcpd.conf                                                                                 
 #                                                                                            
 log-facility local7;                                                                         
                                                                                              
 # No service will be given on this subnet, but declaring it helps the                        
 # DHCP server to understand the network topology.                                            
                                                                                              
 subnet 172.16.50.0 netmask 255.255.255.0 {                                                   
        #filename "/linux-install/pxelinux.0";                                                
        range 172.16.50.245 172.16.50.246;                                                    
        option routers 172.16.50.1;                                                           
        #range dynamic-bootp 172.16.50.245 172.16.50.246;    #自動割振りの場合は有効にする。  
        default-lease-time 600;                                                               
        max-lease-time 7200;                                                                  
 }   
                                                                                         
 #自動割振りの場合は以下は不要                                                                
  host pxe-test {                                                                             
                next-server 172.16.50.29;                                                     
                hardware ethernet 00:0c:29:03:84:d3;                                          
                fixed-address 172.16.50.245;                                                  
                filename    "/linux-install/pxelinux.0";                                      
        }                                                                                     
                                                                                              

設定の確認

 # dhcpd -f -d

問題なければdhcpdを起動する。

# /etc/init.d/dhcpd start

kick-startの準備

サンプルをコピーして適当に編集

 # cp -p /root/anakonda.ks.cfg /var/www/html/ks-test.cfg
 # vim /var/www/html/ks-test.cfg
  
 # Kickstart file automatically generated by anaconda.
 #version=DEVEL
 install
 url --url=http://172.16.50.29/pxe
 lang ja_JP.UTF-8
 keyboard jp106
 network --onboot yes --device eth0 --bootproto dhcp --ip  auto --netmask 255.255.255.0 --gateway 172.16.50.1 --nameserver 172.16.20.10 --  hostname CentOS5.5
 rootpw  passwd
 #firewall --service=ssh
 authconfig --enableshadow --passalgo=sha512
 #selinux --enforcing
 timezone Asia/Tokyo
 bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
 # The following is the partition information you requested
 # Note that any partitions you deleted are not expressed
 # here so unless you clear all partitions first, this is
 # not guaranteed to work
 clearpart --all --drives=sda
 part /boot --fstype ext3 --size=100 --ondisk=sda
 part pv.2 --size=0 --grow --ondisk=sda
 volgroup VolGroup00 --pesize=32768 pv.2
 logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=384 --grow --maxsize=768
 logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow

pxeブート用のコンフィグファイルを作成

 vim /var/lib/tftpboot/linux-install/pxelinux.cfg/default

 
 default    menu.c32
 
 label 1
 menu label ^1) CentOS5.5
 kernel vmlinuz
 append load initrd=initrd.img devfs=nomount ks=http://172.16.50.29/ks-test.cfg
 
 label 2
    menu label ^2) Boot from local drive
    localboot

その後はインストールしたい端末をDHCPサーバと同日セグメントに接続して起動する。(BIOSでPXEを有効にしておくこと)