Sunday, May 12, 2013

Setting up PXE server on Centos 6.4 and doing network install

Centos Release :

$ cat /etc/redhat-release
CentOS release 6.4 (Final)

We will need the following packages installed


yum install dhcp httpd tftp-server syslinux xinetd


  • dhcp; Will hand out IP addresses to the clients during the boot process.
  • tftp-server; This is a PXE compliant FTP server that serves the core boot files to the remote machine.
  • syslinux; Handles special boot files that the remote machine needs to boot.
  • httpd;  Apache webserver that will host the Centos iso image or the DVD using HTTP.




I have setup a Centos PXE server which has 2 NICS
Their IP addresses are
  eth0 : 192.168.1.22  (connected to home router and internet - setup as static ip)
  eth1 : 192.168.0.21  (connected to a switch , PXE client also will be connected to this switch)


Make sure both devices eth0 and eth1 show up when u run the command "system-config-network" as root.
If not simply add by selecting
This will create the interface files in /etc/sysconfig/network-scripts namely
  ifcfg-eth0 and ifcfg-eth1

File contents below.


ifcfg-eth0




[root@xpsi7 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID="fc145c85-edb5-46a6-aef1-c6edbcd2f189"
IPADDR=192.168.1.22
PREFIX=24
GATEWAY=192.168.1.1
DNS1=209.18.47.61
DNS2=209.18.47.62
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:25:64:EE:DD:52
LAST_CONNECT=1350566375
USERCTL=no

ifcfg-eth1


[root@xpsi7 network-scripts]# cat ifcfg-eth1
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY=192.168.1.1
DNS1=209.18.47.61
DEVICE=eth1
BOOTPROTO=none
NETMASK=255.255.255.0
DNS2=209.18.47.62
TYPE=Ethernet
IPADDR=192.168.0.21
HWADDR=00:22:6B:C3:6D:09
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
ONBOOT=yes
[root@xpsi7 network-scripts]# 

Next edit the file /etc/sysconfig/dhcpd 


 This will make sure that just eth1 will be used to serve dhcp.


[root@xpsi7 sysconfig]# cat dhcpd
# Command line options here
DHCPDARGS="eth1";



File : /etc/dhcp/dhcpd.conf

Change your IP's appropriately if required.

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#

allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
next-server 192.168.0.21;
filename "/pxelinux.0";

subnet 192.168.0.0 netmask 255.255.255.0{
        range                                       192.168.0.100   192.168.0.200;
        option routers                          192.168.0.21;  # default gateway
        option subnet-mask                  255.255.255.0;
        option broadcast-address        192.168.0.255;
        option domain-name-servers    192.168.0.10;  # This DNS server does not exist.
        option domain-name                 "xpsi7.lan";
}

Start the dhcp service

[root@xpsi7 #] service dhcpd start


Setting up Apache

Once you install Apache by "yum install apache"
it will create its Document Root in 
   /var/www/html

[root@xpsi7 #] mkdir centos-inst
[root@xpsi7 #] cp -r Centos_6.4_Final/*  /var/www/html/centos-inst/
(you may be able to mount the .iso file if you have not burned it to a dvd using the command
mkdir /mnt/centos
mount -o loop CentOS-6.4-x86_64-bin-DVD1.iso /mnt/centos/
cp -r /mnt/centos/* /var/www/html/centos-inst/
)

Test the Apache installation by
[root@xpsi7 #]  service httpd start

Try to access the page http://192.168.1.22 or http://localhost 
and also http://192.168.1.22/centos-inst/
You should be able to see the Apache test page and
You should be able to see the contents of the Centos DVD that you just copied above.



Disable SELinux


# vim /etc/sysconfig/selinux

Set the line SELINUX=enforcing to

SELINUX=disabled
Disable SELinux immediately without a reboot

setenforce 0




TFTP Setup


Create a directory to store your tftp files. I chose /tftpboot

# mkdir /tftpboot

# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
# cp /usr/share/syslinux/menu.c32 /tftpboot/
# cp /usr/share/syslinux/memdisk /tftpboot/
# cp /usr/share/syslinux/mboot.c32 /tftpboot/
# cp /usr/share/syslinux/chain.c32 /tftpboot/

Create a directory to store your pxe config
# mkdir /tftpboot/pxelinux.cfg

PXE MENU

# vim pxelinux.cfg/default
Add the following to the default file


# create new
timeout 100
default menu.c32

menu title ########## PXE Boot Menu ##########
label 1
   menu label ^1) Install CentOS 6
   kernel centos6/vmlinuz
   append initrd=centos6/initrd.img method=http://192.168.1.22/centos-inst devfs=nomount

label 2
   menu label ^2) Boot from local drive
   localboot



configure xinit for tftp

# vim /etc/xinetd.d/tftp

You need to update the following two lines
server_args = -s /tftpboot
disable = no

Now the config  file looks like this

service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}

Restart xinit for your changes to take effect

# /etc/init.d/xinetd restart

you can make sure the tftp service is running by running the "chkconfig --list" command and you should see tftp on under xinetd based services:
tftp:           on


Debugging Issues:

 Whenever you start a service and it FAILED check /var/log/messages to see detailed error messages and google for help.

 Install Centos using PXE.

1. Connect the machine on which Centos will be installed using PXE to the switch which is also connected to the PXE server (eth1)
2. Make sure the BIOS is setup to boot using PXE and Press F12 for Boot menu and select network install.
3. The DHCP server on the Centos PXE server  should hand out the IP and should present you the PXE menu. 
4. Now simply install Centos following on screen instructions.


Next Steps

I want to setup virtual machines using KVM and do a network install on the  same Centos server. 
The host will act as PXE server and the virtual machines will be installed on the same host using network install.




Monday, February 11, 2013

Sync directories between 2 hosts using rsync

rsync -avz  .  -e 'ssh -p 23421' remoteuser@remote_ip:/gb500

- syncs the current directory (source) with the destination directory /gb500.
- connects on remote ssh port 23421 (changed 22 to 23421)

Followers

About Me

Torrance, CA, United States