先前曾為此折騰過一段時(shí)間,成果如下:
首先建議對(duì)容量大於4GiB的U盤進(jìn)行格式化:FAT32是不支持大於4GiB的文件的,這會(huì)導(dǎo)致無法在U碟上放置諸如openSUSE-13.1-DVD-x86_64.iso這樣的大型鏡像,推薦的一種方法是將U盤分區(qū)格式化為ext2(不建議使用ext3/ext4的原因與不建議使用NTFS的原因一樣)。不過此亦有限制,若需要在Windowz系列上使用此U盤就會(huì)比較麻煩。故而建議在U盤上分兩個(gè)區(qū),一個(gè)FAT32區(qū)與一個(gè)ext2區(qū);請(qǐng)依情況權(quán)衡兩個(gè)分區(qū)的大小。筆者的U盤分區(qū)方案如下所示:
NAME FSTYPE SIZE LABELsdb 14.9G├─sdb1 vfat 720.9M VFATPOOL└─sdb2 ext2 14.2G 2014-01-12
一般在GNU/Linux環(huán)境下有數(shù)個(gè)分區(qū)工具可用,如gparted與fdisk等,本文以後者為例;本例中先將U盤分為兩個(gè)區(qū):
# lsblk -o NAME,FSTYPE,SIZE,LABEL# fdisk /dev/sdx
在插入U(xiǎn)盤後請(qǐng)先不要掛載:依前者輸出來選擇塊設(shè)備,請(qǐng)將「x」替換為U盤所對(duì)應(yīng)的塊設(shè)備的字母;關(guān)於如何使用fdisk,ArchWiki的Beginners' Guide是個(gè)不錯(cuò)的教程。
之後,將第一個(gè)分區(qū)格式化為FAT32:
# mkfs.vfat -n對(duì)應(yīng)卷標(biāo) /dev/sdx1
再將第二個(gè)分區(qū)格式化為ext2:
# mkfs.ext2 -b 4096 -m 0 -N512 -L對(duì)應(yīng)卷標(biāo) /dev/sdx2
為安裝grub,需要掛載U盤分區(qū)。本例中掛載第二個(gè)ext2分區(qū)到/tmp/mntp(假定/tmp掛載的是tmpfs):
$ mkdir /tmp/mntp# mount -o noatime /dev/sdx2 /tmp/mntp# rm -r /tmp/mntp/*# mkdir -p /tmp/mntp/data
安裝grub到U盤,另建一個(gè)目錄用於存放iso鏡像:
# grub-install --target=i386-pc --boot-directory=/tmp/mntp/boot /dev/sdx$ sudo chown -R $USER:storage /tmp/mntp$ mkdir /tmp/mntp/boot/iso
(注:包含chown那行用於修正文件所在組;乃亦可將文件權(quán)限更正為同組可讀寫,這樣方便在不同的機(jī)器上交換文件)
然後將鏡像拷貝進(jìn)去即可。之後需要配置grub.cfg以引導(dǎo)鏡像文件,在本例中g(shù)rub.cfg位於/tmp/mntp/boot/grub/grub.cfg。以筆者U盤上的grub.cfg為例:
set color_normal=light-gray/blackset color_highlight=black/light-grayexport color_normalexport color_highlight#設(shè)置色彩方案insmod acpi#使引導(dǎo)界面支持ACPIloadfont /boot/grub/fonts/unicode.pf2.gz#加載Unicode字體insmod all_videoinsmod gfxtermset gfxmode=autoterminal_input consoleterminal_output gfxterm#若可用,直接重設(shè)為最大可用解析度set drive_label=將紅字改為乃存放iso鏡像文件的那個(gè)分區(qū)的卷標(biāo) export drive_labelset default=0#默認(rèn)菜單項(xiàng)為首項(xiàng)set timeout=-1#無限等待##############menuentry "[loopback]archlinux-2014.05.01-dual" { set isofile="/boot/iso/archlinux-2014.05.01-dual.iso" loopback loop $isofile linux (loop)/arch/boot/x86_64/vmlinuz archisolabel=ARCH_201405 img_label=$drive_label img_loop=$isofile earlymodules=loop initrd (loop)/arch/boot/x86_64/archiso.img}#archlinux的官方鏡像比較特別……乃需要根據(jù)發(fā)佈年份月份來修改紅字部分menuentry "[loopback]archlinux-2014.05.02-x86_64.iso" { set isofile="/boot/iso/archlinux-2014.05.02-x86_64.iso" loopback loop $isofile linux (loop)/arch/boot/x86_64/vmlinuz archisolabel=ALIC_201405 img_label=$drive_label img_loop=$isofile earlymodules=loop initrd (loop)/arch/boot/x86_64/archiso.img}menuentry "[loopback]alde-light-201404" { set isofile="/boot/iso/alde-light-201404.iso" loopback loop $isofile linux (loop)/vmlinuz livemode root=/dev/disk/by-label/$drive_label iso=$isofile locale=zh_TW.UTF-8 initrd (loop)/initrd.img}#ALDE是archlinux吧吧友制作的livecd:alde-201404-releasedmenuentry '[loopback]sage-0.2-dual'{ set isofile="/boot/iso/sage-0.2-dual.iso" loopback loop $isofile linux (loop)/boot/kernel-64 isoboot label=$drive_label root=iso=sage-0.2-dual.iso depth user=root vga=791 quiet initrd (loop)/boot/initramfs-64}#sage是gentoo吧吧友製作的livecd,小巧而實(shí)用,0.2版在此:tieba.baidu.com/p/2271618062#menuentry "[loopback]archlinux-2013.10-1-archboot" {# set isofile="/boot/iso/archlinux-2013.10-1-archboot.iso"# loopback loop $isofile# linux (loop)/boot/vmlinuz_x86_64 iso_loop_dev=/dev/disk/by-label/$drive_label iso_loop_path=$isofile# initrd (loop)/boot/initramfs_x86_64.img#}#menuentry "[loopback]archlinux-2013.11.01-dual" {# set isofile="/boot/iso/archlinux-2013.11.01-dual.iso"# loopback loop $isofile# linux (loop)/arch/boot/x86_64/vmlinuz archisolabel=ARCH_201311 img_dev=/dev/disk/by-label/$drive_label img_loop=$isofile earlymodules=loop# initrd (loop)/arch/boot/x86_64/archiso.img#}#menuentry "[loopback]kali-linux-1.0.6-amd64" {# set isofile="/boot/iso/kali-linux-1.0.6-amd64.iso"# loopback loop $isofile# linux (loop)/live/vmlinuz findiso=$isofile boot=live noconfig=sudo username=root hostname=kali noswap locale=zh_TW.UTF-8# initrd (loop)/live/initrd.img#}#menuentry "[loopback]archbang-2013.09.01-x86_64" {# set isofile="/boot/iso/archbang-2013.09.01-x86_64.iso"# loopback loop $isofile# linux (loop)/arch/boot/x86_64/vmlinuz archisolabel=ARCHBANG img_dev=/dev/disk/by-label/$drive_label img_loop=$isofile earlymodules=loop locale=zh_TW.UTF-8# initrd (loop)/arch/boot/x86_64/archiso.img#}#menuentry "[loopback]gparted-live-0.17.0-1-amd64" {# set isofile="/boot/iso/gparted-live-0.17.0-1-amd64.iso"# loopback loop $isofile# linux (loop)/live/vmlinuz boot=live config union=aufs noswap noprompt vga=788 ip=frommedia toram=filesystem.squashfs findiso=$isofile locale=zh_TW.UTF-8# initrd (loop)/live/initrd.img#}#menuentry "[loopback]CDlinux-0.9.7.1" {# set isofile="/boot/iso/CDlinux-0.9.7.1.iso"# loopback loop $isofile# linux (loop)/CDlinux/bzImage CDL_LANG=zh_TW.UTF-8 CDL_AMOUNT=no CDL_DEV=LABEL=$drive_label CDL_LOOP=yes CDL_DIR=/boot/iso CDL_IMG=CDlinux-0.9.7.1.iso CDL_WAIT=0# initrd (loop)/CDlinux/initrd#}#menuentry "[loopback]openSUSE-13.1-DVD-x86_64" {# set isofile="/boot/iso/openSUSE-13.1-DVD-x86_64.iso"# loopback loop $isofile# linux (loop)/boot/x86_64/loader/linux install=hd:$isofile# initrd (loop)/boot/x86_64/loader/initrd#}#menuentry "[loopback]debian-live-7.2-amd64-lxde-desktop" {# set isofile="/boot/iso/debian-live-7.2-amd64-lxde-desktop.iso"# loopback loop $isofile# linux (loop)/live/vmlinuz boot=live findiso=$isofile config splash# initrd (loop)/live/initrd.img#}#menuentry "[loopback]debian-live-7.4-amd64-xfce-desktop" {# set isofile="/boot/iso/debian-live-7.4-amd64-xfce-desktop.iso"# loopback loop $isofile# linux (loop)/live/vmlinuz boot=live findiso=$isofile config splash# initrd (loop)/live/initrd.img#}#menuentry "[loopback]pclinuxos64-kde-2013.10" {# set isofile="/boot/iso/pclinuxos64-kde-2013.10.iso"# loopback loop $isofile# set root=(loop)# linux /isolinux/vmlinuz bootfromiso=$isofile livecd=livecd root=/dev/rd/3 acpi=on vga=788 keyb=us splash=verbose vmalloc=256M# initrd (loop)/isolinux/initrd.gz#}#menuentry "[loopback]Sabayon_Linux_13.11_amd64_KDE" {# set isofile="/boot/iso/Sabayon_Linux_13.11_amd64_KDE.iso"# loopback loop $isofile# set root=(loop)# linux /boot/sabayon root=/dev/ram0 aufs cdroot locale=zh_TW loop=/livecd.squashfs looptype=squashfs isoboot=$isofile# initrd /boot/sabayon.igz#}#menuentry "[loopback]deepin_2013_zh-hant_amd64" {# set isofile="/boot/iso/deepin_2013_zh-hant_amd64.iso"# loopback loop $isofile# linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile locale=zh_TW.UTF-8# initrd (loop)/casper/initrd.lz#}#menuentry "[loopback]ubuntu-14.04-desktop-amd64" {# set isofile="/boot/iso/ubuntu-14.04-desktop-amd64.iso"# loopback loop $isofile# linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile locale=zh_CN.UTF-8# initrd (loop)/casper/initrd.lz#}#menuentry "[chainload]DEEPIN.PE" {# search --label --set=rootVFATPOOL # ntldr /NTLDR#}#關(guān)於VFATPOOL代表什麼,請(qǐng)參考本文前端部分;引導(dǎo)Windows PE的方法本文暫不明細(xì)提及;#menuentry "[memdisk]DEEPIN.DOSTOOL" {# linux16 "/boot/grub/memdisk.gz" floopy# search --label --set=rootVFATPOOL # initrd16 "/EZBOOT/DOSTOOL.IMG"#}#文件memdisk來自syslinux,請(qǐng)參見其wiki條目;submenu "grub2 other functions" { menuentry "List devices/partitions" { ls -l sleep --interruptible 9999 } menuentry "Enable serial terminal" { serial terminal_input --append serial terminal_output --append serial }}menuentry "Boot HDD" { chainloader +1}menuentry "Reboot"{ reboot}menuentry "Halt now"{ halt}
以上就是筆者的grub.cfg,它包含Arch?Debian-livecd?ArchBang等官方鏡像的引導(dǎo)菜單項(xiàng);另外筆者的iso鏡像文件都放在U盤中的「/boot/iso」中;請(qǐng)諸位按需修改,移除或添加注釋符號(hào)(#)以方便的屏蔽或激活某個(gè)菜單項(xiàng)。另:現(xiàn)在大多數(shù)發(fā)行版的光碟鏡像都能以類似上面的方法引導(dǎo)(而另一小部分:如CentOS 6.5 LiveDVD,是由於某物(dracut)版本過舊所致,乃需要將其鏡像解壓後纔能引導(dǎo))。
聯(lián)系客服