|
|
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/sdb. 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) !!!
The following description assumes that the usb stick is on /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.
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.
先备份MBR
dd if=/dev/sdb of=/tmp/mbr_sdb.bin bs=512 count=1
http://www.livecd.ethz.ch/usbdisk.html
usb linux copy
linux 系统拷贝
原理:
将系统打包,由另一个U盘启动的简单一点的系统执行命令将打包的系统解压到新硬盘,当然,解压前要进行格式化,分区等操作
步骤:
1.tar 打包一个LINUX系统(分别为sda1和sda2全盘打包,--exclude为排除的目录)
mount /dev/sda1 /mnt/sda1cd /mnt/sda1tar -zcvf linuxsystem.sda1.tar.gz *mv linuxsystem.sda1.tar.gz /mnt/usbtar -zcvf /mnt/usb/linuxsystem.sda2.tar.gz / --exclude=/tmp/* --exclude=/mnt/*
2.做一个USB linux 系统启动盘 启动盘制作资料:http://www.livecd.ethz.ch/usbdisk_sl4_sl5.html (网址为英文版,也可见附件中我的操作步骤)
3.写脚本在启动盘中自动执行,把做好的两个包考到/home/sluser/对应目录下(目录在脚本里面定义),用脚本格式化硬盘分区,解压 tar 包,建grub引导
启动时执行的脚本:
######################### CreatDisk.sh #########################echo -e "Please select No of PoweriBox:1\n(1) linuxsystem1;\n(2) linuxsystem2;\n(3) linuxsystem3;\n(4) linuxsystem4;\n" # 打印read -p "Select: " answer1 #等待并获取用户输入count1=0while [ $count1 -le 1 ]doif [ "$answer1"x = "1"x ] ; then #如果用户输入 1 count1=5 # 设置 count1 为 5 (为了跳出循环 ) folder="linuxsystem1" # 赋值 echo -e "linuxsystem1\n" # 打印elif [ "$answer1"x = "2"x ] ; then count1=5 folder="linuxsystem2" echo -e "linuxsystem2\n"elif [ "$answer1"x = "3"x ] ; then count1=5 folder="linuxsystem3" echo -e "linuxsystem3"elif [ "$answer1"x = "4"x ] ; then count1=5 folder="linuxsystem4" echo -e "linuxsystem4"else count1=5 folder="linuxsystem1" echo -e "linuxsystem1"fidone # 循环结束read -p "The usb system will format your hardware and install linuxsystem ! (yes/no) " answer #读取用户输入count=0while [ $count -le 1 ]do if [ "$answer"x = "yes"x ] ; then #如果输入 yes count=5 echo -e "\ninstall linuxsystem!" echo -n "Step 0: Fdisk and making filesystem ..." #打印# umount /dev/sda1 2>/dev/null 1>/dev/null# umount /dev/sda2 2>/dev/null 1>/dev/null #umount /dev/sda3 2>/dev/null 1>/dev/nulldevstr=`fdisk -l | awk 'NR==2{print $2}'` #fdisk 获取磁盘信息并通过管道交给 awk 处理以获取第2行第2列的值赋给 devstr (个人理解)if [ $devstr != '/dev/sda:' ]; then #比较字符echo -e "The hard disk is not sda, so poweroff!"poweroff #关机命令fi str=`fdisk -l | awk 'NR==2{print $3}'` #fdisk -l 的[2][3]的值 echo -e "It is $str G\n" #不解释 if [ $str == 160.0 ]; then fdisk /dev/sda < /usr/bin/fdisk_160.txt #执行fdisk 命令,并把fdisk_160.txt 内容作为参数(如输入 n (回车) 就相当手动输动了 n(回车) ,要回车就直接是一个回车的空行) elif [ $str == 250.0 ]; thenfdisk /dev/sda < /usr/bin/fdisk_250.txt elif [ $str == 320.0 ]; thenfdisk /dev/sda < /usr/bin/fdisk_320.txt elif [ $str == 500.1 ]; thenfdisk /dev/sda < /usr/bin/fdisk_500.txt elsefdisk /dev/sda < /usr/bin/fdisk_320.txt fi #fdisk /dev/sda < /usr/bin/fdisk.txt #2>/dev/null 1>/dev/null && \ mkfs.ext3 /dev/sda1 # 格式化上一步分好的sda1 #2>/dev/null 1>/dev/null && \ mkfs.ext3 /dev/sda2 #2>/dev/null 1>/dev/null && \ #mkfs.ext3 /dev/sda3 2>/dev/null 1>/dev/null && \ echo -e "\t\t[ OK ]" || echo -e "\t\t[ FAILED ]" echo -n "Step 1: Copying writable files to disk ..." ls /mnt/sda1 1>/dev/null 2>/dev/null || mkdir /mnt/sda1 #查看 ls /mnt/sda1 命令是否成功,如果不成功就新建 /mnt/sda1 , 1 >/dev/null 2>dev/null 是将1(标准输出)2(标准出错)的信息指向/dev/null而不现实出来. ls /mnt/sda2 1>/dev/null 2>/dev/null || mkdir /mnt/sda2 mount /dev/sda1 /mnt/sda1 && \ #挂载磁盘 mount /dev/sda2 /mnt/sda2 && \ #cp /home/sluser/PoweriBox2_2.2_sda1.tar.gz /mnt/sda1/ && \ #cp /home/sluser/PoweriBox2_2.2_sda2.tar.gz /mnt/sda2/ && \ #cd /home/sluser/ && tar zxf linuxsystem1_sda1.tar.gz -C /mnt/sda1/ && \ #cd /home/sluser/ && tar zxf linuxsystem2_sda2.tar.gz -C /mnt/sda2/ && \ cd /home/sluser/$folder && tar zxf linuxsystem*sda1.tar.gz -C /mnt/sda1/ && \ #进入指定文件夹,如果成功就解压 linuxsystem* 到/mnt/sda1/下 cd /home/sluser/$folder && tar zxf linuxsystem*sda2.tar.gz -C /mnt/sda2/ && \ echo -e "\n end \n" echo -e "\t[ OK ]" || echo -e "\t[ FAILED ]" umount /mnt/sda1 2>/dev/null && \ #卸载挂载 umount /mnt/sda2 2>/dev/null #echo -n "Step 2: Copying disk image to disk ..." #umount /mnt/disk 2> /dev/null #mount -t ext3 /dev/hda1 /mnt/disk && \ #cp ./boot/* /mnt/disk/ -a && \ #echo -e "\t\t[ OK ]" || echo -e "\t\t[ FAILED ]" #echo -n "Step 3: Liloing ..." #lilo -C ./lilo.conf 2>/dev/null 1>/dev/null && \ #echo -e "\t\t\t\t[ OK ]" || echo -e "\t\t\t\t[ FAILED ]" #umount /mnt/disk #echo echo "Disk created finished !" e2label /dev/sda1 /boot && \ #将/dev/hda1分区的label名设为/boot e2label /dev/sda2 / && \ #将/dev/hda2分区的label名设为/ echo "Install grub !" grub < /usr/bin/grub_install.txt 2 >/dev/null 1>/dev/null && \ # 执行grub 命令并以 /usr/bin/grub_install.txt 中的内容为参数自动执行 sleep 5 # 等5秒 answer="no" poweroffelif [ "$answer"x = "provideo"x ] ; then count=5elif [ "$answer"x = "no"x ] ; then count=5 # 为了跳出循环 echo -e "\nCancal installation!" poweroff else count=1 read -p "Please input yes or no ! (yes/no)" answer fi done
fdisk_320.txt 内容:
d1d2d3 np1 +100Mnp2 +38659np3 p a1 t382 w
fdisk_160.txt 内容:
d1d2d3 np1 +100Mnp2 +19250np3 p a1 t382 w
fdisk_500.txt 内容:
d1d2d3 np1 +100Mnp2 +60547np3 p a1 t382 w
grub_install.txt 内容:
root (hd0,0)setup (hd0)quit |
|