Difference between revisions of "USB Based FAQ"


From Knoppix Documentation Wiki
Jump to: navigation, search
(KNOPPIX USB)
m (KNOPPIX USB: Added 'sync' command to steps to copy ISO to stick)
Line 48: Line 48:
 
  # mount /dev/loop0 knoppix
 
  # mount /dev/loop0 knoppix
 
  # cp -r knoppix/* /mnt
 
  # cp -r knoppix/* /mnt
 +
# sync
 
  # umount knoppix
 
  # umount knoppix
 
  # rmdir knoppix
 
  # rmdir knoppix

Revision as of 23:45, 20 April 2006

KNOPPIX USB

Knoppix is a GNU/Linux distribution that boots and runs completely from cd it can also boot and run completely from a USB drive.

To boot an unmodified Knoppix from a USB stick or USB hard drive is quite easy although it requires a few of steps. This tutorial assumes that you are already running GNU/Linux (and has been tested on Debian).

Edit from Ruymbeke on March 23rd 2006:
A lot of, if not most of the USB dongles are not bootable by default.
You may want to use the HPUSBFW.EXE tool (XP only) to make it bootable
by changing the geometry of the device and perform a low level (re-)format.
It may reduce sligthly the overall size of the drive (to make it bootable)
but I have run it successfuly on all my USB dongles: pqi, lexar, corsair, ...
You will find this tool and an alternate method for booting Knoppix 4.02
from a USB dongle using grub.exe or loadlin.exe from a dos boot in here:
http://www.knoppix.net/forum/viewtopic.php?p=93758#93758
http://www.knoppix.net/forum/viewtopic.php?p=101293#101293 (Knoppix 5.0 addon)
 Edit from mswoon on 14 Apr 2006: 
 
 I didn't have to do the above - just add 
 
 test -n "$FOUND_USB" -a -z "$NOUSB" && DEVICES="$DEVICES /dev/sd?[1-9] /dev/sd?[1-9][0-9]" 
 
 at the right place in linuxrc as documented in 
 
 http://www.knoppix.net/forum/viewtopic.php?p=64999
 
 and it worked on a 2GByte Memorex with no problem. 
 
 Not that I don't trust you, but can you release the source code for that XP-only software?

Attach your USB device to your computer and create a partition (using e.g. cfdisk) large enough to hold the contents of the ISO image plus about 5%. The rest of this discussion assumes that you can address this partition using /dev/sda1.

Create a file system on the partition: (or you can use an existing VFAT filesystem (to keep compatibility with Windows/DOS))

# mke2fs -j /dev/sda1

To prevent fsck from being run on it:

# tune2fs -c 0 -i 0 /dev/sda1

Mount the partition and copy the contents of the KNOPPIX ISO image (named KNOPPIX.iso below) to it:

# mount /dev/sda1 /mnt
# losetup /dev/loop0 KNOPPIX.iso
# mkdir knoppix
# mount /dev/loop0 knoppix
# cp -r knoppix/* /mnt
# sync
# umount knoppix
# rmdir knoppix
# losetup -d /dev/loop0

To setup Grub to boot from the USB drive, copy Grub's working files, namely, stage1, stage2 and the appropriate stage1_5 file, to the partition. It is easiest to simply copy all of Grub's files. Assuming your distribution has Grub's loader in /boot/grub:

# mkdir -p /mnt/boot/grub
# cp -r /boot/grub/* /mnt/boot/grub

To install the stage1 boot loader to the drive's master boot record (MBR), edit the device.map file to tell grub-install that /dev/sda1 is a bios drive:

# echo '(hd0) /dev/sda' > /mnt/boot/grub/device.map

and then install Grub to /dev/sda:

# grub-install --root-directory=/mnt --no-floppy '(hd0)'

Finally, create a menu.lst file. Look at /mnt/boot/isolinux/isolinux.cfg. These are the different default Knoppix configurations. The default configuration on 4.0.2 is:

DEFAULT linux
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=minirt.gz nomce quiet BOOT_IMAGE=knoppix

Converting this a Grub boot is relatively straight forward. On booting, the root is set to the boto device. This is the Knoppix partition which is exactly what we want. The line starting with DEFAULT tells isolinux which kernel in /boot/isolinux to use. APPEND tells isolinux the arguments to pass to the kernel. Grub needs to load the initrd on its own and the arguments go on the kernel line. With a bit of rearranging, we get the following:

title           Knoppix
kernel          /boot/isolinux/linux ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=minirt.gz nomce quiet BOOT_IMAGE=knoppix
initrd          /boot/isolinux/minirt.gz
boot

Add the above along with the following to /mnt/boot/grub/menu.lst to have Knoppix boot auotmatically:

default         0
timeout         2

Finally, unmount the partition.

# umount /mnt

You should now be booting Knoppix from your USB drive.

Booting to an Image on an Alternative Device

Poor Man's USB Based Boot (Boot from USB flash memory stick and then continue boot with Knoppix image stored on a harddisk or a CD or an external USB harddisk ) How To:

What you will need:

  • Computer with BIOS capable of booting from USB keydrive (select USB-HDD). (Unfortunately, some buggy BIOS just wont boot from my USB stick, such as all versions up to F9 for the Gigabyte GA-8IEXP motherboard).
  • USB keydrive that can boot as USB-HDD device. Make sure you read the product specification, only some USB flash sticks support this feature. (or see this 4/05 review on Ars Technica http://arstechnica.com/reviews/hardware/flash2005.ars . Only 3 of 10 reviewed sticks are bootable.)
  • Linux with GRUB grub boot loader already installed. I just use Knoppix.
  • Read Win Partition Poor Man Installation for the more versatile boot mechanism we gonna utilize here.

Steps: (Cautions: Unmount usb stick before you remove it from USB slot to avoid data loss. Backup the MBR of harddisk and USB stick, see the link above)

  1. Insert the USB stick, use cfdisk to create a partition with boot flag on this device ( cfdisk /dev/sda ). Create a file system on the newly created partition.(eg. mke2fs -m0 /dev/sda1)
  2. Mount the partition and install grub boot loader on this device ( mount /dev/sda1 /mnt/usb && grub-install --root-directory=/mnt/usb /dev/sda ). Now the USB stick is already bootable, you will enter the interactive GRUB shell enviroment if you boot with it.
  3. Copy kernel and initrd to USB stick. To continue boot from an knoppix 3.6 ISO image stored on a NTFS/FAT harddisk partition, you will need the kernel and miniroot.gz files from Ruymbeke's files.
  4. Create a file menu.lst under dir /mnt/usb/boot/grub, I just copied the one from Ruymbeke's files pasted in Win Partition PMI. Specify the location of the newly copied kernel and minirt files in this file, note (hd0,0) is the first partition on USB stick when you boot from it, and the first harddisk likes to be hd1. To find out how GRUB map devices, press key c when you see GRUB boot menu at boot time, then type root ( and press TAB key, see the GRUB texinfo for detail.

DONE.

I have created a 32M boot partition on a 128M USB flash stick, and use it to boot Knoppix ISO image stored in a FAT32 partition shared by Windows, or to boot ubuntu live CD (basemodule is Morphix) already copied to another partition. The purpose is to reduce the time to burn these Linux Live CDs and less CDs to carry with.