歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 利用grub和grub2制作雙系統的啟動U盤

利用grub和grub2制作雙系統的啟動U盤

日期:2017/3/1 17:08:24   编辑:關於Linux
利用grub和grub2制作雙系統的啟動U盤 我的U盤插上後, fdisk -l查看U盤信息得知是/dev/sdb www.2cto.com 先將U盤制作分區表。 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/sdb1 mkfs -text3 /dev/sdb2 然後掛載系統 mkdir/mnt/sdb1 mount -text3 /dev/sdb1 /mnt/sdb1 mkdir/mnt/sdb2 mount -text3 /dev/sdb2 /mnt/sdb2 然後將bt5光盤解開後,把casper和preseed文件夾拷貝到第一個分區的根目錄下。 將linux deepin的整個光盤iso文件放入第二個分區的根目錄下。 然後先安裝grub到/mnt/sdb1 grub-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 這個配置文件就是說明,U盤第一個分區用grub引導的bt5,U盤第二個分區由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 然後插著U盤重啟系統,就應該可以順利進入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系統的U盤。
Copyright © Linux教程網 All Rights Reserved