Installing Linux on USB – Part 2: Install Debian Lenny on USB Hard Drive
Welcome to the part 2 of “Installing Linux on USB“ series.
Purpose: In this part we will learn how to install Debian Linux (Lenny) on a USB hard drive. In part 1 of this series I had explained the difference between a USB hard drive and USB flash drive. I suggest you refer to it before you go ahead any further with this part. This is the simplest type of install that you can do on a USB hard drive. Later on we will cover more complex ones like using FAT/ext2 combo, JFFS and squashfs filesystem. For now we will just use the our good old ext3 file system which is recommended for hard drive.
Also this tutorial will mostly be image-oriented and I will add my comments wherever necessary.
Requirements for this part:.
1. A USB or an IDE CD-ROM
2. Debian Lenny Install CD
3. A computer which can boot from USB devices – Hard drives and CD-ROMs (optional, but you need to have an IDE CD-ROM)
Quick conclusion: Installing Debian on USB hard drive is not at all different than installing on a regular IDE (or PATA) and SATA hard disk. The only main difference is that the USB hard drive is detected as “/dev/sdX” instead of the traditional “/dev/hdX” which is for IDE/PATA hard drives. If you are interested in detailed installation step then please read on…
Tip: In order to avoid any confusion and prevent data loss please disconnect any IDE/SATA drive that you may have attached to your system if possible. If you cannot physically disconnect them then try to disable them in your BIOS so that Linux installer does not detect it.
Note: If at any time you want to enlarge the screenshots just click on them and they will open in a new browser window.
Step 0: Boot from the CD-ROM with Debian Lenny Install CD
Step 1: Select either Graphic or simple install (I selected Graphic install)
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:
Note: I just had a USB hard drive attached so the only disk I had was /dev/sda. In case if you also have fixed IDE hard drive attached to your system (which you are likely to have) then you will also see an entry with /dev/hda or even /dev/sdb if your have a SATA drive. Make sure you know the name, size and model number of your USB hard drive so that you select it instead of selecting your IDE/SATA drive and erasing them. Linux detects USB and SATA devices as /dev/sdX
Step 10:
Step 11:
Step 12:
Step 13:
Step 14:
Step 15:
Step 16:
Note: Make sure that you install GRUB bootloader to the MBR of your USB hard drive.
Step 17:
Congratulations! If you have reached so far chances are that you will be able to boot into your Debian system on your USB hard drive. Simply restart your machine and boot from USB hard drive. You should be able to see the GRUB menu.
Upon successfully booting to a console (prompt) you can use this installation just like any other IDE hard drive installation.
What after installation?
File system
Now let’s review how our disk structure and filesystem looks like.
# cat /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
/dev/sda1 / ext3 errors=remount-ro 0 1
/dev/sda5 none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0
/dev/sda1 – Is our primary partition with ext3 filesystem
/dev/sda5 – Is our swap file system
/dev/scd0 – Is our USB CD-ROM
Please note that there are lots of different filesystem like ext2, XFS, ReiserFS, JFFS, etc that you can install Debian too. Each one of them has their own advantage and disadvantage. We will try to cover each one of them separately in this series. So please stay tuned.
Performance
There is lot of debate regarding throughput/performance when it comes to installing Debian on USB devices which in turn is partly dependent on the filesystem that we use. So we will keep track of data throughput for each install type throughout our series. We will use the tool ‘hdparm’ for this purpose.
# apt-get update
# apt-get install hdparm
Note: You might need to change your sources.list file to point to proper repositories in case if you are no longer using the installation CD.
Now give the following command:
debian:~# hdparm -tT /dev/sda
/dev/sda:
Timing cached reads: 428 MB in 2.01 seconds = 213.26 MB/sec
Timing buffered disk reads: 60 MB in 3.05 seconds = 19.65 MB/sec
debian:~#
And following is the throughput when installing Debian on a regular hard drive.
debian:~# hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 462 MB in 2.01 seconds = 230.33 MB/sec
Timing buffered disk reads: 74 MB in 3.07 seconds = 24.13 MB/sec
debian:~#
Additional notes:
As you may have guessed by now that there is nothing special required to install Debian Lenny on a USB hard drive. However there are various things that you can do to optimize the throughput by tweaking the files system setting which we will cover in our new few parts.
As usual, please leave a comment/feedback if you have any. Comments encourages bloggers to post more and keep their spirits high.
Also don’t forget to rate this post below.
Part 3: Which Linux filesystem for USB devices?



















Email Subscription









January 28th, 2009 at 9:24 am
[...] Part 2: Install Debian Lenny on USB Hard Drive [...]
January 28th, 2009 at 9:36 am
[...] Part 2: Install Debian Lenny on USB Hard Drive [...]
February 3rd, 2009 at 11:51 pm
[...] follow from Step 0 to Step 10 of part 2. Now instead of selecting Ext3 as your partition type select Ext2. And also change the default [...]
March 11th, 2009 at 9:44 am
[...] Part 2 [...]
April 29th, 2009 at 9:15 am
Thank u man. If this works you’ll get the credits!
Reply to this comment
May 20th, 2009 at 1:16 am
Hi! I installed yesterday Debian testing from the weekly iso images on to an external USB hard drive. When the install finished, my grub, installed onto MBR of that external drive, complains with error 17 – unknown partition type when I try to run squeeze. When searching the net I came to the forum post on the linuxquestions where you put the link to your posts.
Well, while checking your article, I noticed that the only difference in mine and your install is that I did not disabled mine internal drive in BIOS. Maybe that is causing all the trouble (external was detected by the installer as sdf (i have an internal SATA, sda), but maybe when than starting from grub of the external HDD, the partitions are detected as sda instead of sdf. I will play with fstab and menu.lst files a bit and will see if that will work.
Still, I want to congratulate you for your article. Bravo.
Reply to this comment
Admin Reply:
May 27th, 2009 at 1:33 am
Thank you dawith! Yes it is best to disable any other hard drive that you may have attached to your system.
Reply to this comment
atteSmythe Reply:
October 14th, 2009 at 1:52 pm
How’d your project come out, dawith? I had my IDE controller disabled in BIOS, but somehow the installer detected it anyway! I had the same problem you did, it installed GRUB in the wrong place and now my hard drive is still not in working order – nor my thumb drive! C’est la vie.
Reply to this comment
November 22nd, 2009 at 6:32 pm
Same as dawith – did not disconnect internal hard drives.
Didn’t see why i should since no problem installing ubuntu etc to usb hard drive
Install as u’r article but when offered install to FIRST hard drive said no and gave mbr of my usb hard drive instead BUT system refuses to boot from it (error 17 etc)
Reply to this comment
November 30th, 2009 at 9:09 am
Thanks for your highly detailled article, I’m stuck like dawith and ynys. All install process was fine, I set the MBR of my usb hard drive, tried to boot and nothing ( error 17 ).
By using debian rescue CD, I reset / reinstall Grub without success, same error on boot. Did you solve this problem ?
Reply to this comment
January 28th, 2010 at 12:59 pm
When will these installers and bootloaders start to treat USB drives as first class citizens. It’s ridiculous (IMO) that you have to disable or disconnect your main drives in order to perform an install of the OS.
p.s. your article is great. Wish you had tried it without disabling your hard drive.
Reply to this comment
March 10th, 2010 at 7:02 pm
Could this work as portable?
I Wish to carry my USB HD everyewere I go with all functionality of my linux Debian.
Thanks
Reply to this comment