利用grub和grub2製作雙系統的啟動隨身碟 我的隨身碟插上後,fdisk -l查看隨身碟資訊得知是/dev/sdb www.2cto.com 先將隨身碟製作分區表。fdisk/dev/sdb 用p命令查看得知有一個fat32分區,將他去掉,用d命令,然後用n命令新增加一個主要磁碟分割,n後選擇p(primarypartition),然後Partition number (1-4): 1,再用n命令新增加第二個主要磁碟分割,然後用a命令,把第一個和第二個主要磁碟分割設定為可引導。最後用w命令寫入。 www.2cto.com 格式化分區為ext3,mkfs -t ext3/dev/sdb1mkfs -text3 /dev/sdb2 然後掛載系統mkdir/mnt/sdb1mount -text3 /dev/sdb1 /mnt/sdb1mkdir/mnt/sdb2mount -text3 /dev/sdb2 /mnt/sdb2 然後將bt5光碟片解開後,把casper和preseed檔案夾拷貝到第一個分區的根目錄下。將linux deepin的整個光碟片iso檔案放入第二個分區的根目錄下。 然後先安裝grub到/mnt/sdb1grub-install --root-directory=/mnt/sdb1 /dev/sdb 將/boot/grub/grub.conf拷貝到,u盤上對應的目錄下然後編輯grub.conf [html] timeout 20 default 0 title Windows 7 map (hd0) (hd1) map (hd1) (hd0) rootnoverify (hd1,0) makeactive chainloader +1 title backtrack 5 root (hd0,0) kernel/casper/vmlinuz root=/dev/sdb1 file=/preseed/custom.seed boot=casperlocale=zh_CN text-- initrd/casper/initrd.gz title linux deepin root (hd0,1) kernel/boot/grub/core.img savedefault boot 這個設定檔就是說明,隨身碟第一個分區用grub引導的bt5,隨身碟第二個分區由grub引導core.img然後引導交給core.img,這個core.img是grub2的img。此時第二個分區上還沒有core.img,這個會在後面建立,我們先這樣寫。 然後將grub安裝到MBR上,輸入grub命令[html] grub> root(hd1,0) Filesystem type is ext2fs, partition type 0x83 grub> setup (hd1) Checking if "/boot/grub/stage1"exists... yes Checking if "/boot/grub/stage2"exists... yes Checking if"/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5(hd1)"... 15 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd1)(hd1)1+15 p (hd1,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded Done. grub> quit 然後插著隨身碟重啟系統,就應該可以順利進入bt5系統了,bt5是基於ubuntu的,進入系統後,將grub2寫入第二個分區。grub-install --root-directory=/mnt/sdb2 /dev/sdb此時寫入的是grub2。然後編輯grub2的設定檔,grub.cfg,此檔案內容如下:[html] # # DO NOT EDIT THISFILE # # It isautomatically generated by /usr/sbin/grub-mkconfig using templates # from /etc/grub.dand settings from /etc/default/grub # ### BEGIN/etc/grub.d/00_header ### set timeout=10 ### END/etc/grub.d/00_header ### ### BEGIN/etc/grub.d/05_debian_theme ### setmenu_color_normal=white/black setmenu_color_highlight=black/light-gray ### END/etc/grub.d/05_debian_theme ### ### BEGIN/etc/grub.d/10_linux ### menuentry"linux deepin" { loopbackloop (hd0,2)/deepin_12.06_zh-hans_i386.iso linux(loop)/casper/vmlinuz boot=casperiso-scan/filename=/deepin_12.06_zh-hans_i386.iso locale=zh_CN.UTF-8 nopromptnoeject initrd(loop)/casper/initrd.lz } grub的設定檔裡分區是(hd0,0),而grub2的設定檔裡分區是(hd0,2),因為grub裡面分區從0開始,而grub2裡面分區是從1開始的。 www.2cto.com 此時grub2的MBR會覆蓋掉grub的MBR,所以我們需要重啟系統,進入一個正常的linux系統,然後再執行一遍安裝grub到MBR的命令,將grub的MBR覆蓋掉grub2的MBR。[html] grub> root(hd1,0) Filesystem type is ext2fs, partition type 0x83 grub> setup (hd1) Checking if "/boot/grub/stage1"exists... yes Checking if "/boot/grub/stage2"exists... yes Checking if"/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5(hd1)"... 15 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd1)(hd1)1+15 p (hd1,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded Done. grub> quit 此時再重啟,你就擁有了雙linux系統的隨身碟。