Debian on a Stick: Portable Linux
Install Debian Etch GNU/Linux on a USB flash drive, thumb drive, stick, pendrive, key, or whatchamacallit.
How to Install Debian Etch on a Stick
As stated in the last article, this isn’t about a live-CD-on-a-stick-install, it’s a regular, uncompressed install, as one would do on a hard drive, but slimmed down to fit on a 2-gig stick, with about 750 megs left over.
Disclaimer: The installation instructions described in these articles are to be considered experimental. They may or may not work for you, nor turn out as described or expected. The author bears no liability for your actions or any direct or indirect consequences thereof. If you are not experienced in partitioning drives and installing operating systems, you should not do so.
1st, go to here, select the arch (i386 or amd64), then select iso-cd/, then locate and download the netinst ISO, which will be about 150 megs. If one wants a later kernel version, try the etchnhalf netinst version, but see this first for some caveats.
Update: I have made the Etchnhalf on a Stick article about installing Debian Etchnhalf Netinst to a 2-gig stick. That one has more detailed instructions, and is the logged adventure of my second Debian stick installation.
Update: I now also have an article about installing the latest daily build of Lenny on a Stick. That article has a much better package list.
Laser the ISO to an optical disk and boot it. At the Boot: prompt, select expert. You don’t have to be an expert, it just means you’ll have full control and the installer won’t make any assumptions. It’ll route you through a long list of menu items, and if you don’t know how to answer, don’t guess—back out and boot your regular system, get online, and do some research.
Update: In the next article, I used the default install (not expert) option, and it worked fine.
How long to expect? Going leisurely through the installer menu (expert mode) took me about 45 minutes. Letting it install the base system took over three hours. USB sticks write slowly, and the installer does a lot of writing. One can’t just go away and ignore it, because occasionally a package will stop and ask a question. So, do something else, but keep an eye on it.
Go through the installer, slowly and thoughtfully, deselecting all the modules you know you don’t need, and then selecting your stick (be careful) as the drive to partition. Select the “all in one” automatic partition. It’ll make an ext3 and a small swap. Write down the drive designator it’s using (probably sdb or hdb), because you’ll need that after a while to tell it where to install Grub (the GRand Unified Bootloader). Near the end of the install, it’ll recommend installing Grub to the hard drive, but since this is a stick and we want it portable, make it install Grub to the stick. Be careful! Don’t blame anyone if you wipe out a hard drive, or your hard-drive’s Grub. Remember, if you already have a Grub on the hard drive, you’ll add a stanza for booting the stick later, but for now (this installation) you want the stick to (also) have it’s own Grub, so you can bios-boot it on systems without a Grub.
Don’t try to make the partitioner use one partition and no swap. It won’t work. I consider this an annoyance in the installer: Don’t we all now have at least 1.5 gigs of ram? So why do we need a swap partition? We don’t, and installers that force allocation of at lest 150 megs of swap are just wasting space on the stick. I tried the manual partition option without a swap, and the installer insisted on wanting to format swaps on two other drives! On the other hand, on older hardware with say, 128 megs of ram, yes, you need the swap.
Reboot, catch the BIOS setup, change the first drive to USB-HDD, save and reboot. The stick should boot Grub, and Grub should boot the new Debian. Well, now that it’s booting from the stick, it isn’t the same designation as it was during the install, so we have to drop to the Grub command line and use tab-completion to locate what Grub now thinks is the stick. (Details: During the install, grub saw your stick as hdb or c, but now it sees it as hda, since we booted it from BIOS.) Once located, don’t be surprised if it just sits there for 2-3 minutes. Remember that most BIOSes will load the two boot files (kernel and initrd) at low speed.
First Things First
Log in. Since we didn't select a desktop during install, we’ll work at the console screen(s) for now, and install packages selectively.
Set the root password, then add a new regular user (yourself).
Fix Up the package sources: What we’re offered depends on what package sources apt looks at. Edit the /etc/apt/sources.list file and put:
deb http://ftp.debian.org/debian etch main contrib non-free deb-src http://ftp.debian.org/debian etch main contrib non-free
Comment-out (with #) the cdrom line. Leave the security lines as-is. Save the file. Run apt-get update to make it database the new sources.
Next, do an apt-get install mc gpm lynx localepurge so you have a file browser, mouse, web browser, and an automatic globalization scrubber.
mc (Midnight Commander) is a Commander-style dual-pane file manager that allows us to easily get around the filesystem and view and edit various files.
gpm is a console mouse driver, useful in mc, as well as being able to middle-button paste command lines from lynx and various docs to command lines—saves a lot of typing. (Detail: In Linux you can (1) select some text, then (2) move elsewhere, then (3) press the middle mouse button and it’ll pop it right in there.)
Lynx is a text-mode web browser. We might need that to do some online research while setting up the rest of the system.
Localepurge (note the ‘e’ in there) automatically runs after any package operation to make sure that locales (language settings) we don’t need are purged. Ultimately frees hundreds of megs.
Start mc and look over the new filesystem. Switch to the next terminal (Alt-F2) and log in, then start lynx and get online. Switch to another terminal (Alt-F3) and log in. Use the first for mc, the second for lynx, and the third to run commands (or as desired). (Detail: In Linux text consoles, you can run several, and switch between them with Alt-F{whatever}. Very handy.)
Fix Up Your Grubs
Next, edit your /boot/grub/menu.lst file and set the right hd number so you don’t have to edit the Grub commands during every boot. You’ll also have to edit the Grub menu.lst on your hard drive, if you have one there. The root (hd0,0) in the stick’s Grub will be something else, like root (hd2,0) on the hard drive’s Grub (it’s all a matter of Grub’s perspective).
Another Grub fix is employed in recent Grubs and kernels: The ability to specify the boot location as UUID or LABEL. Examples:
kernel vmlinuz boot=/dev/sdb1 <--this varies as you move the stick (or other stuff) around.
kernel vmlinuz boot=LABEL=Debbie <--this doesn’t vary! Sweet.
Look in /dev/disk/by-label/ (or /by-uuid/) directories to determine what’s what. The UUID is a long number that’s assigned when the partition was created. The LABEL is explicitly set (by you) either when you format the stick, or later with e2label (i.e., e2label /dev/sdc1 MyStickLabel).
Growing the Graphical Desktop
Now the questions are, "What do I have, and what do I need?"
dpkg -l | less will show what you have (exit less with q).
df will show how much of the drive is used and free.
apt-get install {something(s)} will calculate how much space the install will require, so you can reject it or proceed. Some packages are meta-packages, meaning they’ll install a whole bunch of stuff. One can search and locate the component packages and not the whole meta package, if desired, to save space and excess clutter. In fact, on a 2-gig stick, one must.
From here, it’s entirely up to you as to what graphical desktop and window managers (if any) to add, and what applications to add to that. The possibilities are endless, but we do tend to add what we are familiar with. With a 2 gig stick, you’re not limited to a minimal Fluxbox and Dillo—you can add a slimmed Gnome, Evolution, Firefox, Abiword, Synaptic, themes, Brasero, etc., and still have around 700 megs of free space.
Slimming it down
One should not remove any packages from the basic Netinst install. Almost all are needed to boot and run a stable system. For example, you may never use exim4 and mutt (text-based email), but they pull in dependencies that you need to run other things, and besides, the core expects some kind of email agent. I uninstalled "at" (the periodic scheduler) and the system wouldn’t even boot! (it removed some dependency). Keep records.
apt-get clean will delete the package archive cache, several hundred megs. Do it occasionally.
Now df should show around 400-450 megs used. Installing Xorg, parts of Gnome, and a few utilities should add about 600, leaving you about 850 free (the stick is 2 gigs, but the obligatory swap partition takes up about 150). Well, even less than that, because 2 gig sticks are really about 1.85 (they lie by using 1000 instead of 1024).
I tried the gnome meta-package. That’s a big meta-package, 310 packages, that’ll use like 1800 megs or so... Way too much stuff I don’t need! Like inkscape, gdm, gnome office, etc. So it’s one thing at a time, but which ones, and in what order?
Run aptitude, the full-screen package manager. Expand the gnome tree and select desired packages. Keep it under about 700 megs. As you locate and add packages, press g (once!) occasionally to see what will do. If not what you want, deselect some stuff.
Suggested starting list: Either select in aptitude, or apt-get these: (there’s a better list in the next article)
More essential: xorg X.Org X Window System gnome-core GNOME Desktop Environment, essential core synaptic Graphical package manager gnome-commander Dual-pane file manager gnome-control-center Utilities to configure the GNOME desktop hal Hardware Abstraction Layer autofs kernel-based automounter for Linux gnome-vfs-extfs GNOME virtual file-system gnome-volume-manager GNOME daemon to auto-mount and manage media gparted GNOME partition editor gedit Nice tabbed text editor gksu Graphical frontend to su (to run things as root) deborphan Finds orphaned libraries Less Essential: abiword-gnome WYSIWYG word processor sorta like MS-Word brasero Nice & easy CD/DVD burner evince PDF document viewer evolution Email, calendar, organizer sorta like Outlook file-roller Archive manager gcalctool A desktop calculator iceweasel Mozilla Firefox web browser (renamed) iceweasel-gnome-support Support for Gnome in Iceweasel msttcorefonts Installer for MS TrueType core fonts (Arial, etc.) samba-common To connect to Windows shares on your LAN smbclient (ditto) smbfs Mount and umount commands for the smbfs transmission Simple & effective BitTorrent client
Notes:
- I didn’t include a desktop manager (graphical log-in) because (1) it’s not essential, and (2) it’s too big. Without a desktop manager, when you boot it, you’ll just login at the command line then type
startx. When you log out of Gnome, you’ll return to the command line, where you can typehaltorreboot. - Also, not yet installed is support for audio or printing, as these will depend on your particular hardware. The audio support stuff is called alsa (and older is oss), and printing support stuff is called cups and foomatic. Use the Search feature in Synaptic.
- The above list will suck in a bunch of dependencies, mostly lib files, and when done with the above, and after cleaning up, you’ll have about 950 megs on the stick, and 750 free.
- After xorg, gnome-core, and synaptic, you can probably type startx and run a basic Gnome desktop, then run Synaptic and manage the remainder of the packages from there.
- Make sure to set both aptitude and synaptic to not treat “recommends” as dependencies! Else, you’ll get everything the package maintainer thinks you might want, and that’s too much for a 2-gig stick.
- Make sure you run
apt-get cleanto eradicate the downloaded package archives, else your stick will be full. Synaptic can be set to do this automatically.
What’s Next?
After I did all the above, I plugged in another $5 stick and did a Debian Etchnhalf install to it.
Please read about those adventures in the next article, Etchnhalf on a Stick

