Software Engineer

stop burning physical media to install linux – setting up networking booting on a fedora 12 machine to boot CentOS workstations

· by jsnby · Read in about 7 min · (1365 Words)

First, I’d like to thank Cory Wynn. Without his help and inspiration, I probably would still be burning images to physical media for OS installation. Next, let’s talk about what you will need to pull this off. I have Fedora 12 x86_64 running on my laptop. I have a server on which I would like to put CentOS 5.4. I’d like to do this without burning a DVD image for installation (because the box doesn’t have an optical drive). To pull this off, you will need your laptop, your server, two network cables, and a network switch. The network switch should NOT be plugged into any network. We want to create a temporary isolated installation network for the convenience of installing the OS image. I’m going to assume you have root access on your laptop. Let’s get started…

Disable selinux on your laptop. Edit /etc/sysconfig/selinux. Make sure SELINUX is set to disabled: SELINUX=disabled

Then reboot your laptop: /sbin/shutdown -r now

Install some required software on your laptop: yum install tftp-server syslinux httpd cronolog dhcp

Edit /etc/xinetd.d/tftp and change disable to no

Make some directories on your laptop and copy some files into place:

mkdir -p /var/lib/tftpboot/pxelinux.cfg
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
cp /usr/share/syslinux/memdisk /var/lib/tftpboot/
cp /usr/share/syslinux/mboot.c32 /var/lib/tftpboot/
cp /usr/share/syslinux/chain.c32 /var/lib/tftpboot/

mkdir -p /var/lib/tftpboot/images/centos/x86_64/5.4
mkdir -p /var/lib/tftpboot/images/fedora/x86_64/12

mkdir -p /var/www/installation/iso
mkdir -p /var/www/installation/centos/x86_64/5.4
mkdir -p /var/www/installation/fedora/x86_64/12

I’m going to assume that you have already downloaded the .iso images that you want to be able to boot over the network. For our example, I’m going to set my machine up to offer both CentOS 5.4 and Fedora 12, both x86_64. I’m going to assume that you’ve downloaded the .iso images to /tmp/. Move the .iso files into the following locations:

mv /tmp/CentOS-5.4-x86_64-bin-DVD.iso /var/www/installation/iso
mv /tmp/Fedora-12-x86_64-DVD.iso /var/www/installation/iso

Add this to /etc/fstab to mount the .iso images:

/var/www/installation/iso/CentOS-5.4-x86_64-bin-DVD.iso   /var/www/installation/centos/x86_64/5.4  udf,iso9660     user,loop       0 0
/var/www/installation/iso/Fedora-12-x86_64-DVD.iso        /var/www/installation/fedora/x86_64/12   udf,iso9660     user,loop       0 0

Then run mount -a to mount all volumes listed in /etc/fstab.

Copy the files from the mounted .iso images into the tftpboot folder:

cp /var/www/installation/centos/x86_64/5.4/images/pxeboot/initrd.img /var/lib/tftpboot/images/centos/x86_64/5.4/
cp /var/www/installation/centos/x86_64/5.4/images/pxeboot/vmlinuz /var/lib/tftpboot/images/centos/x86_64/5.4/
cp /var/www/installation/fedora/x86_64/12/images/pxeboot/initrd.img /var/lib/tftpboot/images/fedora/x86_64/12/
cp /var/www/installation/fedora/x86_64/12/images/pxeboot/vmlinuz /var/lib/tftpboot/images/fedora/x86_64/12/

Set up menu files: /var/lib/tftpboot/pxelinux.cfg/default:

default menu.c32
prompt 0
timeout 300


LABEL local
        MENU LABEL Boot local hard drive
        LOCALBOOT 0

        MENU LABEL CentOS
        KERNEL menu.c32
        APPEND pxelinux.cfg/CentOS

LABEL Fedora
        MENU LABEL Fedora
        KERNEL menu.c32
        APPEND pxelinux.cfg/Fedora



LABEL Main Menu
        MENU LABEL Main Menu
        KERNEL menu.c32
        APPEND pxelinux.cfg/default

LABEL CentOS 5.4 x86_64
        MENU LABEL CentOS 5.4 x86_64
        KERNEL images/centos/x86_64/5.4/vmlinuz
        APPEND initrd=images/centos/x86_64/5.4/initrd.img ramdisk_size=100000 method=



LABEL Main Menu
        MENU LABEL Main Menu
        KERNEL menu.c32
        APPEND pxelinux.cfg/default

LABEL Fedora 12 x86_64
        MENU LABEL Fedora 12 x86_64
        KERNEL images/fedora/x86_64/12/vmlinuz
        APPEND ks initrd=images/fedora/x86_64/12/initrd.img ramdisk_size=100000 method=

Configure apache. Create /etc/httpd/conf.d/virtualhost_installation.conf with the following contents:

Listen 2400
<VirtualHost *:2400>
   CustomLog "|/usr/sbin/cronolog /var/log/httpd/%Y/%m/%d/installation_access" combined
   ErrorLog "|/usr/sbin/cronolog /var/log/httpd/%Y/%m/%d/installation_error"
   DocumentRoot "/var/www/installation"

Port 2400 was picked arbitrarily. Feel free to choose another port, just remember to replace 2400 with the new port number throughout all the other configurations.

Configure iptables for http and tftp (/etc/sysconfig/iptables). We need to add the following lines:

-A INPUT -p tcp -m tcp --dport 2400 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p tcp --dport 69 -j ACCEPT

My /etc/sysconfig/iptables reads:

-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p tcp --dport 69 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2400 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

Restart iptables and apache.

You can test connectivity to apache by running this command from any other machine on your network(replace with the ip of the machine): telnet <ip> 2400

You should see something like this:

Configure your laptop to have a secondary network interface on eth0 with a static IP. To do this, I right-clicked on Network Manager, selected Edit Connections..., on the wired tab clicked add and added a new connection called eth0_1. Under the IPv4 Settings tab, set Method to Manual. Under addresses, click add. Type for address, for netmask, and for gateway. Click apply.

Configure dhcp by editing /etc/dhcp/dhcpd.conf. Don’t worry about knowing the MAC address of the machine you are installing the linux image on….you will edit this file later. My dhcpd.conf file reads:

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

allow booting;
allow bootp;
ddns-update-style interim;
ignore client-updates;


subnet netmask {
       option routers        ; #Default Gateway
       option subnet-mask    ;
       option domain-name              "";
       range dynamic-bootp;  #DHCP Range to assign
       default-lease-time 43200;
       max-lease-time 86400;

host new_machine {
        hardware ethernet 00:27:0e:02:02:b7;
        filename "/pxelinux.0";

Now, unplug your normal network cable. Plug your laptop directly into the switch for our isolated network. Click on Network Manager and disable your normal eth0 connection, then enable your new eth0_1 connection.

Make sure all services are up:

/etc/init.d/iptables restart
/etc/init.d/dhcpd restart
/etc/init.d/httpd restart
/etc/init.d/xinetd restart

If you have multiple network interfaces (such as a wireless interface), disable them, otherwise dhcpd will not start. You can get around this by editing the dhcpd.conf file, but I opted for just temporarily disabling my wireless interface for the duration of the install.

Now plug the machine that you want to install the new OS image onto directly into the isolated network switch.

On your PXE server (in my case, it’s my laptop), run tail -f /var/log/messages | grep dhcp. What we need to do is capture the MAC address of the NIC in the server that you’re installing the new OS image on.

Power up the server. You may have to adjust boot priority in BIOS settings to get your machine to boot over the network. Look at the output of your tail command. You should see something like this:

Apr  7 10:26:47 machinename dhcpd: DHCPDISCOVER from 00:27:0e:02:02:b7 via eth0

Copy 00:27:0e:02:02:b7, then open up /etc/dhcp/dhcpd.conf and replace the mac address in the new_machine section with this mac address. Restart dhcpd by running /etc/init.d/dhcpd restart. You may or may not have to reboot the server on which you’re installing the OS image.

If everything is working, you should get the PXE boot menu. Select an image to install and away you go! Install the image. When asked about network settings, leave it set to use DHCP, even if you intend on giving this machine a static address…we’ll address that in a minute. When you get to the last screen where it asks you to reboot the box, unplug the server from the switch, plug it into your network and reboot it. As the box comes back up, you should get a screen that asks if you want to configure Authentication, Network Settings, System Services, etc. If are going to use DHCP, just bypass this screen. If you want to adjust your network settings to use a static address, select the network settings and plug in your info. When you are finished, continue on. Eventually you will get a login prompt. Log in as root. If you assigned your box a static IP, I noticed that it wrote out the /etc/sysconfig/network-scripts/ifconfig-ethX files correctly, but the system wasn’t currently using them. You need to restart the network interface by typing /etc/init.d/network restart. A quick check of ifconfig should prove that you are using the assigned static IP.

Something else you might notice is that anaconda wrote out a kickstart file based on the installation parameters you gave during the install to /root/anaconda-ks.cfg. If you plan on imaging this box again in the near future (which is what I intend on doing), then you can save yourself some time by setting up your PXE boot menu to offer a kickstart install using this file. This post is long enough, so I will save that for another entry.