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:
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
kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/hda1 ro vga=791 splash rootdelay=8
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:
Also please don’t forget to rate this post below.