Installing SuSE on External USB Drive

From openSUSE

This article provides a guide on installing openSUSE to an external USB drive and booting computer, with existing Windows installation, to openSUSE on USB disk.

You may want to try the Portable SUSE project. It offers easy installation of openSUSE to external USB drives.
It has been suggested that this article or section be merged with Portable SUSE . (Discuss)


Contents

Fixing problems

Before beginning such config, it's wise to know how to cope with problems...

As you will have to edit the boot system of your computer, you may have a corrupted boot system on your hard drive.

This is not scary, it's easy to fix.

So if after removing your USB device you get a GRUB error at start, the best way is to start the installed system with any install cd/dvd. Start the cd/dvd, go to install, click "other" and you will be proposed to "boot the installed system". Do that.

Do not use the "repair" option as it's very long and not necessary in your case, it can even add errors...

After the system start (and without any USB drive connected, not to be at risk of modifying this one an place of the internal drive), go to YaST, System, boot manager. Go to the Tab where you can choose where the boot mamaner is installed and choose only the place you had initially (probably the mbr). On 10.3 openSUSE one can choose several places, but it seems than only one is installed, so setup one at a time.

Save

Try it (reboot) it should be good.

Preparation

Things you need:

  • SuSE Linux installation DVD or CD

And that's all !

Boot

Boot the PC from the installation DVD.

Installation

Follow the setup wizard to the configuration of GRUB, proceed to Installation Settings, select Expert mode, in the Boot Loader Installation tab of Boot Loader Settings dialog, select Boot from Root Partition for the Boot Loader Location option. after the installation, SuSE will reboot automatically. Directly booting, even from the BIOS "USB Boot" will probably fail. So boot from the installation DVD again, proceed to Installation Mode, select Boot Installed System from Other Options, to complete the installation.

Warning

  • USB Boot of motherboards is tricky and often fail. Often without notice or reason.
  • Some bioses map the USB device only on demand, so even if you have any Linux installed, you can't boot the USB key from there at the first menu level (at least with GRUB), because GRUB don't know there is an USB device there.
  • USB HDD (as opposed to USB keys) draw much power. If they are not self powered (wall plug), they sometime need to be connected to two usb sockets to have enough power, and are is this case sold with special USB cable with the necessary two plugs.

Bootable flag

Seems like even on an USB stick, a partition have to get the "bootable flag" in the USB key partition table to be bootable by GRUB or syslinux, so use any fdisk utility to verify this (it may be dangerous to trust YaST for such unusual task)

First option

Login as root to the new installation, run grub-install in the terminal (assuming /dev/sdb being your external USB drive):

grub-install /dev/sdb

to install GRUB on the MBR of the external drive.

  • Notice: Do not install GRUB on the MBR of the internal hard disk, otherwise GRUB will fail to boot when the external drive is removed as it cannot access /boot/grub on the external drive.

This First option may or may not work. It's possible with some bioses to be stuck with "GRUB..." written in the upper left corner of the screen and nothing more.

In fact this option should not work (this doesn't mean it doesn't :-), because there is only one "MBR", on the very first disk of your system. So you should better (also) put GRUB on the root partition (again: assuming that sdb is your external USB drive)

grub-install /dev/sdb1

For example

Second option

One can also use "syslinux", the booting system used from floppies, cd's, dvd's and now USB devices. "syslinux" is for FAT file systems and may be usefull for booting from iso images located on a key. Extlinux is for ext2/etx3 file systems, so one can use these file systems on an USB device with Linux installed.

Follow all the install procedure described here up to the end. If GRUB don't start, boot from any Linux instalation. You can probably use the very USB device install, booted through the install dvd, but you must install the package "syslinux" with YaST.

Then go root, and on the mounted USB device do the following:

cd <absolute path where the kernel is>
extlinux -i <absolute path where the kernel is>

For example, if the USB device is mounted on the /media/disk folder of a pre-installed Linux, and you have your kernel in the /boot folder of the stick:

cd /media/disk/boot/
extlinux -i /media/disk/boot/

Then create in this very same folder (/media/disk/boot/) a config file "extlinux.conf" and fill it with:

default vmlinuz
append initrd=initrd.gz

Then copy the actual USB device initrd to the new name:

cp initrd initrd.gz

This because extlinux must know the initrd is compressed by it's extension.

Then boot... and enjoy

Configuring GRUB

If you have one SATA internal HDD and one external USB drive installed, the /boot/grub/device.map would be:

(hd0)	/dev/sda
(hd1)	/dev/sdb
  • Notice: When booting from external drive, GRUB will regard the external drive as /dev/sda (hd0) and the internal drive as /dev/sdb (hd1), which is the exact opposite situation when booting from the internal drive.

So edit /boot/grub/menu.lst, replace all hd0 with hd1 and hd1 with hd0. (In OpenSUSE 10.3 it does not seem necessary anymore.)

In case of a future kernel update, /boot/grub/menu.lst will probably be updated by Yast: remember that the same correction (hd0 <-> hd1) will again be necessary.

Additional Steps to Boot Existing Windows Installation from GRUB

As stated before, GURB treat the internal drive as (hd1) and if you directly boot Windows from GRUB, it'll pause after command chainloader (hd1,0)+1 because the Windows boot loader (NTLDR) refuse to boot from a slave hard drive. To fix the problem, add two lines in the Windows entry of /boot/grub/menu.lst:

map (hd0) (hd1)
map (hd1) (hd0)

So the entire entry would be like:

###Don't change this comment - YaST2 identifier: Original name: windows###
title Microsoft Windows XP Professional
   map (hd0) (hd1)
   map (hd1) (hd0)
   rootnoverify (hd1,0)
   chainloader +1

Save changes to menu.lst and reboot, the Windows boot loader will work now.

Conclusion

Now the system can boot from SuSE's GRUB when the external drive is pluged and BIOS is configured to boot from external USB device. When the external drive is removed, the system will boot from the internal drive as its original state.

When USB booting fails

Some PCs are not capable of booting from an external USB drive, no matter which BIOS setting you use or what you put into GRUB menu.lst. There are alternative solutions available.

Using internal drive

Another solution is to prepare a small partition in the internal hard drive, format as ext3 and mount /boot at that partition, install GRUB directly to the MBR and configure the BIOS to boot from the internal drive. Remember to plugin the external drive while booting to SuSE. (Remove the external drive won't affect GRUB using this methoed)

Using CD-image of your kernel

It is possible to prepare a bootable CD based on your installed system. The boot-CD will load the kernel and switch over to root-partition on the external USB-drive. However, there is a big gotcha. Default SuSE kernels have USB-drivers as modules making the root-partition unaccessible. To remedy this you need to do one of these:

  • You need to compile your own kernel and include USB-drivers in the kernel.
  • Include USB-modules in the init RAM-disk
    1. Modify /etc/sysconfig/kernel, section INITRD_MODULES to contain usb-storage and ohci-hcd/uhci-hcd/ehci-hcd depending on your system setup. Use lsmod and check which one you're running.
    2. Execute command mkinitrd to make previous change effective.
    3. Now your initrd has required modules in it. Go create the boot-image.

RedHat Linux has a script capable of creating a boot image. Make sure you have mkisofs and syslinux packages installed. Download and save a modified (SuSEfied) version of the bash-script. Check your kernel version (cat /proc/version or ls -l /boot/vmlinuz*) and execute the script:

./mkbootdisk.from.rh5-modified --device boot.iso -v --iso 2.6.18.2-34-default

boot.iso is the filename of ISO image to be created.
2.6.18.2-34-default is the kernel version to be put into the image.

Now burn the ISO-file into a CD and boot from it.

Xen

If you're running Xen, the above boot image will not work. The command line for Xen-kernels is:

./mkbootdisk.from.rh5-modified --device boot.iso -v --iso --xen 2.6.18.8-0.5-xenpae

boot.iso is the filename of ISO image to be created.
2.6.18.8-0.5-xenpae is the kernel version to be put into the image.

Using the Linux Volume Manager (LVM) for root on the USB disk

If your USB disk uses the Linux Volume Manager (LVM) to contain the root filesystem, the built-in /init script won't find it and will drop to a shell in the initrd environment. To work around this, apply the following patch to /sbin/mkinitrd and re-run it:

--- /root/mkinitrd-orig	2007-03-24 20:54:03.000000000 -0700
+++ mkinitrd	2007-03-24 21:22:26.000000000 -0700
@@ -2445,6 +2445,16 @@
 	|		break;
 	|	    fi
 	|	    sleep 1
+	EOF
+
+    if [ -n "$root_lvm2" ]; then
+    cat_linuxrc <<-'EOF'
+	|           /sbin/lvm vgscan
+	|           /sbin/lvm vgchange -ay
+	EOF
+    fi
+
+    cat_linuxrc <<-'EOF'
 	|	    echo -n "."
 	|	    timeout=$(( $timeout - 1 ))
 	|	done

Reference