Thursday, July 21, 2011

Installing CentOS via local FTP using PXE and unRAID

So I have my unRAID server serving PXE requests, now what? Well: install CentOS of course!
CentOS is an Enterprise-class Linux Distribution and they have created some nice tools to be able to create a PXE installation environment, here is how I did it.



Setting up Anonymous FTP

Fist we need an FTP server and unRAID has the standard vsftpd build in, we'll use that.

But there are some steps to take to make it compatible with the CentOS installer.
By default the only user allowd is 'root' so first we must change that.
  1. First we need a directory where our 'Anonymous' FTP users go when they connect, run: mkdir -p /mnt/user/SERVER/FTP_ROOT/
  2. Create a anonymous ftp user, run: useradd ftp -m
  3. If you get an error that the user already exists, create a homefolder for it: mkdir /home/ftp
  4. Copy the unRAID default vsftpd.conf file to your flash drive, run: cp /etc/vsftpd.conf /boot/config/(I like editing in Windows, but if you are really determent you can do it in vi)
  5. Open the file \\tower\flash\config\vsftpd.conf in your favorite text editor (like Windows notepad, but I prefer Notepad2)
  6. Edit it, so it looks like this:
  7. # vsftpd.conf for unRAID
    #
    write_enable=NO
    connect_from_port_20=YES
    #
    # anonymous logins
    anonymous_enable=YES
    anon_root=/mnt/user/SERVER/FTP_ROOT
    anon_world_readable_only=YES
    #
    # Allow local users to log in.
    local_enable=YES
    local_umask=077
    local_root=/mnt/
    check_shell=NO
    #
    # All file ownership will be 'root'
    guest_enable=NO
    anon_upload_enable=NO
    anon_other_write_enable=NO
    anon_mkdir_write_enable=NO
    #
    # Logging to syslog
    syslog_enable=YES
    log_ftp_protocol=NO
    xferlog_enable=NO
    #
    # Misc.
    dirmessage_enable=NO
    ls_recurse_enable=YES
  8. Now save it back to its drive and run the command: cp /boot/config/vsftpd.conf /etc/
  9. Also add this line to your 'go' script (\\tower\flash\config\go)
  10. Now restart the FTP server, run the command: /etc/rc.d/rc.inetd restart
  11. You should be able to connect to your server using an FTP client, for Windows I recommend the free application FileZilla. Just fill in your server name or IP adress and hit connect.
  12. If you already put files in this directory you can make them visible by setting them 'World readable', do:  chmod -R -c 755 /mnt/user/SERVER/FTP_ROOT/



Getting the files


Although it is possible to install CentOS by loading the ISO and installing it form there, its faster and more practical to use the separate packages from the /centos//os/ directory because you then only have to load what you need from your local FTP server, witch makes the installation faster and easy to script.
I will be downloading the 6.0 distribution since that is the current build at this moment.

  1. Create a directory structure for your files: mkdir -p /mnt/user/SERVER/FTP_ROOT/CentOS/6.0/os/i386/
    Optionally you can also create a /os/x86_64/ directory if you need the 64bit version
  2. Find a mirror nearby from the CentOS public mirror list, find one that has RSYNC support, copy the link to the RSYNC link to you clipboard.
  3. Now run the command: rsync -avSHP rsync://mirror.near.you/centos/6.0/os/i386/ /mnt/user/SERVER/FTP_ROOT/CentOS/6.0/os/i386/ Make sure you replace the red part with the link you have in your clipboard. For the x64 edition change the link and the path accordingly.
  4. Now let rsync download all the required files, no worry's; if the connection drops during transmission it will pickup where it left of. Depending on your connection this may take a while, the download is about 4.37GB
  5. Now we need to copy 2 of the files from here to our 'PXE images' directory, first create a directory, run: mkdir -p /mnt/user/SERVER/tftpboot/images/CentOS/i386/6.0/
  6. Then copy over the files: cp /mnt/user/SERVER/FTP_ROOT/CentOS/6.0/os/i386/images/pxeboot/* /mnt/user/SERVER/tftpboot/images/CentOS/i386/6.0/ If it say's "cp: cannot stat `/mnt/user/SERV....etc" it means your download is not completed yet and the directory is empty. you might wanna try this step later or download the files from an FTP server (also in the mirror list)
  7. Make them 'world readable' by running: chmod -R -c 755 /mnt/user/SERVER/FTP_ROOT/
Modify your PXE config file

Now we have downloaded the files (or your download is still running in the background) we can modify our PXE menu to be able to boot to the CentOS installer.
  1. Open the default file with your favorite text editor If you have followed my post about PXE on unRAID it is in \\TOWER\server\tftpboot\pxelinux.cfg\
  2. Add these lines to it: LABEL CentOS 6 x86 Manual MENU LABEL Install CentOS 6 x86 manually from FTP KERNEL images/CentOS/i386/6.0/vmlinuz APPEND initrd=images/CentOS/i386/6.0/initrd.img ramdisk_size=100000 ks=ftp://x.x.x.x/CentOS/6.0/os/i386/config/manual.cfg Make sure you replace the x.x.x.x with the IP or hostname of your FTP server.
  3. You can now start the installation via PXE, only you need to select all the options manually (Local media or URL, location of kickstart script, etc) we don't want that, so let's creator some kickstart scripts.

Creating CentOS kickstart scripts

Now you may have noticed I refer to a ftp://x.x.x.x/CentOS/6.0/os/i386/config/manual.cfg file, and if you have try'd to start the CentOS installation you might have noticed the installation asks for the correct location, so lets create some.
  1. Create a folder structure to hold your CentOS kickstart configuration files, run: mkdir /mnt/user/SERVER/FTP_ROOT/CentOS/6.0/os/i386/config/
  2. Open your favorite editor and create a new file with the following contents, this will create our 'manual' installation, it just sets the FTP path, the keyboard layout and assigns a DHCP address to the fist ethernet adapter it finds. For more information about kickstart scripts just do a google search for "kickstart centos" or "kickstart anaconda" and you will find a massive amount of websites and tutorials or take a look at the CentOS wiki. # Kickstart file for a manual FTP install. install url --url ftp://x.x.x.x/CentOS/6.0/os/i386/ lang en_US.UTF-8 keyboard us # Start the network driver and assign the client a dynamic IP network --device eth0 --bootproto dhcp Make sure you replace the x.x.x.x with the IP or hostname of your FTP server
  3. Save the file to your server in \\tower\SERVER\FTP_ROOT\CentOS\6.0\os\i386\config\ and name it: manual.cfg
  4. Make sure the files in the FTP directory are 'world readable' run chmod -R -c 755 /mnt/user/SERVER/FTP_ROOT/ once more.
  5. Test the installation, you should now get a step-by-step installation of CentOS that downloads all the files of the FTP server when it needs to.


As I said, there are very elaborate sites about using kickstart scripts. This is a very nice one I found by 'Security Nut' aka Damian Tommasino it's a basically installing a complete (bare server) OS completely automatic!
I've modify'd it a bit to suit my needs, but you can always try the original.
WARNING! If you uncomment the red section it will wipe your hard disk!

# Kickstart file for a basic FTP install.
install
url --url ftp://x.x.x.x/CentOS/6.0/os/i386/
lang en_US.UTF-8
keyboard us

# Start the network driver and assign the client a dynamic IP
network --device eth0 --bootproto dhcp

# Set the root password
rootpw --iscrypted

# Enable the firewall and open port 22 for SSH remote administration
firewall --enabled --port=22:tcp

# Setup security and SELinux levels
authconfig --enableshadow --enablemd5
selinux --permissive

# Set the timezone
timezone --utc Europe/Amsterdam

# Create the bootloader in the MBR with drive hda being the drive to install it on
bootloader --location=mbr --driveorder=hda

# Wipe all partitions and build them with the info below
# ***hda may be different on your machine depending on the type of drives you use***
#clearpart --drives=hda --all --initlabel
#part /boot --fstype ext3 --size=100
#part / --fstype ext3 --size=5000
#part swap --size=2000
#part /home --fstype ext3 --size=100 --grow

# Install the Base and Core software package groups for a minimal install, plus OpenSSH server & client
%packages
@Core
@Base
openssh-clients
openssh-server

No comments:

Post a Comment