Difference between revisions of "Install linux on a USB disk"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
m
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
Modern computers can boot from [[USB]] storage like disks and sticks. But how to make a USB disc or stick bootable? Here are some approaches:
+
Modern computers can boot from [[USB]] storage like disks and sticks. But how to [[install Linux]] there to have a USB disc or stick bootable? Here are some approaches:
  
 
{| class="wikitable sortable" border=1
 
{| class="wikitable sortable" border=1
! approach !! time to succeed !! remarks
+
! approach !! OS of your computer must be !! distro of bootdisk will be !! time to succeed
 
|-
 
|-
| Unetbootin || 1 hour, depends on your choices || works with all distributions supported by unetbootin and with all distros you have a bootable medium of
+
| [[install Linux on a USB disk with Unetbootin]] || Linux or Windows || any || 1 hour, depends on your choices
 
|-
 
|-
| Knoppix    || 30 min, depends on harddisk speed and size || only works with Knoppix
+
| [[install Linux on a USB disk with Knoppix]]   || any || Knoppix || 30 min, depends on disk speed and size
 
|-
 
|-
| SUSE Studio || 1 hour || only works with SUSE distros
+
| [[install Linux on a USB disk with SUSE Studio]] || Linux or Windows || SUSE || 1 hour
 
|-
 
|-
| Cloning-approach || 2 hours || work with almost all distributions
+
| [[install Linux on a USB disk by cloning your computer]] || any Linux || any || 2 hours
 
|}
 
|}
 
 
= the unetbootin approach =
 
UNetBootIn allows you to install Linux to a harddisk from the network or from a bootable CD, DVD, harddisk or image.
 
* download unetbootin from http://unetbootin.sourceforge.net
 
* [[open a console]] and make the downloaded file executable, e.g.:
 
cd
 
cd Downloads
 
chmod 777 unetbootin-linux-575
 
* start it
 
./unetbootin-linux-575
 
* when asked for libpng12, install the 32bit version of it, e.g. under SUSE Linux 12.1 x64:
 
yast -i libpng12-0-32bit
 
* when asked for p7zip, install it, e.g. under SUSE Linux 12.1 x64:
 
yast -i p7zip
 
* select which distribution you want to have installed on what disk:
 
[[File:unetbootin.png]]
 
 
= the knoppix approach =
 
There are two knoppix tools to install knoppix to a USB drive,
 
* flash-knoppix
 
* own
 
In this tutorial we use flash-knoppix.
 
 
Boot your system from [http://www.knoppix.org knoppix], then [[open a console]] and enter
 
flash-knoppix
 
The program starts and lets you select a harddrive:
 
 
[[File:snapshot-flash-knoppix.png]]
 
 
Then select a harddisk or a USB Flash drive. This will be made boot Knoppix. After that, you can make it possible to store something on your bootdisk:
 
[[File:Snapshot-flash-knoppix2.png]]
 
 
== additional information ==
 
Make sure you have a graphical display. This installer will give a lot more messages than the text-based installer.
 
 
== TroubleShooting ==
 
* Your USB Flash drive must be vfat-formatted. Otherwise, flash-knoppix will not work.
 
 
= the SUSE Studio approach =
 
Go to www.susestudio.com. Choose your favorite SUSE, add packages as you like. Tell the web site to build a USB stick from it. Download the image and put it onto your USB stick.
 
 
For example, if your USB stick is /dev/sdh, use something like
 
dd if=usbstick.i686-0.0.1.raw of=/dev/sdh
 
 
= the cloning approach =
 
The cloning approach is the manual approach where you clone your harddisk to a USB harddisk and then write a bootsector using [[grub]].
 
 
== Boot your favorite Linux ==
 
This has been tested with SUSE Linux 10.0 and Ubuntu 7.04.
 
 
== Connect the USB disk ==
 
Attach the USB disk and type <tt>[[dmesg]]</tt>. At the end of the messages, you will find something like "Attached SCSI device to /dev/sda". Then you know your USB disk's device name is /dev/sda. In this tutorial, we assume the device name is /dev/sda.
 
 
== Partition the USB disk ==
 
[[fdisk]] /dev/sda
 
In this tutorial, we will assume you create a partition /dev/sda1 for your root ( / ) directory.
 
 
== Format the USB disk ==
 
mkfs -t ext3 /dev/sda1
 
 
== Clone your system ==
 
Copy over all files from / to your USB disk. See also [[Cloning]].
 
[[mkdir]] -p /mnt/sda1
 
[[mount]] /dev/sda1 /mnt/sda1
 
[[cd]] /
 
[[tar]] -c [[Bash_operators#.24.28.29|$(]][[ls]] -1 [[piping||]] [[grep]] -Ev "[[regex|proc|sys|tmp|media|mnt]]"[[Bash_operators#.24.28.29|)]] [[piping||]] (cd /mnt/sda1; tar -xv)
 
 
'''You should know''' that you will need the /dev folder to create the ramdisk later. You can also use tar -cl ('''l'''ocal filesystems only), but that might exclude your /boot partition.
 
 
== Make your USB disk bootable ==
 
Here are two possibilities for making the disk bootable, it is not unusual that one fails. Try the uppermost first. We assume your USB disk is drive ''/dev/sdx'' mounted to ''/mnt/sdx''.
 
 
=== Possibility (1) ===
 
$ [[cp -pr]] ''/dev/sdx*'' ''/mnt/sdx1''/dev
 
$ [[cd]] ''/mnt/sdx1''
 
$ [[chroot]] .
 
Now make sure you can access all devices from /boot/grub/device.map.
 
$ mount /proc
 
$ grub-install ''/dev/sdx''
 
$ exit
 
 
=== Possibility (2) ===
 
$ grub-install --recheck --root-directory=''/mnt/sdx1'' ''/dev/sdx''
 
Probing devices to guess BIOS drives. This may take a long time.
 
Installation finished. No error reported.
 
This is the contents of the device map /mnt/sda1/boot/grub/device.map.
 
Check if this is correct or not. If any of the lines is incorrect,
 
fix it and re-run the script `grub-install'.
 
 
(fd0)  /dev/fd0
 
(hd0)  /dev/hda
 
(hd1)  /dev/hdb
 
(hd2)  ''/dev/sdx''
 
 
=== TroubleShooting ===
 
==== The file /boot/grub/stage1 not read correctly ====
 
* '''Symptome''' is that grub-install fails with the message
 
The file /boot/grub/stage1 not read correctly
 
 
* '''Reason''' can be that your partition type is incorrect, e.g. like this:
 
$ fdisk -l
 
 
Disk ''/dev/sdx'': 160.0 GB, 160041885696 bytes
 
255 heads, 63 sectors/track, 19457 cylinders
 
Units = cylinders of 16065 * 512 = 8225280 bytes
 
 
    Device Boot      Start        End      Blocks  Id  System
 
''/dev/sdx1''  *          1      19456  156280288+  '''c  W95 FAT32 (LBA)'''
 
 
* '''Solution''' can be to correct your partition type to 83 (Linux) using [[fdisk]].
 
 
== Edit your initial ramdisk ==
 
The initial ramdisk ([[initrd]]) must contain the modules needed to load usb storage. We will use [[mkinitrd]] to rebuild your initial ramdisk. First, change to your system on the USB disk:
 
cd ''/mnt/sdx1''
 
chroot .
 
mount /proc
 
Now have a look at the drivers that are loaded by the initial ramdisk.
 
 
=== SUSE ===
 
For [[SUSE]], your drivers file is /etc/sysconfig/kernel.
 
You will find a line starting with INITRD_MODULES= in /etc/sysconfig/kernel. It should look like this:
 
INITRD_MODULES="jbd reiserfs ext3 usbcore usb_storage scsi_mod sd_mod uhci_hcd ehci-hcd sbp2 sr_mod"
 
it can also contain more modules. Verify this line exists, then, create the initial ramdisk:
 
mkinitrd
 
 
=== Ubuntu ===
 
For Ubuntu, your drivers file is /etc/modules. It should look at least like this (it can also contain more modules):
 
<pre>
 
# /etc/modules: kernel modules to load at boot time.
 
#
 
# This file contains the names of kernel modules that should be loaded
 
# at boot time, one per line. Lines beginning with "#" are ignored.
 
 
fuse
 
lp
 
usb_storage
 
uhci_hcd
 
usbcore
 
usbhid
 
sr_mod
 
sd_mod
 
scsi_mod
 
</pre>
 
After you verified the file exists, create your [[initrd]] with the command:
 
mkinitramfs -o /boot/initrd.img
 
 
== Use a unique device name ==
 
If you now boot from your USB disk, it might be that it appears under another name than /dev/sda. To circumvent this problem, we will now use the disk's unique ID instead of /dev/sda. Try
 
[[hwinfo]] --partition
 
You will get a line similar to the following:
 
  Device Files: ''/dev/sda1'', /dev/disk/by-id/usb-CompanyXXXXXX,_Inc._USB_Mass_Stor
 
age_Device_100-part1, /dev/disk/by-path/pci-0000:00:1d.7-usb-0:3:1.0-scsi-0:0:0:
 
0-part1, ''/dev/disk/by-uuid/84ff6790-9b69-4401-9ba2-43d044af1d30'', /dev/disk/by-la
 
bel/Whatever
 
Now you know your partition is not only accessible via ''/dev/sda1'', but also via ''/dev/disk/by-uuid/84ff6790-9b69-4401-9ba2-43d044af1d30''.
 
 
=== /etc/fstab ===
 
You can now edit the [[fstab]] on your USB disk:
 
[http://userbase.kde.org/KWrite kwrite] /mnt/sda1/etc/fstab
 
there is one line for the mountpoint '''/''', maybe:   
 
''/dev/sda1''              /              ext2            defaults        1  1
 
In our example, you would change this line to
 
''/dev/disk/by-uuid/84ff6790-9b69-4401-9ba2-43d044af1d30''  /  ext2  defaults  1  1
 
 
=== /boot/grub/menu.lst ===
 
In /mnt/sda1/boot/grub/menu.lst, you will find some lines telling the kernel where to find the root (/) file system, maybe:
 
kernel          /boot/vmlinuz-2.6.20-16-generic root=''/dev/sda1'' ro quiet splash
 
not to boot from the wrong partition, you can also replace them:
 
kernel          /boot/vmlinuz-2.6.20-16-generic root=UUID=''84ff6790-9b69-4401-9ba2-43d044af1d30'' ro quiet splash
 
 
== Try booting from your disk ==
 
If there are problems, continue with TroubleShooting.
 
 
== TroubleShooting ==
 
=== GRUB - nothing else ===
 
* When booting from USB, I get a line saying
 
GRUB
 
nothing else.
 
: This can be a problem with your device map. Keep in mind that, when booting from USB, your USB disk corresponds to (hd0), the first harddisk. grub-install will tell you where its device map is - try correcting it.
 
 
=== Error 17 after boot menu ===
 
* After choosing an item from the [[grub]] menu, I get a line saying
 
Error 17: Cannot mount selected partition
 
: most probably, your device order has changed. For example, if you [[installed linux]] from CD and your IDE harddisk was device 0, it may now be device 1 after [[Booting from USB]]. In this case change
 
root (hd''1'',1)
 
to
 
root (hd''0'',1)
 
Please note that ''1'' is simply an example for a partition, it may also be any other number.
 
 
=== Error 17 before boot menu ===
 
* Instead of getting the [[grub]] menu, I get a line saying nothing else but
 
Error 17
 
: most probably, your device order has changed and grub searches its menu (stage) on the wrong disk. You will have to do grub-install again.
 
 
=== Error 21 before boot menu ===
 
* instead of getting the [[grub]] menu, I get a line saying
 
Error 21
 
: Solution was to correct ''/mnt/sda3''/boot/grub/device.map and ''/mnt/sda3''/boot/grub/menu.lst, the re-do a grub-install.
 
 
=== Waiting for /dev/sda to appear ===
 
* After selecting the boot entry in the [[grub]] menu, you get some lines of messages then the boot process stops with the message
 
Waiting for ''/dev/sda'' to appear
 
: your USB disk is recognized and supported by your BIOS, but your initrd's drivers do not recognize it. You will have to edit your initial ramdisk to contain the correct drivers, as discussed under initrd.
 
 
=== No bootable partition in table ===
 
* After starting the computer, you get a line saying
 
No bootable partition in table
 
: you do not have a partition that is marked as bootable. Use [[fdisk]]'s "a" command to set the bootable flag of ''/dev/sda1''.
 
 
== What comes next ==
 
Now that you can boot from your USB disk, you should be aware that you cannot write very often to a specific sector, so you should make /tmp a [[ramdisk]] like this:
 
mount -t tmpfs tmpfs /tmp -o size=512M
 
  
 
= See also =
 
= See also =

Latest revision as of 14:25, 1 November 2013

Modern computers can boot from USB storage like disks and sticks. But how to install Linux there to have a USB disc or stick bootable? Here are some approaches:

approach OS of your computer must be distro of bootdisk will be time to succeed
install Linux on a USB disk with Unetbootin Linux or Windows any 1 hour, depends on your choices
install Linux on a USB disk with Knoppix any Knoppix 30 min, depends on disk speed and size
install Linux on a USB disk with SUSE Studio Linux or Windows SUSE 1 hour
install Linux on a USB disk by cloning your computer any Linux any 2 hours

See also