Sunday, February 14, 2010

Using Apt-Mirror with Debian/Ubuntu netbooting

Just want to share my experiences in configuring your own local apt-mirror to use with netboot installation methods of Debian/Ubuntu. I did this setup in a Debian Lenny 32bit Server inside a VM instance.

First off, the main packages that you do need to install onto your server are...

For your netboot:
# apt-get install tftpd-hpa dhcp3-server

The DHCP server is optional if your network already have a separate machine that handles that since we could use that...

For your apt-mirror and sharing it:
# apt-get install apt-mirror apache2

The first thing that you initially have to do is add something to the configuration file of your DHCP server. Apart from the basic configurations in defining your intended subnet, there is a few additional configurations to be added specifically for your netbooting. You have to add a few lines inside your /etc/dhcp3/dhcpd.conf that will handle redirection of those requesting an IP address and are in PXE booting mode. Below is a sample that needs to be added inside your subnet declaration.

#this is what is inside my DHCP server conf file

subnet 10.10.0.0 netmask 255.255.0.0
{

range 10.10.1.1 10.10.1.199;

option broadcast-address 10.10.255.255;
option router 10.10.1.254;
allow unknown-clients;

#this is what I added for the netboot
next-server (URL or IP of netboot server);
filename "pxelinux.0";
}


Afterwards, you need to edit your /etc/apt/mirror.list to point to the desired mirror server ubuntu/debian resources that you want to copy or mirror. The contents and format of mirror.list is quite similar to what is contained on your /etc/apt/sources.list. There is only one more important detail that needs to be added, which is a "main/debian-installer" and "restricted/debian-installer". To do this, just add an additional entry of a source in your mirror.list that looks something like below, just change the values accordingly to what you intend (if debian or ubuntu and what distro version).

#my sample here is something for Ubuntu Karmic mirror

deb http://(URL of external mirror site)/ubuntu karmic main restricted
deb http://
(URL of external mirror site)/ubuntu karmic main/debian-installer restricted/debian-installer
clean http://
(URL of external mirror site)

Upon doing this, do a "sudo apt-mirror" so that it will start fetching the packages and such into your local mirror server. For the sample I shown a while ago, it was around 6.7 GB worth of packages, therefore be mindful of the storage capacity of your server and your bandwidth. This will definitely take some time, so let's configure the other stuff you need.

Remember I had you install apache2? We're going to need this to make your apt-mirror visible and can be shared over the network easily. What we only need to do, as a quick configure, is to make a soft-link of your apt-mirror sources file directory (/var/spool/apt-mirror/mirror/) into the default directory of apache2 (/var/www/). Below is a sample on the command to do this.

#if you are making a debian apt-mirror
sudo ln -s /var/spool/apt-mirror/mirror/(URL of external mirror site)/debian /var/www/debian
#if you are making an ubuntu apt-mirror
sudo ln -s /var/spool/apt-mirror/mirror/(URL of external mirror site)/ubuntu /var/www/ubuntu

Afterwards, run your apache2 server and try to view it with your browser (localhost/ubuntu or localhost/debian). You should see a directory on display that somewhat contains packages and stuff that is being fetched by your apt-mirror.

Now we configure your TFTPBOOT. First off, we need to edit your /etc/default/tftpd-hpa file. Try to mimic the settings shown below.

#defaults of the tftpd-hpa with RUN_DAEMON set to YES

RUN_DAEMON=yes
OPTIONS="-l -s /var/lib/tftpboot"

The directory /var/lib/tftpboot is the default directory where your intended netboot images will be placed. You are free to change this value but just be mindful of the needed permissions or ownership of the file or directory as it might be cause some trouble. You can copy into this directory the netboot files of either Ubuntu or Debian. The images that you need can be downloaded here for Debian and here for Ubuntu. In some cases, the default directory doesn't exist so you might need to mkdir one.

After you have placed a netboot image, we then try to run it by...

# /etc/init.d/tftpd-hpa start

To check if it is working, try to boot-up a PC (of course with PXE network booting capabilities) that is connected to your network. If that PC boots up to a network installation menu of the distro that you pasted in your tftpboot directory, it means that things are working for your netboot.

To check if your apt-mirror is working and sharing, during your netboot installation it will ask for a mirror site, you should select the topmost option from the list which gives you a way to manually define the mirror URL. Just type in the IP address of your mirror server and press enter for the defaults of the remaining questions related to it. if it proceeds to the next step of your installation, it is therefore working.

One problem that I encountered while configuring my apt-mirror is that the "debian-installer" is missing, and possible reasons for this is not being included in the /etc/apt/mirror.list or the selected URL site being mirrored doesn't have that resources. Changing the sources and re-run the apt-mirror should do the job.

Some sources I used in making this are listed below. Credits to the writers of the guides.
  • http://www.debian-administration.org/articles/478
  • http://www.howtoforge.org/local_debian_ubuntu_mirror
Hope my guide helps some of you guys out there.

No comments:

Post a Comment