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.
THANK YOU THANK YOU THANK YOU.
Finally, someone intelligent and experienced trying to use Ubuntu on a thumb drive like me (NOT live).
I’ve been looking for an explanation like this for some time. Thanks.
Now I suppose I should become more acquainted with all of the data stored in that home directory, so that I know when I’m about to make a change there that I want to keep….
Comment by Jeff — May 19, 2010 @ 11:58 am
Thank you for posting this solution. It works like a charm!
I did, however, make some changes when I noticed that rsync doesn’t sync two-ways and I do not want my home directory to grow.
First I bought a 16 GB SD card and mounted it as /home2.
Then I followed your instructions.
I use rsync to copy /home to the ramdisk at boot. Just as you wrote. But instead of rsync /home to /home2, I use unison (http://www.cis.upenn.edu/~bcpierce/unison/) to synchronize my home dir.
In /etc/gdm/PostSession/Default i put:
/usr/bin/unison default.prf
/bin/chmod 666 /davor/unison/unison.log
The content of the configuration file .unison/default.prf:
# Unison preferences file
root = /home/davor
root = /home2/davor
auto = true
owner = true
batch = true
logfile = /davor/unison/unison.log
Files that I do not want to be synchronized I put in /davor.
Using unison instead of rsync to sync from /home to /home2 makes it unnecessary to open a virtual terminal and rsync. Just log out, and log in again.
I also followed these guides:
http://forums.overclockers.co.uk/showthread.php?p=13612981
http://forums.gentoo.org/viewtopic-t-717117.html
As soon as I have finished redecorating my home I will check out how to sync my home directory to my home server over ssh (and dyn-dns)
Again, thank you.
Davor
Comment by Davor Vusir — November 14, 2010 @ 11:31 am