Showing posts with label multiple boot. Show all posts
Showing posts with label multiple boot. Show all posts

Wednesday, October 26, 2011

利用grub2直读iso镜像 制作多启动u盘

U盘现在容量越来越大,4-8G的U盘只装一个启动系统太浪费了,这几天看了看利用grub2制作多启动U盘的内容,有点心得,这里大概说说.

原理:
利用grub2可以启动iso文件的方法,可以制作大量的多启动U盘,但是很大部分还不支持,比如常用的debian,centos,等等就不支持,不过我常用的systermrescuecd,archboot,freebsd都支持这种启动方式.


操作过程:

首先把U盘分区,我实验用的U盘有2G容量,为了通用性,我就格式化为fat32格式,这样windows和linux,以及bsd下都可以复制iso,修改grub.cfg文件.

1)分区就使用fdisk

首先你要把u盘的mbr清空,避免以前做的mbr影响将要安装的grub2启动

(X代表你的U盘所在的盘符,比如我的u盘就是/dev/sdb)

$ sudo dd if=/dev/zero of=/dev/sdX bs=512  count=1

$ sudo fdisk -l
$ sudo fdisk /dev/sdX

d删除已有分区,p显示分区情况,m察看fdisk帮助,n新建分区,p为主分区,t转换分区格式,b转换为win95vfat格式,l显示可以转换的分区格式,a激活启动分区,w保存分区情况,q不保存关闭fdisk

2) 安装grub2

这里要注意,安装的grub2最好是32位的,比如systermrescuecd和ubuntu livecd都选用32位的,可以保持兼容性;我这里就走了很多弯路,使用机器arch本身的grub2,导致u盘无法启动的情况,应为我的arch是64位的.

首先挂载你的u盘,如果你使用gnome3,或者其他自动挂载的桌面,你就需要找到你的u盘挂载的地方

$ sudo mount -t vfat /dev/sdb1 /mnt

$ sudo grub-install --no-floppy --force --root-directory=/mnt /dev/sdb1


3) 编辑grub.cfg文件,并添加iso文件

$ sudo mkdir /mnt/iso

把你需要启动的iso镜像放到/mnt/iso目录中就可以了

$ sudo vim /mnt/boot/grub/grub.cfg

下面是我的grub.cfg配置文件,你可以自己根据自己的情况修改
~/grub.cfg.html
set color_normal='light-blue/black'
set color_highlight='light-cyan/blue'

menuentry "System Rescue CD" {
 loopback loop /iso/systemrescuecd-x86-2.3.1.iso
 linux (loop)/isolinux/rescuecd isoloop=/iso/systemrescuecd-x86-2.3.1.iso setkmap=us docache dostartx
 initrd (loop)/isolinux/initram.igz
}

menuentry "Parted Magic Disk Utilities" {
 loopback loop /iso/pmagic-6.2.iso
 linux (loop)/pmagic/bzImage iso_filename=/iso/pmagic-6.2.iso edd=off noapic load_ramdisk=1 prompt_ramdisk=0 rwnomce sleep=10 loglevel=0
 initrd (loop)/pmagic/initramfs
}

menuentry "Ubuntu 11.04" {
 loopback loop /iso/ubuntu-11.04-desktop-i386.iso
 linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/iso/ubuntu-11.04-desktop-i386.iso noeject noprompt --
 initrd (loop)/casper/initrd.lz
}

menuentry "Arch Linux i686" {
 loopback loop /iso/archlinux-2011.10-1-archboot.iso
 linux (loop)/boot/vmlinuz rootdelay=10
 initrd (loop)/boot/initrd.img
}

menuentry "Arch Linux x86_64" {
 loopback loop /iso/archlinux-2011.10-1-archboot.iso
 linux (loop)/boot/vm64 rootdelay=10
 initrd (loop)/boot/initrd64.img
}

menuentry "FreeBSD 8.2 i386" {
 set isofile=/iso/FreeBSD-8.2-RELEASE-i386-disc1.iso
 loopback loop $isofile
 kfreebsd (loop)/boot/kernel/kernel iso-scan/filename=$isofile noeject noprompt splash --
 kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}

menuentry "FreeBSD 8.2 x86_64" {
 set isofile=/iso/FreeBSD-8.2-RELEASE-amd64-disc1.iso
 loopback loop $isofile
 kfreebsd (loop)/boot/kernel/kernel iso-scan/filename=$isofile noeject noprompt splash --
 kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}


参考 :  Restore_Usbstick
       Boot Multiple ISO from USB via Grub2 using Linux
       MultiBootUSB shell
       Installing Grub (2) on a USB flash drive
       Install GRUB2 on USB from Ubuntu Linux

qemu直接使用u盘启动

一直使用virtualbox做虚拟机,今天想做个usb的多启动光盘,但是vbox使用u盘启动的方法太麻烦了.


搜索发现qemu可以支持直接u盘启动,方法也很简单.

首先 , 确保安装qemu  

$ sudo pacman -S qemu


然后,找到你的u盘,可以使用fdisk,df,来察看,比如我的u盘就是/dev/sdb

$ sudo fdisk -l

最后,就可以使用qemu来启动你的u盘了

$ sudo qemu -m 128 -hda /dev/sdb

上面参数的含义是使用128M内存,以hda方式,把/dev/sdb作为启动盘引导


当然,你也可以使用物理硬盘来引导,比如

$ sudo qemu -m 128 -hda /dev/sda

就可以把你本身的物理硬盘系统启动起来




恢复u盘的默认状态

Restore Usbstick

Take care about which device actually is your USB stick. The next command will render all data on /dev/sdX inaccessible.
  • First, wipe the bootsector of the USB stick:
dd if=/dev/zero of=/dev/sdX bs=512 count=1
  • Then, create a new FAT32 partition on the stick and write a FAT32 filesystem on it (vfat or type b in fdisk terminology):
fdisk /dev/sdX 
n
p
1


t
b
w


mkdosfs -F32 /dev/sdX1 
or (mkfs.vfat -F 32 -n mutilboot /dev/sdX1)

Tuesday, October 25, 2011

Boot Multiple ISO from USB via Grub2 using Linux

Boot ISO Files directly from USB using Grub2 from Linux. Here is one way to create a Multiboot USB Flash Drive from a running Ubuntu (I used the Live CD). You may eventually need a large Flash Drive or USB Hard Drive in order to include every bootable ISO entry. I will add more Bootable ISO files to the grub.cfg file as I find time to test them. Contact me to submit working Bootable Linux ISO grub.cfg entries for inclusion.

I. Format your USB Flash Drive to use a Single Partition:
  1. Open a terminal and type sudo su
  2. Type fdisk -l (and note which device is your USB Drive)
  3. Type fdisk /dev/sdx (replacing x with your actual usb device)
  4. Type d (to delete the existing partition)
  5. Type n (to create a new partition)
  6. Type p (for primary partition)
  7. Type 1 (to create the first partition)
  8. Press Enter (to use the first cylinder)
  9. Press Enter again (to use the default value as the last cylinder)
  10. Type a (for active)
  11. Type 1 (to mark the first partition active "bootable")
  12. Type w (to write the changes and close fdisk)
II. Create a Fat32 Filesystem on the USB Flash Drive:
  1. Type umount /dev/sdx1 (to unmount the mounted partition)
  2. Type mkfs.vfat -F 32 -n MULTIBOOT /dev/sdx1 (to format the partition as fat32)
III. Install Grub2 on the USB Flash Drive:
  1. Type mkdir /media/MULTIBOOT (to create a directory for the mountpoint)
  2. Type mount /dev/sdx1 /media/MULTIBOOT (to mount the USB)
  3. Type grub-install --force --no-floppy --root-directory=/media/MULTIBOOT /dev/sdx (to install Grub2)
  4. Type cd /media/MULTIBOOT/boot/grub (to change directory)
  5. Type wget pendrivelinux.com/downloads/multibootlinux/grub.cfg (to get the grub.cfg file)
IV. Test to make sure your USB Device Boots into Grub2:
Reboot your Computer, and enter your BIOS or Boot Menu. Set the Boot Order to boot from the USB Device. Save your changes and Reboot. If all goes well, you should be presented with a Grub2 Boot Menu.
V. Adding the Bootable ISO files:
  1. Type cd /media/MULTIBOOT (assuming USB is still mounted here)
  2. Follow the instructions for the ISO Distro you would like to add below. Simply click to expand the instructions.
 http://www.pendrivelinux.com/boot-multiple-iso-from-usb-via-grub2-using-linux/
 http://www.pendrivelinux.com/install-grub2-on-usb-from-ubuntu-linux/
http://inportb.com/2010/07/19/install-windows-7-from-usb-pen-drive-using-grub2-and-grub4dos/