利用grub和grub2制作双系统的启动U盘

93 篇文章 1 订阅

我的U盘插上后,

fdisk -l查看U盘信息得知是/dev/sdb


先将U盘制作分区表。

fdisk/dev/sdb

 

用p命令查看得知有一个fat32分区,

将他去掉,用d命令,

然后用n命令新增加一个主分区,

n后选择p(primarypartition),

然后Partition number (1-4): 1,

再用n命令新增加第二个主分区,

然后用a命令,把第一个和第二个主分区设置为可引导。

最后用w命令写入。

 

格式化分区为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

 

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命令

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,此文件内容如下:

#

# 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开始的。


此时grub2的MBR会覆盖掉grub的MBR,所以我们需要重启系统,进入一个正常的linux系统,

然后再执行一遍安装grub到MBR的命令,将grub的MBR覆盖掉grub2的MBR。

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盘。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值