Wednesday, February 18, 2009

A Stick of Mint

One of the neat things about Linux is that you can install an entire operating system on a little USB stick. This allows you to run your personal operating system from just about any computer at any location. As you can imagine, there are many reasons for doing this. I'll explain mine below.

I have access to a laptop with an encrypted hard drive with Windows installed on it. I won't get in to the reasons why, but I should not be installing any programs on it. Use your imagination. If I can't install programs on Windows, I could normally resize the Windows partition and install Linux on the cleared space. However, I can't just resize the partition because the hard drive is encrypted. The one good thing is that the bios is not password protected, so I am free to change the boot order. This allows me to boot the laptop from things other than hard drives, such as CDs or USB drives.

I put an 8GB thumb drive on my Christmas list, and my brother-in-law was kind enough to get me one. Let the experimentation begin!

You can do this with as little as 1GB, but that only leaves you with about 200 MB of extra data storage. 4GB should give you plenty of wiggle room for installing updates, configuration changes, and adding several extra programs. With 8GB, I have plenty of extra room for things like music and videos.

I tried this twice, and I'll explain why later. The first method is simpler but limits your storage space to about 4GB. The second method unlocks all the available space on your USB drive.

Ubuntu has a program called usb-creator, and I used it for both methods. It is installed by default on Ubuntu 8.10, but it also works on Ubuntu 8.04 if you download it. To use it, look for the option to create a USB startup disk under the Administration menu. You might be doing this from a Live CD, which is just fine. I heard that you can even run usb-creator from Windows, so you are free to do this from your Linux or Windows desktop if you wish.

In order to boot from a live CD or a USB drive, you may need to change the boot order in your bios. This method can vary depending on your motherboard, so I won't get into that here.

The First Method:

For my first go, I formatted my entire USB drive with a FAT32 partition before using usb-creator. To do this, you can use the program, GParted, which can be found in the administration menu as "Format Hard Disk." You will need at least one FAT32 partition because the USB drive will be running Linux similar to the way your Live CD does. Don't worry, the program will enable a way to save your files and changes as I mentioned earlier.

When you run usb-creator, the program will ask you to select a .iso file to use for the installation. This can be the same .iso file you used to create your live CD. I used a second thumb drive to hold this .iso file while the program running off the live CD installed to my new thumb drive. I suppose you could copy the .iso file to the home folder of the live CD, which means it would be stored in RAM and erased when you rebooted. That's fine because you only need it once, and it allows you to get away with using only one thumb drive for the entire process.

I used a .iso file for the Ubuntu 8.10 64-bit Desktop version the first time. This worked right "out of the box" with only one small issue that I will discuss later.

One of the other options the program gives you is the ability to enable persistency. This allows your changes to the operating system to be saved, making it much nicer than just running from the Live CD. This option presents you with a slider, allowing you to designate an amount of "persistent space" on your thumb drive. This space can be as small as 128MB or as large as 4GB. Here's what's really happening behind the scenes:

The usb-creator program will copy the Live CD files from the .iso image to your thumb drive just like it does for CDs, and mark the FAT32 partition as bootable. This takes up about 700MB of the parition's space. Then, the program will create what is called a persistency file. This file is named "casper-rw" and is stored on the root of your FAT32 partition right along with the Live CD files. This persistency file is used by your Linux installation to store all the changes you make to the operating system. All your configuration changes, software updates, and added data files such as music or office documents are magically stored inside this persistency file. Think of it as a big, complex .zip file. The FAT32 file system cannot handle files that are larger than 4GB, no matter what operating system you are using. You cannot create a persistency file larger than 4GB, and as a result, you cannot store more than 4GB of extra data in it. There is a way around this, and I used it for my second method which I will discuss later.

Anyway, once you tell the program how large you want the persistency file to be, it's ready for you to click, "Make Startup Disk." Writing to flash isn't exactly speedy, so this may take a few minutes. Once it's finished, shut down operating system, remove the CD when it tells you to, and boot up again with the USB stick in the computer of your choice.

When I did this the first time, I had an almost fully functional Ubuntu operating system. It takes a while to boot up because flash drives are slower than hard drives. However, once the operating system is up and running, most things seem to run quite smoothly. The one thing that did not work right away was the wireless card. All I had to do was connect the laptop to my wired network, go to Hardware Management in the Administration menu, and select the wireless driver I wanted to enable. It downloaded the driver and turned it on after I rebooted. This is a Dell Latitude D630.

I noticed that whenever I would boot off the thumb drive, it would come up with a menu similar to the one you see on the Live CD. If you just select the default or let it timeout to the default for you, it will continue to boot to your persistent Ubuntu installation. I also noticed that Ubuntu did not require any login credentials by default, just like the Live CD. You can enable this if you want, and I did the first time, but I won't get into that right now.

One of the most fun things about having Linux on the laptop was that I was able to install Adobe Flash and watch TV shows on Hulu.com via my 32" LCD TV. I didn't have to worry about hauling a larger, noisier desktop machine over by the TV and running network cables to the family room. There were two drawbacks to this, however. First, the only sound output on the laptop is meant for microphones. In order to hear the shows we had to turn the volume all the way up on the TV and computer. I am sure a desktop or other laptop with standard sound output would not have this problem. Second, the laptop doesn't like displaying at full resolution on my TV, so the picture is smaller than it could be if the show is in widescreen. I also think that a desktop would fix this issue, because the operating system won't have to worry about the laptop's built-in display. I may still figure out how to get this to work.

Anyway, I did have one small problem when I tried installing updates from Synaptic Package Manager. I selected "Mark All Upgrades" and let it do its thing, as usual. However, when it was done, it gave me an error about a broken symbolic link. This error would pop up every time I did an update in the future. After a bit of research, I found out that it was because of an issue downloading Linux kernel updates onto Live CD types of installations. Remember, the usb-creator method of making a bootable thumb drive treats your installation much like a Live CD. The update that caused the bug wasn't really necessary, and the bug itself seemed to be harmless. I also discovered a way to fix it, but I won't go into that here.

Remember that my persistency file was only about 4GB in size. The core Linux installation was about 700MB. This left me with around 3.5GB of wasted space. I used GParted to turn that extra space into a separate FAT32 partition so I could store other files on it and access them while Linux was running. However, in the end I decided I really wanted to have all of my storage space on a single partition so I could install as many programs as I wanted in the future. This brings me to...

The Second Method:

I also had recently done some research on another popular Linux distribution called Linux Mint. According to DistroWatch.com, it is the third most popular Linux distro after Ubuntu and openSUSE. Linux Mint is based off of Ubuntu similar to the way Ubuntu is based off of Debian. However, they seem to focus on a much more user friendly experience (though I would definitely not complain about Ubuntu being unfriendly) and a better "out of the box" experience. The primary version of the operating system comes with media codecs and other free proprietary software (such as Adobe Flash) preinstalled. It also comes with some applications called Mint Tools, which have been added to make life a little easier. The graphical interface is also attractive, and more familiar to people who are used to Windows.

Since changing how persistent data was stored on my thumb drive would require me to basically start over from the beginning anyway, I decided to use Linux Mint 6 64-bit for my .iso this time. But why did I need to start over?

I found out that instead of using the casper-rw persistence file, it is also possible to simply create a separate partition with the label "casper-rw" and it will store all of the persistent data. You just need to delete the casper-rw file so Linux knows to use the partition instead.

The recommended file system for this partition is ext2. Why not ext3? Well, ext3 does a lot of extra writing to the drive for things like indexing, which isn't necessary and will actually wear out your flash drive faster. (Flash drives are supposed to have a more limited lifespan than hard drives, so keep this in mind if you ever use them for important data.) Also, it is my understanding that some of the features of ext3 aren't even enabled when running like a Live CD, so much of the benefit of ext3 is wasted anyway. So, I used GParted to make a 900MB FAT32 partition for the Live CD portion of the operating system combined with a temporary minimal casper-rw file, and used the rest of the space for ext2.

After the partitions were set up, I went to usb-creator and had it make my Linux Mint bootable drive with a minimum persistence file of 128MB. After that was finished, I deleted the casper-rw file from the FAT32 partition. In order to make use of that extra space, I went back to GParted and resized the FAT partition to 700MB and added the extra to my ext2 partition. Then, I had to label the ext2 partition as "casper-rw" by using the following command in the terminal:

e2label /dev/ casper-rw

The exact location of the ext2 partition should be listed in GParted, so be sure to use that in the command.

I rebooted, took out the CD, booted from the thumb drive, and had Linux Mint running. There was just one problem: no persistence. Of course, it was the first thing I tested. I did some research and learned a little about the Live CD menu that pops up before you actually boot into Linux. On the Live CD, and on the thumb drive, there is a file that tells the menu what options to display and how to behave. This file is /syslinux/syslinux.cfg. This file needs to tell Linux to boot into persistent mode, not just normal Live mode. I am assuming that for whatever reason, usb-creator was able to properly modify this file for Ubuntu but not for Mint, so I had to do it myself. Here's how:

Above the line that says "label live" you need to insert the lines:

label custom
menu label Start Linux Mint in ^persistent mode
kernel /casper/vmlinuz
append file=/cdrom/preseed/mint.seed boot=casper persistent initrd=/casper/initrd.gz quiet splash --

You'll notice that the only difference between the custom section and the live section is the word "persistent." After you insert those lines, you need to go to the top line and change it to say:

default custom

I guess this tells the menu to use the information in the "custom" label as the default option. For the heck of it, I also changed the "timeout 100" line to say:

timeout 50

After doing this, two things happened. First, I noticed that I no longer got the boot menu at all! The thumb drive just went straight into Linux Mint. I'm not sure why this happened, but I might have messed up the syntax in the config file. After all, this was all new to me. I actually thought this was a good thing, however, because I really don't need that menu anyway. The other thing that happened: persistent mode was now working. I guess I killed two birds with one stone.

After I installed the wireless driver exactly as before, everything worked perfectly. I didn't have to install Adobe Flash because it was already installed, and Hulu worked the same as before. I also heard that DVDs play just fine right out of the box.

Instead of using Synaptic Package Manager for my updates, I used mintUpdate, which was located in the lower right corner of the tray. One of the neat things about mintUpdate is that it ranks each update on a scale of 1 to 5. If something is very important and/or very safe to install, it gets a 1. If something is unnecessary and/or unstable, it gets a 5. I've heard that these ranks can change based on user feedback, so even if a package gets through initial testing but causes problems later, it can be moved down the list. By default, mintUpdate only displays and installs updates with a rank of 1 to 3. I changed it to display all five ranks, but only install 1 to 3. Guess what package showed up in the list of unsafe updates? The kernel update that gave me that error under Ubuntu. One of Linux Mint's tools just prevented me from getting an unnecessary error that Ubuntu would have given me (and did). I am a happy camper.

Linux Mint looks like the best option for Windows users that want to get away from Windows. I'm already talking it up to my friends. It's free, easy to use, and has a nice graphical interface that feels a bit more like what we're used to under Windows. (As with most Linux distros, you customize the GUI to look very different if you wish.) It comes with a complete office suite and e-mail client among other useful software, and it's completely free. Check it out at http://www.linuxmint.com/.