- 论坛徽章:
- 0
|
又发现一个好东西
Live System on USB flash drive / USB memory stick
http://linux.web.psi.ch/livecd/usbdisk.html
Live System on USB flash drive / USB memory stick
In order to boot from a USB drive your BIOS has to support booting from an USB device
and you need to install a bootloader like grub or syslinux on it.
The following description uses
syslinux
as bootloader and assumes that the USB memory stick
is on /dev/sda. A similar setup can also be done with grub as bootloader.
Please note, you must be root to execute most of the following commands.
If you don't have a running Linux system, you can do the whole procedure
out of a running SL LiveCD/DVD.
WARNING: If you change the wrong MBR or if you format the wrong partition,
you can destroy your system, which can leave to complete data loss!
Please make sure that you know which device corresponds to your USB memory stick (e.g. /dev/sda or /dev/sdb) !!!
To boot from USB memory is not a trivial task.
Whether it works or not can depend on the MBR and on the partition of
your stick, on the USB memory stick itself and on the BIOS of your PC.
If you have any suggestions/corrections for the following procedure,
please let me know
.
Format the USB stick
On Windows
There is a useful tool from HP which allows you to format your USB memory stick.
Unfortunately it runs only under Windows.
Download the HP USB Disk Storage Format Tool
from
ftp://ftp.compaq.com/pub/softpaq/sp27001-27500/SP27213.exe
.
Choose as file system FAT (not FAT32) and format the stick.
I have to admit that I had more success using the HP tool than doing it under Linux.
On Linux
Check on which device (dev/sd?) your USB memory stick is recognized
by the system. If you have only IDE disks, it will be most probably
appear on /dev/sda otherwise it can be on /dev/sdb or higher. See
# tail -f /var/log/message
while you plug in the USB memory stick.
The USB device should also be visible by the command
# fdisk -l
First you have to overwrite the master boot record (MBR) of your USB flash drive.
Caution: Overwriting the wrong MBR (for example the one of your hard disk) can leave to complete data loss!
If you are unsure, please back up your MBR(s) to a file and copy this file to a safe place
(floppy disk, other USB memory stick, ...).
For example to write the MBR of the first SATA disk (/dev/sda) to a file mbr_sda.bin, run:
# dd if=/dev/sda of=/tmp/mbr_sda.bin bs=512 count=1
Create a Windows 95/98 MBR on USB memory stick, using ms-sys
(
http://ms-sys.sourceforge.net
). Ms-sys is available on recent SL LiveCD/DVDs or you can take the rpm for el4 from
http://dag.wieers.com/packages/ms-sys/
.
# ms-sys --mbr95b /dev/sda
Windows 95B/98/98SE/ME master boot record successfully written to /dev/sda
Then create a FAT16 partition on the USB flash drive:
# fdisk /dev/sda
Create a new partition (enter n): Choose Primary partition (enter p), Partition number (enter 1).
The size of the partition should be at least as larger as the LiveCD/DVD you want to install on the USB device.
Afterwards, change the type (enter t) of first partition (enter 1) to W95 FAT16 LBA (enter e),
and make first partition active (enter a and select 1).
Before writing the partition table to the USB flash drive (enter w), you can print the changed settings (enter p).
Now format the first partition (/dev/sda1) as FAT16:
# mkdosfs /dev/sda1
Note, this is all done without mounting the partition.
Make the USB memory stick bootable using syslinux
You should have now something like:
# fdisk -l /dev/sda
Disk /dev/sda: 524 MB, 524288000 bytes
17 heads, 59 sectors/track, 1020 cylinders
Units = cylinders of 1003 * 512 = 513536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 390 195555+ e W95 FAT16 (LBA)
Important: The first partition is active (marked with *) and is a FAT16 partition: ID "e".
In the above case, I created an active FAT16 partition having a size of 200MB,
which is enough to store the data of the Mini LiveCD.
Now the syslinux boot loader has to be installed on the first FAT partition.
Scientific Linux 4 comes with syslinux version 2.11. Try to use first this syslinux version:
# syslinux /dev/sda1
If you get the error "Cluster sizes larger than 16K not supported", try to use a more recent version of syslinux.
Syslinux can be downloaded from kernel.org:
http://www.kernel.org/pub/linux/utils/boot/syslinux/.
I have successfully used syslinux 3.11. Download, unpack and compile syslinux by executing "make".
You will find the syslinux binary in the folder unix:
# wget http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.11.tar.gz
# tar xfvz syslinux-3.11.tar.gz
# cd syslinux-3.11
# make
# cd unix
# ./syslinux /dev/sda1
This should create a file "ldlinux.sys" in the sda1 partition.
Now try to boot from the USB memory stick. If this works you should see someting like:
SYSLINUX 3.11 2005-09-02 EBIOS Copyright (C) 1994-2005 H. Peter Anvin
Could not find kernel image: linux
boot:
Congratulation, you USB stick is no bootable!
If you get "boot failed", "Missing operation system", "Boot error" or just nothing, try to redo the above steps -
also try to format the stick under Windows as described above.
Copy LiveCD data
First mount the partition. Under Scientific Linux /dev/sda1 will be mountable under /media/"something":
# mount /dev/sda1
or do it manually:
# mkdir -p /media/usbdisk
# mount /dev/sda1 /media/usbdisk
Since your have already installed syslinux on the USB memory stick before, you should see
# ll /media/usbdisk
total 12
-r-xr-xr-x 1 root root 8236 Apr 27 21:23 ldlinux.sys
Either mount the LiveCD/DVD directly or just mount the ISO image of the LiveCD/DVD:
# mkdir -p /mnt/iso
# mount -o loop mini_livecd_SL42_2006-03-28.iso /mnt/iso
Copy everything from the CD/DVD to the USB flash drive:
# cp -r /mnt/iso/* /media/usbdisk/
In contrast to grub, syslinux can not access the kernel and the initial RAM disk
in the "boot" folder.
Therefore you have to move the "boot"-files to the root folder of the USB flash drive:
# cd /media/usbdisk/
# mv boot/* .
Rename isolinux.cfg to syslinux.cfg and delete the path "boot/" in syslinux.cfg, splash.cfg and help*.txt:
# mv isolinux.cfg syslinux.cfg
# sed -i "s|boot/||" syslinux.cfg
# sed -i "s|boot/||" splash.cfg
# sed -i "s|boot/||" help*.txt
You can also remove the isolinux.bi_, isolinux.bin and isolinux.boot files:
# rm isolinux.*
Now everything should be ready for booting the USB flash drive.
The most important files on the USB flash drive are:
|-- base
| |-- bin.mo
| |-- etc.mo
| |-- ....
|-- ...
|-- help1.txt
|-- help2.txt
|-- ...
|-- initrd.gz
|-- ldlinux.sys
|-- livecd.sgn
|-- memtest
|-- splash.cfg
|-- splash.lss
|-- syslinux.cfg
|-- vmlinuz
Finally, unmount the USB flash drive.
# umount /media/usbdisk
Create a writable /home partition on the USB flash drive
First you need some free space on your USB memory stick which is not used by the first partition (/dev/sda1).
Either you have already taking this into account when you created the first partition
or you can try to resize your first partition with parted.
Please make sure that you know which device corresponds to your USB memory stick (e.g. /dev/sda or /dev/sdb) !!!
Maybe it's easier to resize the partition before coping the LiveCD data into it. In short:
# parted /dev/sda
...
Using /dev/sda
(parted) resize
Partition number? 1
Start? [0.0308]?
End? [1983.9995]? 1890
...
(parted) quit
If you get errors during the use of parted, just type "i" for Ignore and
do not change the file system to FAT32 - leave it as FAT.
Now create a ext3 partition on /dev/sda:
# fdisk /dev/sda
Create new partition (n): Primary partition (p), Partition number (2) and
choose an appropriate size for the partition.
Format /dev/sda2:
# mkfs.ext3 /dev/sda2
Maybe you want to disable automatic filesystem check for this partition:
# tune2fs -c 0 /dev/sda2
Create home directory on /dev/sda2:
# mkdir -p /media/usbdisk2
# mount /dev/sda2 /media/usbdisk2
# mkdir /media/usbdisk2/home
Add boot parameter "home=/dev/sda2:/home" to syslinux.cfg.
You should add home=/dev/sda2:/home even if your USB stick is now on /dev/sdb or /dev/sdc!
Because (most probably) the USB stick will be seen /dev/sda if you boot from it.
# cat syslinux.cfg
...
append home=/dev/sda2:/home max_loop=32 vga=791 initrd=initrd.gz .....
Or even more advanced
# cat syslinux.cfg
...
append home=/dev/sda2:/home kb=sg-latin1 pw=mypassord max_loop=32 vga=791 initrd=initrd.gz .....
See
boot parameters
for more options.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/904/showart_242827.html |
|