Home > Howtos > Setting up Ubuntu with vsFTP for network install

Setting up Ubuntu with vsFTP for network install

August 11th, 2009 matt Leave a comment Go to comments

This is the next post in the series of using Ubuntu to PXEboot other Linux installations.
Click Here to read on how to set up the TFTPboot server on Ubuntu

In our last post, we configured TFTP on the Ubuntu server and successfully tested it using VMware or a second PC. Using a menu-based system, we can select and retrieve the memtest image over network and can test memory with out setup. This is fine and dandy, and with the right hardware, (I use a Compaq Presario desktop) can prove advantageous for testing the random bits of RAM you have without the hassle of finding your UBCD or fiddling with floppy disks.

This article will cover the incorporation of Centos 5 into our TFTP server and covers setting up VSFTPd on the Ubuntu server as well as copying/merging the distribution CDs into a single installation directory. Although some information here is CentOS specific (like where the network boot floppy image is stored on the CD iso for instance) these steps can be used for any distribution of Linux that supports an install from network option. Just about everything from RedHat 6.2 all the way up to the RHEL series, Ubuntu and Ubuntu Server, Mandrake/Mandriva and the rest have a prebuilt network boot disk image to use. This is required unless you fancy building your own network boot images and initrds. (which I do not. :P )

Prerequisites:

  • Ubuntu computer with TFTP server installed and working
  • SCP/SSH access to the Ubuntu computer
  • A copy of WinSCP is highly recommended
  • Centos 5 CD images, already downloaded from a mirror listed from CentOS.org
  • An FTP client helps to diagnose connection issues but is not required.
  • We’re going to start off by copying the ISO images to the Ubuntu server first so we can perform some checks on the images to make sure they were downloaded properly. Use WinSCP to establish a connection to your Ubuntu server and create your temporary directory. Hit “F5″ to create a directory and call it something descriptive so you know what’s in there. I called mine “Centos5″.

    Copy all the files into the new directory. This is going to take a while (even on gigabit) so while we are copying the files, we can set up the FTP server. Before we get into the commands, let’s discuss the difference between HTTP and FTP for these installations.

    HTTP:Most installers support installation via HTTP. This is accessed by a URL, even when on a local network like: http://192.168.0.2/install/CentOS5/initrd.img

    FTP:Some installers support FTP installation as well which means that you don’t necessarily have to have Apache running in order to perform the installation.

    There really is no difference which distribution method you use. I have used Apache and FTP many times with great success for performing LAN installs. I do want to warn you that using Apache on a machine to distribute your installation images is not recommended as this might end up killing the server should a bunch of people discover your repository and start performing installs. If you do decide to use Apache, look for information on how to set up your own virtual host so you don’t spread your repository across the world and make sure that only people on your local network can access that directory.

    I’m using FTP because I have Apache configured for serving pages to the Internet and don’t want to saturate my internet connection with people performing distribution installs and my FTP server is blocked by my router/firewall so I know that no one on the outside can access it.

    So enough of talking, let’s get to doing stuff!

    Setting up VSFTPd

    Be sure that your user account has SUDO access before you begin. If you don’t like SUDOing all the time, you can “sudo bash” to stay as root user until you are done. You will need to be the root user to set up VSFTP and perform the necessary configuration. Go ahead and install VSFTpd:
    sudo apt-get install vsftpd

    This instructs apt-get (the package manager) to install vsftpd on the server and start it. You should now be able to connect to the Ubuntu server:

    C:\Documents and Settings\Administrator>ftp 192.168.0.2
    Connected to 192.168.0.2.
    220 (vsFTPd 2.0.6)
    User (192.168.0.2:(none)): anonymous
    331 Please specify the password.
    Password:
    230 Login successful.
    ftp> dir
    200 PORT command successful. Consider using PASV.
    150 Here comes the directory listing.
    226 Directory send OK.
    ftp> ls -la
    200 PORT command successful. Consider using PASV.
    150 Here comes the directory listing.
    drwxr-xr-x 2 0 65534 4096 Aug 11 16:53 .
    drwxr-xr-x 2 0 65534 4096 Aug 11 16:53 ..
    226 Directory send OK.
    ftp: 119 bytes received in 0.00Seconds 119000.00Kbytes/sec.
    ftp> quit
    221 Goodbye.

    The snip above shows that the FTP server is up and running, accepts anonymous connections (ideal) and is ready. By default, the VSFTPd server starts up accepting only anonymous connections requiring no password and with read only access. It is not needed to create a user for vsftpd unless you want to as the default install is pretty secure as is. Anonymous users don’t need write access and they need to be able to read from the installation media.

    Now, unlike previous FTP servers, there is no /var/lib/ftp or /var/ftp directories. Instead, VSFTP has its own directory in /home/ftp/. Unlike adding a new user to the system, there are no “dotfiles” (files with a leading . in the filename like .bash_history) like there are for normal users. This is because vsFTP uses this as the root of the FTP server and there are no need for these configuration files in the home directory.

    I would recommend keeping your distributions organized in some semblance of order. For this server, I am going to use the following structure as I plan to add more installation disks to this server later on:

    / - the root of the FTP server (from the client's perspective) This is /home/ftp on the server.
    /bootdisks - This will be for some network boot floppy images just in case I have a NIC that doesn't support TFTP
    /dist - This is the main distribution directory
    /dist/iso - This is where I'll keep the ISO images once I'm done with copying them
    /dist/installer - This is where each distribution will have its own directory for their install files..
    /dist/installer/Centos5 - This is where CentOS's installation files go

    This is recommended to keep your FTP server clean. If you use your FTP server for many different things, you will know at-a-glance what a directory is for and what it contains. It’s just good housekeeping to keep your server tidy. If you want to use this structure, then you can use the following code to get the directories set up.


    cd /home/ftp && mkdir bootdisks && mkdir dist &&\
    mkdir dist/iso && mkdir dist/installer && mkdir dist/installer/centos5

    MD5SUM check the ISOs

    Hopefully by now, the ISO images have been copied. If available, make sure you copy the MD5sum file along with them to your temporary directory on the server.

    CD into the directory and we can use MD5 to check these files using the syntax below:

    root@littleblackbox:~/Centos5# md5sum -c md5sum.txt

    This command ‘md5sum’ generates an MD5 hash which should be identical to what is in md5sum.txt. The MD5 hash is like a special checksum validation that you can use to validate that downloaded files match their sources on the server you downloaded them from. Using the above command, I get the below results indicating a valid match. If one of the files had been changed by even so much as a comma in a configuration file on the ISO, the test would have failed.

    root@littleblackbox:~/Centos5# md5sum -c md5sum.txt
    CentOS-5.3-i386-bin-1of6.iso: OK
    CentOS-5.3-i386-bin-2of6.iso: OK
    CentOS-5.3-i386-bin-3of6.iso: OK
    CentOS-5.3-i386-bin-4of6.iso: OK
    CentOS-5.3-i386-bin-5of6.iso: OK
    CentOS-5.3-i386-bin-6of6.iso: OK
    root@littleblackbox:~/Centos5#

    If you don’t have the md5sum.txt, you can still use the md5sum application. Use the command below to generate the MD5 checksums of the ISO images:

    root@littleblackbox:~/Centos5# md5sum *.iso

    This command will output the MD5 checksum and the filename for each of the files. You then compare this to what is listed on the server where you got them and compare the numbers. If they do not match, you know you got a corrupted download. Here is the MD5sums of the ISO images I have:

    dd93a6da1b900548825159206099603c CentOS-5.3-i386-bin-1of6.iso
    5441ae0a3c9efd47cd8bfab873fe20c1 CentOS-5.3-i386-bin-2of6.iso
    024ca72da4e14f79522a90bf8f4fdf9f CentOS-5.3-i386-bin-3of6.iso
    95e5e446754e76b3fa07aaf4946c0aa9 CentOS-5.3-i386-bin-4of6.iso
    0cda242797ded4b6b2ea0469984aca82 CentOS-5.3-i386-bin-5of6.iso
    889ff6389108a85780a06cd38b7375e7 CentOS-5.3-i386-bin-6of6.iso

    Mount, copy, Lather, Rinse, Repeat

    We have our FTP server and we have our validated ISO images. Now it’s time to get messy. The next part comes in mounting these CD iso images, then copying their contents to the FTP directory we made earlier. This can be tedious and can be done incorrectly, rendering a good amount of time wasted if you aren’t careful.

    We’ll start off by creating a temporary directory within the temporary directory called “source” and another one called “destination” and then mount the first ISO image into the source directory by use of the loopback option. Once mounted, we’re going to copy everything from source and put it in destination, then unmount the ISO image and repeat for the other 5 images. You can see the commands I used below:

    root@littleblackbox:~/Centos5# mkdir source
    root@littleblackbox:~/Centos5# mkdir destination
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-1of6.iso /source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-2of6.iso ./source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-3of6.iso ./source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-3of6.iso ./source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-4of6.iso ./source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-5of6.iso ./source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source
    root@littleblackbox:~/Centos5# mount -o loop CentOS-5.3-i386-bin-6of6.iso ./source
    root@littleblackbox:~/Centos5# cp -R ./source/* ./destination
    root@littleblackbox:~/Centos5# umount ./source

    What we’ve done now, is created a directory called “destination” and copied every CD to that directory, overlapping them. What this does is it puts all the CentOS install packages into one directory and adds the necessary additional files to the root of the directory where the installer can find them. Now that we’ve done this, we can move the ISO files to the FTP server’s ISO directory and the “destination” files to the centos5 directory. It is important to keep your files organized to prevent confusion so I also moved the md5sum.txt and renamed it to CentOS5-i386-MD5SUM.txt. I also went ahead and assigned the group permissions to our new files as well.

    root@littleblackbox:~/Centos5# mv *.iso /home/ftp/dist/iso
    root@littleblackbox:~/Centos5# mv md5sum.txt /home/ftp/dist/iso
    root@littleblackbox:~/Centos5# mv /home/ftp/dist/iso/md5sum.txt /home/ftp/dist/iso/CentOS-5.3-i386-MD5.txt
    root@littleblackbox:~/Centos5# mv destination/* /home/ftp/dist/installer/centos5/
    root@littleblackbox:~/Centos5# cd /home/ftp
    root@littleblackbox:/home/ftp# chgrp -R nogroup *

    Ok, so that’s the hard part. Now we have our installation files in place, our ISOs are in place (in case we need them again) and we’re ready to get those bootdisk images. Let’s take a look and see what we’re up against:

    root@littleblackbox:/home/ftp# ls dist/installer/centos5/images
    boot.iso diskboot.img minstg2.img pxeboot README stage2.img TRANS.TBL xen

    Something interesting is that pxeboot directory. Rather than having to mount a network-boot floppy and copy the files in it like demonstrated in the first Howto, they have already created the necessary images for us. This is going to speed things up a lot.

    root@littleblackbox:/home/ftp/dist/installer/centos5/images# cd pxeboot/
    root@littleblackbox:/home/ftp/dist/installer/centos5/images/pxeboot# ls
    initrd.img README TRANS.TBL vmlinuz

    Let’s copy the files over to the /tftpboot/images directory and finish up configuring the images for booting.

    More copying, Configuring the PXE Menu for tftpboot

    Remember what I said about wanting to keep things organized? Here’s where it comes into play. The initrd.img and vmlinuz files are generic filenames. They are VERY specific however and don’t play well with others. I can’t use this initrd with the vmlinuz of the Redhat 7.3 install disk we configured in the last howto as they are very different kernels and very different operating systems. This is why I mention that keeping your server clean with descriptive filenames for your images is important!

    We’ll start off by copying the files into /tftpboot/images (where we put the disk images) and rename them into something more relevant:

    root@littleblackbox:/home/ftp/dist/installer/centos5/images/pxeboot# cp * /tftpboot/images
    root@littleblackbox:/home/ftp/dist/installer/centos5/images/pxeboot# cd /tftpboot/images
    root@littleblackbox:/tftpboot/images# mv vmlinuz vmlinuz-Centos5-netboot
    root@littleblackbox:/tftpboot/images# mv initrd.img initrd-Centos5-netboot
    root@littleblackbox:/tftpboot/images# rm README -f
    root@littleblackbox:/tftpboot/images# rm TRANS.TBL -f
    root@littleblackbox:/tftpboot/images# ls
    initrd-Centos5-netboot initrd-rh73-netboot memdisk memtest vmlinuz-Centos5-netboot vmlinuz-rh73-netboot

    Now we have descriptive filenames along with the proper files in place. All that remains is to edit the menu file and we’ll be ready to test. Open up /tftpboot/menus/main.mnu and add the following text:

    label Install Centos 5
    kernel /images/vmlinuz-Centos5-netboot
    append initrd=/images/initrd-Centos5-netboot

    This code adds the “Install Centos 5″ option to our Main Menu and tells the Menu system which kernel to boot and which initial ramdisk to append to the kernel so that the installer can run. That’s all there is to needing to configure the menu system.

    Testing!

    Ok, so now we have the files in place in /home/ftp, we have the images in /tftpboot/images and we have the menu configured for our new install option. Fire up your VMware workstation or test computer and try it out.

    If you have performed all the steps necessary, after a moment of text on the screen, you should be looking at the installer for CentOS 5. Go through the normal language and keyboard options and when you get to the “Installation Method” screen, be sure you select FTP.

    When prompted, use your FTP server’s IP or hostname as the FTP “site name” then use the directory path we created “/dist/installer/centos5/” and see what happens. Since we are using vsftp’s default anonymous only mode, there’s no need to do anything further with the prompt. Hit OK and see if you get any errors.

    If all was done well, you should get a “Retrieving images” screen. If that’s the case, then congratulations! You have completed your addition of CentOS5 to your tftp server and can now do a CD-less installation of CentOS across the network. Kick back, finish the installer if you want (or power off the test machine/VMware window if you don’t want to).

    Troubleshooting

    Yeah, because even I make mistakes, here are some troubleshooting items you can use if yours just doesn’t work.

  • Timeout while contacting TFTP server
  • This means that the test computer couldn’t reach your TFTP server or the TFTP server doesn’t have the process running. You can check it by using “ps auwx | grep in.tftpd” and seeing if it is running. (The ps command may show your command “grep in.tftpd”. This doesn’t count. :P

  • Menu item shows up but says file not found
  • This means that the main.mnu has the incorrect path to the kernel image file. Check the main.mnu file and make sure that all paths start off with /images/ since this is where we put the images in our installation steps.

  • Kernel panic = no init found?
  • This means that when the network install kernel was mounted and executed, but something happened to the initial ramdisk (the initrd). Check your path in the “append” line of main.mnu and make sure it points to the correct file in /images/

  • The CentOS installer says it can’t find the installation media
  • This means that the directory you provided to the FTP site were incorrect. You may need to check with a regular FTP client. In our guide, I used “/dist/installer/centos5″ as the root path to the installation CD images. If you used something different, use that path instead.

    Afterword

    I had a lot of fun writing this HOWTO and the one before it so I hope you have fun reading it and doing the steps involved and hope that yours is up and working too. Please feel free to leave some comments regarding your experience in setting up TFTP or suggestions that you have in regards to these articles. I always appreciate people’s comments. :)

    Categories: Howtos Tags: , , ,
    1. No comments yet.
    1. No trackbacks yet.