Linux-based PXE image server?
January 6, 2009 11:15 AM   Subscribe

Need to create a PXE image server that supports ghost images. Difficulty: Linux

So my company makes a bunch of products and during testing I'm frequently breaking and needing to re-image the devices. This can be a pain as it is right now because my method is using bootable DVD's with ghost on it, and some of the devices don't have optical drives unless I hook up an external.

So I'd like to hook up a server that works with my DHCP switch to where i can set my device to network boot and it would start up in an interface where i can select the device and the image version, and it would all get pushed automatically.

I think this can be done with Windows Server, but for cost and geek reasons I'd rather use linux.

Thoughts?
posted by Industrial PhD to Computers & Internet (11 answers total) 5 users marked this as a favorite
 
It's actually very easy to set up a Linux PXE server. My former employer used to do this deploy all the Linux desktops. It was very, very nice. You might check out Clonezilla which I think is similar to Ghost. Disclaimer: have not had a chance to use it myself yet.
posted by icebourg at 11:42 AM on January 6, 2009


I was able to get Ghost PXE booting a while back, using a version that still ran on top of DOS, not the current weird embedded Windows thing. It's a bit of a process:

1. Set up dhcpd to boot memdisk.i from syslinux
2. Set up tftpd to serve your DOS image
3. Set up your DOS image to run ghost via autoexec.bat

So when you boot over the network, memdisk.i is loaded at PXE time, which then downloads the DOS image into memory, where it then acts as a disk and the system boots. Trouble was, I could never figure out a way to load images over the network, so I always imaged from a CDROM drive.

Have you considered Acronis TrueImage? With a bootable CD, you can access an SMB/Windows file share, and load images from there. A similar boot process (with a larger image for memdisk.i) might work.

I suspect you'll get better performance out of a locally-attached drive, though.
posted by lalas at 1:19 PM on January 6, 2009


I think you can probably do this with FOG, but it'll take a little elbow grease. I can't say for sure though, I only looked into it briefly before when setting up my PXE infrastructure. I actually ended up just going with WDS since it was faster to set up and we were deploying XP images anyway, but if you don't have a spare Server 2003 machine I think FOG will do.
posted by tracert at 1:33 PM on January 6, 2009


If the devices run Windows, FOG is a solution. If the devices run linux, you could try Clonezilla. In my experience the Clonezilla setup process is rather opaque. I prefer to set up the services and write a few scripts myself so that I know what's going on. I list some of the alternatives for different parts of the process here.

I've been meaning to write up one possible step-by-step configuration to complement that presentation. I might as well do it now. In the example I'm pretending

A) You want to use /var/lib/tftpboot as your tftp root directory
B) You want to store system images in /srv/images
C) The clients have a 512MB swap partition /dev/sda1 and the rest of the disk is an ext3 root partition
D) The clients use GRUB to boot
E) Your PXE server has an ip address of 192.168.1.1 on eth0
F) eth0 connects to the same network that your clients do
G) There is no DHCP server already on this network. If there is already a DHCP server, replace step 1a with setting up the tftp-hpa server and reconfiguring your existing DHCP server.

1) Set up a PXE server.

a) Install dnsmasq. In /etc/dnsmasq.conf configure it to provide dhcp and tftp via


interface=eth0
dhcp-range=192.168.1.2,192.168.1.254,1h
dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/var/lib/tftpboot


b) Download syslinux and extract pxelinux.0 (it's in syslinux-*/core) to /var/lib/tftpboot

2) Set up SystemRescueCD to PXE boot. SystemRescueCD is by far my favorite live cd. I use a customized version where I've stripped out all the graphical utilities to reduce RAM requirements and have set the imaging script to automatically run.

a) Download the latest iso and extract the files rescuecd, initram.igz, sysrcd.dat, and sysrcd.md5 to /var/lib/tftpboot/sysrcd

b) Place the following in the file /var/lib/tftpboot/pxelinux.cfg/default


default menu.c32
prompt 0

menu title PXE Boot Menu
MENU AUTOBOOT Starting Local System in # seconds

label local
menu label Boot from local disk
menu default
localboot 0
timeout 100

label sysrcd
menu label Boot SystemRescueCD over the network
kernel sysrcd/rescuecd
append initrd=sysrcd/initram.igz setkmap=us vga=5 boottftp=tftp://192.168.1.1/sysrcd/sysrcd.dat


3) Set up an NFS server to store your images

a) Install the nfs kernel module and services if they aren't already. This procedure varies depending on your distribution so I won't try to describe it.

b) Export your image directory by adding to /etc/fstab


/srv/images 192.168.1.*(rw,no_root_squash)


4) Use partimage to create an image

a) Use your new PXE setup to boot SystemRescueCD
b) Mount your nfs share somewhere


mount -t nfs 192.168.1.1:/srv/images /mnt/custom


c) Run partimage and follow the prompts to backup /dev/sda2 to your nfs share. I recommend enabling gzip compression

5) Write a script for restoring an image and save it to /srv/images


#!/bin/sh

function error_exit {
# Display error message and exit
echo "$1" | tee /root/image.log
exit 1
}

function show_status {
# Display next operation and pause
echo "$1..."
sleep 3
}

IMAGE=$1

DEVICE="/dev/sda"
SWAPPART="${DEVICE}1"
LINUXPARTNUM="2"
LINUXPART="${DEVICE}${LINUXPARTNUM}"
MOUNTPOINT="/mnt/local"

if [ $# -ne 1 ]
then
error_exit "Must specify path to image"
fi

show_status "WARNING: About to overwrite all data on the first hard disk"

show_status "Disabling swap"
swapoff -a || error_exit "$LINENO: Couldn't deactivate swap"

show_status "Erasing partition table"
parted -s $DEVICE mklabel msdos || error_exit "$LINENO: Couldn't create new partition table"

show_status "Creating and enabling swap"
parted -s $DEVICE mkpart primary linux-swap 0GB 0.5GB || error_exit "$LINENO: Couldn't create partiton for swap"
sleep 1
mkswap -L swap $SWAPPART || error_exit "$LINENO: Couldn't make swap"
sleep 1
swapon /dev/sda1 || error_exit "$LINENO: Couldn't activate swap"

show_status "Creating linux partition"
parted -s $DEVICE mkpart primary ext2 0.5GB 100% || error_exit "$LINENO: Couldn't create partiton for linux"
parted -s $DEVICE set $LINUXPARTNUM boot on || error_exit "$LINENO: COuldn't amke linux partiton bootable"

show_status "Restoring linux from system image"
partimage -b restore $LINUXPART $IMAGE || error_exit "$LINENO: Image failed"

show_status "Verifying then expanding linux filesystem"
e2fsck -f -p $LINUXPART || echo "$LINENO: Error $? encountered while checking linux filesystem, continuing anyway"
resize2fs -p $LINUXPART || error_exit "$LINENO: Couldn't expand linux filesystem"

show_status "Installing bootloader"
mount $LINUXPART "$MOUNTPOINT" || error_exit "$LINENO: Couldn't mount linux filesystem"
grub-install "--root-directory=$MOUNTPOINT" $DEVICE || error_exit "$LINENO: Couldn't install grub"

show_status "Finished! Shutting down."
halt


6) Use the script to restore an image

a) Use your new PXE setup to boot SystemRescueCD
b) Mount your nfs share somewhere


mount -t nfs 192.168.1.1:/srv/images /mnt/custom


c) Run the script with the path to the image file as the argument

Hopefully the above makes sense and there aren't too many typos. You may run into trouble if your clients use UUIDs or labels in their /etc/fstab to keep track of partitions. The UUID of the root filesystem will stay the same when it's reimaged but swap will change since it's recreated.
posted by PueExMachina at 4:26 PM on January 6, 2009 [1 favorite]


Response by poster: (boggle)
(seizure)

Looks like it's a bit more complicated in Linux. I might have to borrow some elbows, with as much grease as this is going to require.

Keep'em coming!
posted by Industrial PhD at 4:32 PM on January 6, 2009


Response by poster: I should also clarify:

The majority of the devices that will be imaged are going to be mandrake-based Linux. There would be a few instances of XP/Vista machines, but it'll more often than not be Linux. I'd also like the image server itself be linux, and I noticed FOG is a windows-based app, which I guess would work if I had to, but that doesn't support Linux clients, according to their website.
posted by Industrial PhD at 4:35 PM on January 6, 2009


FOG is actually a Linux app, but you're right, it's only for deploying Windows, so it won't be good for Mandrake. I probably should have mentioned that before, I'm sorry. Looks like Clonezilla is a good bet though! If all else fails you can also use WDS for linux too, but it's messy and gross.
posted by tracert at 5:33 PM on January 6, 2009


If you follow PueExMachina's advice, just be a little wary of dnsmasq. I've had problems with it offering DHCP services to bare-bones clients (which I mentioned in a vaguely similar context here).

Never had a problem using the reference ISC DHCP server, though it's slightly less easy to configure with or without a standalone tfpt server.
posted by Pinback at 5:43 PM on January 6, 2009


@Pinback: That's interesting, thanks for bringing it up.

@Industrial PhD: If you don't want to set up a permanent PXE server (i.e. steps 1-3), you can just burn SystemRescueCD to a CD, boot it, configure your network, and run /etc/init.d/pxebootsrv start. Details here.
posted by PueExMachina at 11:01 PM on January 6, 2009


According to the user guide, FOG can image linux systems under certain conditions:

Single Disk will back up all the supported partitions on the first disk drive detected by FOG, but the partitions are NOT resizable by FOG. This means that the image must be restored to a disk of the same or larger capacity. It is possible to backup NTFS drives with vendor specific 'restore' partitions with this type of image.

It is possible to backup Linux systems with this type of image given the following criteria:

* There is a Grub boot loader present.
* LVM is not used.
* The partitions include ext2, ext3, reiserfs, or swap.

Linux support is still pretty primitive, and has only been tested with a default Ubuntu 8.04 Installation.

posted by PueExMachina at 11:11 PM on January 6, 2009


Another vote for Clonezilla being exactly what you want (and another vote saying it's not the most fun thing to setup).
posted by mysterious1der at 11:20 AM on January 7, 2009


« Older Subway to Boston from where?   |   Is HDMI hook up necessary for awesome High Def TV? Newer »
This thread is closed to new comments.