Slightly less Random Ramblings

April 22, 2010

Ubuntu thumb drive

Filed under: linux — Tags: , , , , , — Robert Wicks @ 9:44 pm

I recently installed Ubuntu 10.04 beta 2 (Lucid Lynx) on an Imation 4GB thumb drive. Ubuntu has a feature to install the live CD onto a thumb drive, but I have always found that solution a bit unsatisfying. I wanted an installation which could be updated and modified as I see fit. So, I wanted to use the thumb drive like a hard drive. Most of what I do allows me to forgo persistent local storage, but I did want that option, so I encrypted my home directory, which is an install option. One of the potential problems with that plan is the fact that flash storage, especially cheap flash storage, like the kind in a thumb drive, has a limited number of writes before it fails.

installing Ubuntu onto a thumb drive, using it like a hard drive, is simple. Just run the normal install, clicking on the “Advanced” tab on the screen prior to the beginning of the actual install. The subsequent screen allows you to choose the location for the boot sector. Simply change the boot sector to the thumb device, and you are done there. For further details, go here.

After the install, you can update your Ubuntu install as normal. Now, the next step is to do things which will extend the life of your thumb drive. Obviously, you do not want to have a swap file. I formatted the swap partition which Ubuntu automatically created and mounted that partition as /home. I also made use of tmpfs to mount some of the more heavily written areas in RAM, discarding them on each reboot. Here is what I did in /etc/fstab:

tmpfs /var/tmp tmpfs noatime,rw,mode=1777 0 0
tmpfs /tmp tmpfs noatime,rw,mode=1777 0 0
tmpfs /var/cache/apt tmpfs noatime,rw 0 0
tmpfs /var/log tmpfs noatime,rw 0 0

Additionally, I added this to /etc/rc.local:

mkdir -p /var/cache/apt/archives/partial
mkdir /var/log/apt

This means that the heavily written stuff, like logs, and the update cache for software, are written to RAM and discarded. The /etc/rc.local line is needed because apt-get requires both the archives and archives/partial directories to function correctly.

Once I had the system up and running, I found Firefox performance to be bad. Using the ever-trusty lsof, I found that Firefox uses multiple sqlite databases to hold stuff like preferences. The solution I decided on was to move my home directory onto a ramdisk. Since I had a small /home partition, I added the following things to my /etc/fstab:

UUID=f39t7wj8-v872-4dc9-ik47-nve73hv923nbsw1 /home2           ext4    rw,noatime        0       2
tmpfs /home tmpfs noatime,rw 0 0

Your uuid will differ, but the idea is to mount your original /home partition on /home2 instead, and mount /home as a ramdisk. I also added the following to /etc/rc.local:

rsync -a /home2/ /home/

This syncs the contents of /home2 (which is on the flash) with /home (which is in ram, and discarded at every boot). If I make an important change to my home directory, I log out of my GUI session, open another virtual terminal (by pressing ctrl-alt-F1), log in as root (you will need to set your root password to allow this), and run:

rsync -a /home/ /home2/

This will sync the changes you made back to the flash card. You should only rarely have to do this. One useful way to save files is to use the free Ubuntu One service which is included with Lucid. That makes it easy to save small files and sync them to the cloud, which ends the worry associated with having your home directory in RAM. Save any files you want to the Ubuntu One directory, and they will be saved offsite.

If you have any issues with doing any of this, feel free to contact me at robwicks@gmail.com. Also, I would greatly appreciate corrections and suggestions. I may experiment with AUFS in the future. That may be a good alternative to tmpfs alone on some of the filesystems.

Advertisements

Create a free website or blog at WordPress.com.

%d bloggers like this: