< Back to Blogs
PXE Dust: The magic of CD-less installs... by MichaelF on September 01, 2006 07:19PM

(Special thanks to Dan Simonton & Kyle Adams for the testing and writing of this tech tip)

 

Have you ever stood in front of a server you are building, feeding it install cds, and thought to yourself “it just doesn’t get any better than this…?”

 

Me neither.

 

But look at the bright side: That growing collection of CDRS that are now spilling over the top of the spindle will make an excellent conversation piece when you have guests in your facility. It also makes for an interesting makeshift “jenga” type game. Ok, maybe not. The point is, there are alternatives.

 

After a growing frustration with having to burn new install discs every time one got a scratch in the wrong place, misplaced, or needing them while they were currently in use, some of the other penguins and I said, “STOP THE INSANITY!!”, and then endeavored to build ourselves a PXE boot server for our lab so we could install our machines on the fly. We anticipate this being a major time saver in the future.

 

If you live in an IT cave or for some other reason are unfamiliar with PXE boot systems, the acronym itself stands for “Preboot Execution Environment”. It is a boot option that is built into the firmware of the bios on most modern network interface cards. Essentially it is a coupling of dhcp(bootp) and tftp. Basically, a dhcp request is sent out from the client machine, it receives an ip address and a file with instructions to complete the transaction. From here, the install process is initiated. That’s the short version. If you want the long version, look here: http://www.pix.net/software/pxeboot/archive/pxespec.pdf

 

We set ours up on a machine with a dhcp server, tftp server, and an apache web server. It is possible to setup the PXE system, adding it to the configuration of an existing, authoritative dhcp server, but for the sake of simplicity, we kept ours on a separate machine running RHEL4 AS. If an authoritative DHCP server already exists on the network, it is important that the following option be applied to it’s configuration under the subnet specification:

 

          ignore bootp;

 

This ensures it will not attempt to answer requests by the PXE client. Otherwise, any PXE installation you attempt may not make it very far.

 

On the PXE dhcp server, you will want to setup with the following options

 

          not authoritative;

            allow bootp;

           

subnet 192.168.1.0 netmask 255.255.255.0 {

        range dynamic-bootp 192.168.0.200 192.168.0.254;

        max-lease-time 3600;

        default-lease-time 3600;

        option routers 192.168.1.1;

        option subnetmask 255.255.255.0;

        filename "pxelinux.0";

}

 

We kept the lease time at 1 hour. Once the install is complete (which should only take a third of that time), it won’t need it anymore, so we figured this was sufficient. It is important to note the “not authoritative” option at the top, as this will prevent unintended machines from leasing non-routable ip addresses from the machine.

 

We then mounted the FC5 iso images on a loopback and copied all of the files over to a directory we created called FC5, under /tftpboot.

         

          mkdir /tmp/FC5

          mount –o loop FC-5-i386-disc1.iso /tmp/FC5

            cp –r /tmp/FC5/* /tftpboot/FC5

 

We repeated this process for disc 2-5.

 

In our /etc/httpd/conf/httpd.conf file, we’ve added the following directory options.

 

          <Directory /tftpboot/FC5>

  Options Indexes

  AllowOverride None

</Directory>

  Alias /linux /tftpboot/FC5

 

As the directory specification “FC5” might suggest, we’re using this to install Fedora Core 5 from the PXE server. This specification within the httpd.conf gives Anaconda access to the necessary files to install FC5 via http. 

 

It’s worthy of mention that you can choose to do this for as many operating systems as you wish to install.  We primarily run RHEL4 and Fedora Core 5 systems for the sake of uniformity, so we’ll use RHEL4 in this example. Next we copied  initrd.img and vmlinuz files from both /tftpboot/FC5/isolinux and /tftpboot/RHEL4/isolinux into the upper /tftpboot directory and renamed them according to distribution (rhel4-initrd.img and rhel4-vmlinuz for example).

 

Next we have to setup the tftp server. If the file does not exist under /etc/xinetd.d, it will need to be created (but most likely, it’s already there). It should have the following options specified:

 

          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

}

 

Next, create the directory /tftpboot/pxelinux.cfg and make it world-readable. Inside this directory, we need to create eight zero-byte files which represent 192.168.0.254 (use the “touch” command).

 

touch C
touch C0
touch C0A
touch C0A8
touch C0A80
touch C0A800
touch C0A800F
touch C0A800FE

 

and lastly, a 9th file for the MAC address, with 01 pre-pended to the beginning

 

            touch 01-AA-BB-CC-DD-EE-FF

 

The AA-BB-CC-DD-EE-FF portion of course, replaced with the actual mac address of the interface you will be using.  If you do not have this information, it can be obtained via:

 

          $ ifconfig

 

            eth0      Link encap:Ethernet  HWaddr

00:C0:A8:8D:D0:D0 ß ß ß

inet addr:192.168.1.1  Bcast:157.55.215.255  Mask:255.255.248.0

 

Next we create a file called “default” with the following added to it:

 

          prompt 1

default linux-fc5 ks=http://10.197.173.80/FC5/ks.cfg

timeout 100

 

label linux-fc5

kernel vmlinuz-fc5

append initrd=initrd-fc5.img ramdisk_size=9216 noapic acpi=off

 

label linux-rhel4

kernel vmlinuz-rhel4

append initrd=initrd-rhel4.img ramdisk_size=9216 noacpi acpi=off

 

The options are pretty much the same as you would see in a grub configuration. You can add kickstart file options here if you wish, as noted above. With this configuration, once we reach the PXE linux boot prompt, we can specify either the linux-fc5 or linux-rhel4 to begin the install. If you wish to use a kickstart file, simply specify the location next to the kernel option. As you can see, in our example, it is being taken from an http connection on a different machine. One final step, copy /usr/syslinux/pxelinux.0 into your /tftpboot directory and you should be ready to go.

 

The final step in the process would be to actually perform an install. On the machine intended for this, go into your bios and place PXE/Network boot in the order before harddrive (if there is an OS present on the machine already). Alternatively, if there is a key-press option (such as f12) on post, you could do that as well. You should see the dhcp client address request progress on screen. Once the address has been obtained, you will see the files specified under /tftpboot/pxelinux.cfg directory load and will get a “boot:” prompt. At this point, specify the label of the kernel you wish to boot (these were defined in your /tftpboot/pxelinux.cfg/default file).  The install process should now begin.

 

That’s all there is to it.

 

Comments RSS
  1. rhorn said:

    That seems a lot more complicated than it needs to be.

    The Debian documentation for doing the same thing isn't nearly as long.  How does Apache play into the picture?

    http://www.us.debian.org/releases/stable/i386/ch04s06.html.en

    posted at 03:11AM 09/04/2006
  2. ickiller said:

    There seem to be an error in you DHCP configuration. The IP range given (range dynamic-bootp 192.168.0.200 192.168.0.254;) doesn't match the network/netmask/routers of the block they are in (192.168.1.x). Why do you create the 9 empty files in /tftpboot? The "default" is IMHO enough as the others are empty anyway.

    posted at 03:06AM 09/05/2006
  3. hjanssen said:

    In the lab we frequently do reloads of all kinds of distro's of Linux and Windows OS's. We put the PXE server in to make our lives a little easier. The article written was a result of us putting in our PXE server. After we did, we realized that it would be a good techtip. There are probably a dozen different ways to create the same thing; but we chose a method that was most relevant to our existing lab infrastructure. The Debian article is relatively Debian-specific and refers to a few pieces of somewhat “legacy” software, particularly in its mention of inetd and bootpd. We chose a means of implementing a PXE system that would support multiple operating systems, including those without network install support for FTP and NFS mounts. Nearly every operating system that can be installed over a network will support http. We didn’t feel that adding a few lines to an apache configuration was too much trouble to warrant against doing so. Thanks, Hank.

    posted at 02:42PM 09/08/2006
  4. jjesse said:

    Great article, bookmarked this.  Would also like any further information you might have in regards to this

    posted at 02:53PM 09/15/2006
  5. hjanssen said:

    I just realized that one of my previous comments showed up twice. Seems to be a leftover from the problems we had last week.

    Sorry about that.!

    Hank.

    posted at 04:48PM 09/19/2006
  6. MoobyFR said:

    "we need to create eight zero-byte files which represent 192.168.0.254 (use the “touch” command).

    (touch C C0 C0A C0A8 C0A80 C0A800 C0A800F C0A800FE )"

    This isn't right: the value must represent the ip of the computer, so 192.168.1.1 in your example.

    and these files aren't needed: if not present, "default" is used. these files are used when you want a particular setup for an ip or a subnet C0A800FE=IP/32 C0A800F=IP/28 C0A800=IP/24 ...

    the file 01-AA-BB-CC-DD-EE-FF with the MAC adress must be lowercase too.

    Emmanuel

    posted at 03:09AM 11/05/2006
  7. Kad said:

    I know that this is an old thread, but I found this on the Gentoo site found at http://www.gentoo.org/doc/en/altinstall.xml

    Diskless install using PXE boot

    Requirements

    You will need a network card on the diskless client that uses the PXE protocol to boot, like many 3com cards. You will also need a BIOS that supports booting from PXE.

    Server base setup

    Create directories: The first thing to do is to create the directories where your diskless system will be stored. Create a directory called /diskless which houses a directory for each diskless client. For the rest of this howto we'll be working on the client 'eta'.

    Code Listing 4.1: Directory setup

    # mkdir /diskless

    # mkdir /diskless/eta

    # mkdir /diskless/eta/boot

    DHCP and TFTP setup: The client will get boot informations using DHCP and download all the required files using TFTP. Just emerge DHCP and configure it for your basic needs. Then, add the following on /etc/dhcp/dhcpd.conf.

    Note: This provide a static IP address for the client and the path of a PXE boot image, here pxegrub. You have to replace the MAC address of the Ethernet card of the client and the directory where you will put the client files with the one you use.

    For DHCPd, run emerge dhcp (or any other DHCP server of your choice). Make sure that the correct interface is selected in /etc/conf.d/dhcp.

    Code Listing 4.2: dhcp.conf

    option option-150 code 150 = text ;

    ddns-update-style none ;

    host eta {

    hardware ethernet 00:00:00:00:00:00;

    fixed-address ip.add.re.ss;

    option option-150 "/eta/boot/grub.lst";

    filename "/eta/boot/pxegrub";

    }

    Next you'll need to configure your interface in /etc/conf.d/net so that it doesn't get cleared at bootup. See /etc/conf.d/net.example for more information.

    Code Listing 4.3: /etc/conf.d/net

    (Replace eth0 with the correct interface)

    config_eth0=( "noop" )

    For TFTP, emerge app-admin/tftp-hpa. In /etc/conf.d/in.tftpd, put the following :

    Code Listing 4.4: in.tftpd

    INTFTPD_PATH="/diskless"

    INTFTPD_USER="nobody"

    INTFTPD_OPTS="-u ${INTFTPD_USER} -l -vvvvvv -p -c -s ${INTFTPD_PATH}"

    Setup GRUB: To provide PXE booting I use GRUB with the netboot USE flag enabled. Once GRUB is compiled, copy the PXE image to the diskless client's boot directory. Then edit its grub.lst config file.

    Code Listing 4.5: Grub setup

    # echo "sys-boot/grub netboot" >> /etc/portage/package.use

    # emerge -av grub

    # cp /usr/lib/grub/pxegrub /diskless/eta/boot/pxegrub

    # nano -w /diskless/eta/boot/grub.lst

    Code Listing 4.6: grub.lst

    default 0

    timeout 30

    title=Diskless Gentoo

    root (nd)

    kernel /eta/bzImage ip=dhcp root=/dev/nfs nfsroot=ip.add.re.ss:/diskless/eta

    # For the nfsroot option, the IP address is the one of the server and

    the directory is the one where your diskless client files are located (on the server).

    Setup NFS: NFS is quite easy to configure. The only thing you have to do is to add a line on the /etc/exports config file:

    Code Listing 4.7: /etc/exports

    # nano -w /etc/exports

    # /etc/exports: NFS file systems being exported.  See exports(5).

    /diskless/eta eta(rw,sync,no_root_squash)

    Update your hosts: One important thing to do now is to modify your /etc/hosts file to fit your needs.

    Code Listing 4.8: /etc/hosts

    127.0.0.1 localhost

    192.168.1.10 eta.example.com eta

    192.168.1.20 sigma.example.com sigma

    Creating the system on the server

    You might want to reboot the server with a Gentoo Install CD, although you can very well continue immediately if you know how to proceed with the Gentoo Installation Instructions from an existing installation. Follow the standard install procedure as explained in the Gentoo Handbook BUT with the following differences: When you mount the file system, do the following (where hdaX is the partition where you created the /diskless directory). You do not need to mount any other partitions as all of the files will reside in the /diskless/eta directory.

    Code Listing 4.9: Mounting the filesystem

    # mount /dev/hdaX /mnt/gentoo

    Stage tarballs and chroot: This example uses a stage3 tarball. Mount /proc to your diskless directory and chroot into it to continue with the install. Then follow the installation manual until kernel configuration.

    Warning: Be very careful where you extract your stage tarball. You don't want to end up extracting over your existing installation.

    Code Listing 4.10: Extracting the stage tarball

    # cd /mnt/gentoo/diskless/eta/

    # tar -xvjpf  /mnt/cdrom/gentoo/stage3-*.tar.bz2

    # mount -t proc /proc /mnt/gentoo/diskless/eta/proc

    # cp /etc/resolv.conf /mnt/gentoo/diskless/eta/etc/resolv.conf

    # chroot /mnt/gentoo/diskless/eta/ /bin/bash

    # env-update

    # source /etc/profile

    Kernel configuration: When you do the make menuconfig of your kernel configuration, don't forget to enable the following options with the others recommended into the install howto.

    Code Listing 4.11: menuconfig options

    - Your network card device support

    (In the kernel, *not* as a module!)

    - Under "Networking options" :

    [*] TCP/IP networking

    [*] IP: kernel level autoconfiguration

    [*] IP: DHCP support

    [*] IP: BOOTP support

    - Under "File systems --> Network File Systems" :

    <*> NFS file system support

    [*] Provide NFSv3 client support

    [*] Root file system on NFS

    Save the kernel in your chrooted / (not in /boot) according to the pxegrub setting defined earlier. Next configure your diskless client's /etc/fstab.

    Code Listing 4.12: /etc/fstab

    # nano -w /etc/fstab

    /dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0

    proc /proc proc defaults 0 0

    tmpfs /dev/shm tmpfs nodev,nosuid,noexec 0 0

    You also need to prevent the client to run a filesystem check:

    Code Listing 4.13: Preventing the client to run a filesystem check

    # touch /fastboot

    # echo "touch /fastboot" >> /etc/conf.d/local.start

    Install nfs-utils since your client will heavily depend on it:

    Code Listing 4.14: Installing nfs-utils

    # emerge nfs-utils

    Bootloader. Don't install another bootloader because we already have one - pxegrub. Simply finish the install and restart the server. Start the services you'll need to boot the new client: DHCP, TFTPD, and NFS.

    Code Listing 4.15: Starting services

    # /etc/init.d/dhcp start

    # /etc/init.d/in.tftpd start

    # /etc/init.d/nfs start

    Booting the new client

    For the new client to boot properly, you'll need to configure the bios and the network card to use PXE as the first boot method - before CD-ROM or floppy. For help with this consult your hardware manuals or manufacturers website. The network card should get an IP address using DHCP and download the GRUB PXE image using TFTP. Then, you should see a nice black and white GRUB bootmenu where you will select the kernel to boot and press Enter. If everything is ok the kernel should boot, mount the root filesystem using NFS and provide you with a login prompt. Enjoy.

    posted at 07:41AM 11/06/2007
Post a Comment
*
*