On our small remote sites we use HP thin clients to connect to applications using Citrix. The thin clients are Linux based, with 1Gb of flash memory for storage and running an HP customised version of Debian. The distro is basically a cut down Gnome desktop with Iceweasel (Firefox), and some HP branding and tools for backing up and restoring the client and for connecting to HP printers.
We've recently had some downtime with ADSL connections in these sites and wanted a contingency for network problems. We came up with the idea of 3G USB dongles and had bought a Vodafone one, but after testing it, the conclusion was this would not work without a lot of hacking about with the packages available in the HP Distro. However, after some testing in Ubuntu we found it worked perfectly with the most recent version of Network Manager. With Network Manager you can basically just insert the key and after a minute right-click the tray icon, select 'Vodefone 3G' and you're off (yes, incredibly it really is that good). So ... the challenge was to reconfigure our thin clients, so that:
- It used Ubuntu and Network Manager
- It could be easily deployed by a user from booting a USB stick
- Had a system to allow IT to make changes to the image and re-image the USB stick
- The USB sticks should be easily cloned to distribute to all remote offices.
I can't resist a good challenge, expecially when it involves tinkering with Linux.
1. Installing a lean and mean Ubuntu machine
This step was a challenge in in itself - Ubuntu Jaunty would not boot into a live session on this computer, (kernel modules were failing to load right at the start) and doing a basic text based install (with no GUI elements) pretty much filled the entire drive, give or take a few Mb!
I had partitioned the disk with no swap partition, 100Mb for home and 70Mb for boot. I set off by removing unwanted locales from the system using 'locale purge':
sudo apt-get install localepurge
sudo apt-get clean
I decided I would go for XFCE for the Window manager, since it was impossible to install a Gnome desktop without hundreds of megs of bloat. All I really need is a desktop with a web browser so installing a Gnome desktop seems like overkill.
sudo apt-get install xfce4
This automatically pulls in all of the dependancies, like the X-Window system. Next to start reclaiming used disk space. To find out which directories were using the most space I used du:
sudo du / -h --max-depth=1 | grep M
The main culprets were /usr/share and /lib. Deleting items from /lib is not advisable, removing the dependant packages and then using an 'apt-get autoremove' will tidy them up the clean way. I prefer to use Synaptic to do this rather than apt-get, some things are just better and faster using a GUI.
sudo apt-get install synaptic
xfce4-session
From within XFCE, I launched Synaptic and removed everything that was unnecessary. Afterwards went back into /usr/share and used du to locate the large DIR's again. I removed gimp files and unnecessary locales:
cd /usr/share
sudo rm -rf gimp
sudo mv locale/en .
sudo mv locale/en_GB .
sudo rm -rf locale/*
sudo mv en locale
sudo mv en_GB locale
Removed unnecessary docs, myspell and redundant openoffice.org components. Have no idea why these were even installed in the first place since the openoffice suite was not installed ... totally unnecessary bloat!
sudo apt-get remove myspell-en myspell-en-gb
sudo rm /var/lib/dpkg/info/openoffice* -f
sudo dpkg -r --force-remove-reinstreq openoffice.org-hyphenation-en-us
sudo dpkg --purge openoffice.org-hypnenation-en-us
sudo tar fzvc /home/docs.tgz doc --remove-files
I deleted /home/docs.tgz after a reboot, since nothing stopped working.
Next got rid of unwanted XFCE themes:
cd /usr/share/themes
sudo mkdir ../themes_OLD
sudo mv * ../themes_OLD/
sudo mv themes_OLD/Def* .
sudo mv themes_OLD/Xfce* .
sudo rm -rf themes_OLD
Installed Firefox, usplash (pretty startup screen) and the all-important Network Manager:
sudo apt-get install firefox usplash network-manager
To get the Network Manager tray icon in XFCE, you just have to configure 'nm-applet' to start when XFCE is started. Tested Network Manager using the Vodafone 3G dongle and success, it worked first time! Citrix sessions actually run quite well over 3G too.
Once last package cleanup, for good measure:
sudo apt-get remove synaptic
sudo apt-get autoremove
sudo apt-get clean
This left me around 30Mb free on /, which is pretty much what I had started with on the HP/Debian distro.
Last few bits were configuring the user to auto login, installing printers using CUPS, installing the Citrix client (this goes into the users /home directory), setting desktop background, and a few other customisations, like configuring Firefox to automatically purge data when closed ... that 100Mb home partition would fill up pretty quickly otherwise.
The autologon to XFCE without a login manager was a bit tricky since Ubuntu uses Upstart to manage the startup sequence rather than the traditional Linux sysinit, since this is a bit unfamiliar to me I had to follow some guides on the Ubuntu forums to get it working. The community support is excellent though, which is one other reason we chose it in the move away from the HP thin client distro. There always seems to be someone before you who has already had the same problem!
2. User friendly imaging from a bootable USB stick
My weapon of choice for this initially was the Linux tool 'dd', which does block level duplication of partitions or sections of a disk quite easily. For example to clone the second partition on disk 'hda' to a file, you could use:
dd if=/dev/hda2 of=/myimages/thin_client_hda2.img
dd can also be piped into tar or zip to compress the output. One drawback is dd does also duplicate white space into the output file, so it's not the most efficient tool for the job. My tests with dd were not very successful, creating the image was fine, but writing the image back to disk always failed complaining it had run out of disk space.
I dumped dd and started looking into CloneZilla. It's an open source partition and disk imaging tool that boots from CD or USB and can dump a disk image locally, or to an NFS or Samba share. It is comparible to norton ghost in features but not quite as friendly in the GUI department, since the menus are all text based and keyboard controlled. Clonezilla can dump an image to usb attached or to windows or NFS shares and can even be set up as a PXE server to multicast images across a network and image multiple machines at once, but it's most common form is imaging a single machine in live mode. To dump a disk image locally I has to split my usb stick into 2 partitions : 500Mb for Clonezilla (formatted in fat32) and 1.5Gb for the partition images (formatted in ext3). This was necessary as you can't write images to the filesystem clonezilla has booted from.
I used unetbootin (awesome utility) to write the Clonezilla iso to the usb stick and make it bootable. You may notice unetbootin already contains a Clonezilla option, I did try using this but the stick that was created was somehow missing important files from /etc/ocs, so I'd advise downloading the latest iso from clonezilla first, and then just using unetbootin wo write the iso file.

Unetbootin
Next boot from the stick but instead of going into an interactive session, choose the command line mode. Grant yourself root access by using:
sudo su -
Edit the syslinux.cfg file to customise the boot menu.
vi /live/image/syslinux.cfg
If you've ever created a Linux PXE server you'll recognise the layout of this file. By editing this and passing different options to the kernel at boot, you can launch custom clonezilla scripts without user interaction. My syslinux.cfg looked like this ... the top menu item becomes the default, so this configuration will automatically restore the thin client from the usb stick if there is no interaction for 10 seconds - perfect for sending to users on remote sites.
default vesamenu.c32
prompt 0
menu title UNetbootin
timeout 100
label restore
menu label Restore image from USB stick
kernel /ubnkern
append initrd=ubninit boot=live union=aufs vga=788 ip=frommedia ocs_live_run="/live/image/pkg/custom-ocs-restore" ocs_live_extra_param="" ocs_live_keymap="NONE" ocs_live_batch="yes" ocs_lang="en_us.UTF8"
label backup
menu label Backup image to USB stick
kernel /ubnkern
append initrd=ubninit boot=live union=aufs vga=788 ip=frommedia ocs_live_run="/live/image/pkg/custom-ocs-backup" ocs_live_extra_param="" ocs_live_keymap="NONE" ocs_live_batch="yes" ocs_lang="en_us.UTF8"
label unetbootindefault
menu label CloneZilla Live Session
kernel /ubnkern
append initrd=/ubninit boot=live union=aufs nolocales ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=791 ip=frommedia
The ocs_live_run parameter in each stanza points to the custom script you want to run. These scripts have to exist in /live/image/pkg and be marked as executable. They can be called anything you like. Some examples already exist on the live cd, can't remember the exact location but I found them using:
find / -name "custom-ocs*"
My backup and restore scripts looked like this:
/live/image/pkg/custom-ocs-backup
#!/bin/bash
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/opt/drbl/}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. $DRBL_SCRIPT_PATH/conf/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions
if [ -e /etc/ocs/ocs-live.conf ]; then . /etc/ocs/ocs-live.conf; fi
ask_and_load_lang_set en_US.UTF-8
mkdir -p /home/partimag
mount /dev/sda2 /home/partimag
/opt/drbl/sbin/ocs-sr -q2 -c -j2 -z1 -i 2000 -p true savedisk "maverick-img" "hda"
/live/image/pkg/custom-ocs-restore
#!/bin/bash
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/opt/drbl/}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. $DRBL_SCRIPT_PATH/conf/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions
if [ -e /etc/ocs/ocs-live.conf ]; then . /etc/ocs/ocs-live.conf; fi
ask_and_load_lang_set en_US.UTF-8
mkdir -p /home/partimag
mount /dev/sda2 /home/partimag
/opt/drbl/sbin/ocs-sr -g auto -c -p true restoredisk "maverick-img" "hda"
I got stuck in a few places, the project maintainer (Steven Shiau) helped me out on the clonezilla forums (thanks Steven).
3. Cloning the USB stick
Gah ... well I've got this working using dd ... but I need a Windows tool that can do this since the IT Service Desk are all on Windows machines! Provided the partitions on the USB stick are the correct size, one can use:
dd if=/dev/sda1 of=/dev/sdb1 conv=notrunc
dd if=/dev/sda2 of=/dev/sdb2 conv=notrunc
What Windows tool can I use to do this ... don't really have the time to spend but I am thinking a 3rd option in the Clonezilla boot menu for duplicating the stick. Perhaps a 2nd part in the future to this already too long blog post!