Installing Linux on USB – Part 5: Installing Debian Linux on USB flash memory drives
Welcome to the part 5 of “Installing Linux on USB” series. In this part we are going to learn how to install Linux on a USB Flash memory drive. Please remember that a USB flash drive is different than a USB hard drive. Please refer to our part 1 to see the differences. Purpose: In this post we will see what are some precautions that we need to take while installing Linux on USB flash drives. This part is mainly based on our part 2 of this series which explained how to install Debian Linux on USB hard drives. So let’s get started… Please 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 mount options to “noatime” and “relatime”. We discussed all this in our part 4 of this series. So in short your Step 11 would be:
Step 12:
Step 13:
Now you can follow the rest of the steps (from Step 11 onwards) from part 3. Now once you are finish installing Debian and installing GRUB to your MBR reboot your system and boot from your USB flash drive. You should be able to see the GRUB screen. Now as soon as you see the GRUB screen hit “e” key on your keyboard which will take you to the GRUB editing screen. Append the following at the end of your kernel command line: rootdelay=<seconds> So your line should look something like this: kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/hda1 ro vga=791 splash rootdelay=8 The rationale of adding the rootdelay boot parameter is that we need to introduce a certain amount of delay in seconds so that the USB mass storage (your USB flash drive) gets initialized properly so that the kernel can load the root filesystem which is present on your root device (USB flash drive). If we don’t give any delay, chances are that you will see the following dreaded “VFS” kernel panic error message: VFS: Cannot open root device 'hda1' or unknown-block(0,0) Please append a correct 'root=' boot option Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
This happens because as soon as the kernel finishes initializing it’s data structures after getting loaded into the memory, it starts to look for the root filesystem on the bootable device (say which is /dev/sda). Generally USB storage devices takes some time (5 to 10 seconds) before they are fully initialized and ready to be used. So if we don’t tell kernel to wait for some seconds (through adding rootdelay parameter), the kernel will just assume that there is not root filesystem present and will start panicking. Since kernel 2.6.10, the USB flash storage initialization code got changed and hence we need to introduce the rootdelay parameter. Note: You may not be required to give this parameter if you are using “initrd” to boot your Debian installation which is likely the case because Debian’s default boot method involves using initrd (initial ramdisk). However it is still recommended that you give the “rootdelay=” parameter just as a fail-safe measure. To make this change permanent you need to edit your /boot/menu.lst file and add the parameter at the following locations:
........ .........
# kopt=root=/dev/hda1 ro vga=791 splash rootdelay=8
..... .....
title Debian GNU/Linux, kernel 2.6.26-1-686
root (hd0,0)
kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/hda1 ro vga=791 splash rootdelay=8
initrd /boot/initrd.img-2.6.26-1-686
Also you can try experimenting with the seconds value and see what works out best for you. Some USB flash drives requires just rootdelay=5 whereas some may require rootdelay=10. You need to find out what’s works best for you. Although ‘8′ is a safe option and will work for most of the USB flash drives. Conclusion: To conclude this post, we only need to take care of two things while installing Linux on USB flash drives: 1. Format your partition as Ext2 instead of Ext3 and add noatime and/or relatime option to your /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/sda1 / ext2 noatime,errors=remount-ro 0 1 /dev/sda5 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0 2. Add the rootdelay= parameter to your GRUB’s menu.lst file title Debian GNU/Linux, kernel 2.6.26-1-686 root (hd0,0) kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/hda1 ro vga=791 splash rootdelay=8 initrd /boot/initrd.img-2.6.26-1-686 Hopefully after following all the above you are able to run Debian (Lenny) from your USB flash memory/drive. As usual, please leave a comment/feedback if you have any. Comments encourages bloggers to post more and keep their spirits high.
If this post was helpful to you then please consider subscribing to this blog site:
Or else you can register here. Fore more information regarding subscriptions/registration please click here.
Also please don’t forget to rate this post below.
Part 6: Create a DOS and Linux bootable USB flash drive




Free Email Subscription









February 3rd, 2009 at 11:42 pm
[...] Part 5: Installing Debian Linux on USB flash memory drives [...]
February 3rd, 2009 at 11:47 pm
[...] Part 5: Installing Debian Linux on USB flash memory drives [...]
February 11th, 2009 at 12:25 am
[...] our Linux partition (/dev/sdc2) that we created above as Ext2 partition. Why Ext2? Please read my previous post for more details on this [...]
February 22nd, 2009 at 12:38 am
If I disconnect my hdd while installing onto the flash drive it doesn’t really work. After booting into GRUB after the install with hdd connected again and selecting the first option to boot, it tries booting from the hdd instead of the flash drive (although GRUB did start from flash drive). However with hdd disconnected it works just fine.
Reply to this comment
Kushal Reply:
February 22nd, 2009 at 1:08 am
Hello Shake,
Thank you for your comment! Always nice to hear back from visitors.
Yes, I think I know the reason. Is your hdd detected as /dev/sd*
If yes, then this is a pretty obvious and annoying scenario…
What does your GRUB first option contains? root=/dev/sda I am guessing….Now when you connect your HDD and are trying to boot from USB try passing root=/dev/sdb and see if you can get your system to boot. Once can switch to using UUIDs instead of /dev/sd* naming scheme to solve this problem.
Please report back if this solves your problem.
Reply to this comment
March 9th, 2009 at 1:25 pm
Smokin’ tutorial.
Reply to this comment
Admin Reply:
March 10th, 2009 at 9:49 am
Thank you for your comment!
You can also subscribe to my blog site here:
http://blogs.koolwal.net/subscribe/
Reply to this comment
March 13th, 2009 at 11:23 am
[...] Part 5 [...]
August 1st, 2009 at 5:40 am
Very nice tutorial..
I am wondering if it is ok to do the same steps(Part5) for CompactFlash?
Reply to this comment
Admin Reply:
August 5th, 2009 at 12:11 pm
That depends. Usually Compact Flash are detected as regular hard drives so they won’t require any special treatment. If they are not then I don’t see why anybody cannot use the same steps as mentioned in Part 5. So go ahead and try it.
Reply to this comment
firefox2501 Reply:
January 8th, 2010 at 7:49 pm
Yes, compact flash drives are typically recognized as standard hard drives. But they are more similar to USB flash drives, as they also have a limited number of writes.
Reply to this comment
August 12th, 2009 at 5:37 am
“Now once you are finish installing Debian and installing GRUB to your MBR reboot your system and boot from your USB flash drive”
In the above lines i would suggest to clarify the procedure more. Since installing GRUB should be on the USB not on the HDD MBR. because if you installed on the HDD you will not be able to boot your original PC’s OS unless USB is plugged.
So all what you have to do is click “NO” when the installer asks about installing GRUB, and on the following page you will be able to specify USBs path for installation directory i.e. /dev/sdb1 (in my case).
I believe this hints will avoid users to have problems as i had when going through your nice tutorial.
Reply to this comment
January 8th, 2010 at 7:41 pm
A lot of this article focuses on reducing the number of writes to the flash drive. And you did that very well.
However, according to the fstab snippet you posted, you still have the swap partition on the flash drive. This can also generate a lot of writes to the flash.
Options to get around putting the swap partition on the flash:
1) You can install without a swap partition, however, that may cause problems down the road, and that would require manually partitioning the drive.
2) You can install the swap partition on another drive, preferably a hard drive, not a flash. But once again, this requires manually partitioning the drive.
Anyone have other thoughts on how to get around excessive writes for the swap partition?
Reply to this comment