[原创]grub实现多系统启动和隐藏分区备份恢复功能。

启动讨论 grub/grub2/syslinux/grub4dos/Lilo
回复
minibird
帖子: 18
注册时间: 2007-01-26 18:49

[原创]grub实现多系统启动和隐藏分区备份恢复功能。

#1

帖子 minibird » 2007-03-05 21:48

作者:minibirdregister#gmail.com欢迎交流。
用ubuntu一个多月了,在这里得到很多知识,也贡献一点心得,与大家分享。
使用linux之前,我一直使用ibm的bmgr工具来自动修改mbr,实现隐藏分区备份恢复功能。
grub不但可以引导各种系统,还可以隐藏分区,激活分区。可以用来实现隐藏分区备份功能。
本文主要实现功能如下:
1. 多系统引导。
2.独立的隐藏分区,利用ghost,可以实现对立于各系统、每个分区的备份恢复,不怕乱装乱搞,把系统弄崩溃了。
一、划分分区
使用一张可以启动dos系统,能够启动pq的光盘。网上有很多这样的维护工具光盘。
我利用pq分区如下。你可以根据自己的实际情况调整。

Device Boot Start End Blocks Id System
/dev/sda1 * 1 542 4097488+ 7 HPFS/NTFS
/dev/sda2 543 1220 5125680 1c Hidden W95 FAT32 (LBA)
/dev/sda3 1221 1290 529200 83 Linux
/dev/sda4 1291 10337 68395320 f W95 Ext'd (LBA)
/dev/sda5 1291 2645 10243768+ 7 HPFS/NTFS
/dev/sda6 2646 3999 10236208+ 83 Linux
/dev/sda7 4000 10257 47310448+ b W95 FAT32
/dev/sda8 10258 10337 604768+ 82 Linux swap / Solaris
下面说说我分区的思路。
由于只能划分3个主分区,而操作系统启动必须在主分区上(不是绝对的,linux也可以在拓展分区启动),因此sda1,2,3刚好分别给windowsxp/dos/linux。
dos只有系统文件,主要用于备份各操作系统数据,我给了5G,在sda2。
windows在sda1,我安装的是deepin 精简版本。各种应用软件一般不装在C盘,装在D盘,也就是sda5。另外,我喜欢绿色软件,这样更方便。
linux 的/boot在sda3,sda6是根分区。没有把/home单独分配分区,现在觉得不方便,建议大家还是把/home放在单独的分区上。
sda7在linux下我挂载在/share位置,在windows下是e盘,存放各类数据,可以在linux下和windows下访问。
sda8是swap分区。
最后,强调一下,你也可以不使用pq,直接在安装过程中利用各系统的安装盘自行分区。

二、安装顺序
(1)windows
安装windows后,再安装dos可能导致后面的sda5,7的盘符不是D,E的顺序,不怕,可以在windows中重新分配盘符。
安装完widnows后,应该进行优化,以便使用ghost备份时,尽量少占空间。主要优化内容有:修改系统环境变量将temp/tmp等路径,虚拟页面文件,ie的临时文件家,“我的文档”的路径等等,都放在D盘。以后安装程序也尽量安装在D盘。喜欢在桌面放很多文件的,也可以把桌面的路径也放到D盘。
(2)dos
sda2使用dos下的工具foramt格式化成fat32格式,加 /s 参数可以写入系统文件,能够启动。再拷贝一个ghost8.3的文件,就可以镜像各分区了。
只要你会用ghost,那么可以随时对各系统进行备份,自由自在,比什么一键恢复功能好多了。
(3)ubuntu
最后安装ubuntu。
使用pq分配的ext分区,可能ubuntu无法安装。需要使用ubuntu安装时自带的图形化分区工具,删除pq分配好的ext分区,再重新分配。但这又很可能导致分区前后有少量闲置空间,看着很讨厌。也许可以分好以后再用pq调整一下,但我没这么尝试过。
另外ubuntu安装时自带的图形化分区工具重新删除pq分配好的分区再划分时,可能导致设备号次序混乱。解决方法:分好区并应用后,不要继续安装,重新启动一次再安装。
安装时,/boot挂载在sda3,grub的配置文件也在这里。
安装完ubuntu后,可以启动ubuntu了,虽然此时无法进入windows或dos,不要着急,我们可以进入ubuntu,配置grub了。
三、配置grub
下面是我的grub配置文件,位置在/boot/gurb/menu.lst。
我不详细介绍了,主要的注意事项见注释。
# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default saved
#注释:你上次启动了哪个系统,如果这个系统配置项中有savedefault参数,那么再次启动的时候,这个系统就是默认启动项。省得每次都得手动选择启动项,或者经常修改menu.lst
## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 3
#注释:延迟3秒,如果无反应,就加载默认启动项。
## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
hiddenmenu
#注释:隐藏grub菜单,可以按ESC键来呼出grub菜单,选择启动项。

# Pretty colours
#color cyan/blue white/blue
color gray/black
#注释:配置grub菜单的颜色。
## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret
#注释:可以设置密码,密码还可以使用md5方式加密。我没设置。
#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=c141cae8-9998-414a-ba5f-e3cba302076f ro
# kopt_2_6=root=/dev/sda6 ro

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,2)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash locale=zh_CN

## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all

## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## ## End Default Options ##
##注释:下面是5个启动项,每个启动项以title开始,title就是grub启动菜单中显示的启动项。
title Ubuntu, kernel 2.6.17-11-generic
root (hd0,2)
kernel /vmlinuz-2.6.17-11-generic root=/dev/sda6 ro quiet splash locale=zh_CN vga=791
initrd /initrd.img-2.6.17-11-generic
savedefault
#注释:看到这个savedefault了吗?如果我这次启动了ubuntu,那么下次重新启动,默认继续启动ubuntu,而不是其他系统。注意,要想使这个参数起作用,要放在这个位置。对linux来说,在boot前,initrd后。
boot

##下面这个是ubuntu的恢复模式。默认的,我没动它。和检测内存的memtest以及用来恢复的dos一样,没必要使用savedefault了吧?
title Ubuntu, kernel 2.6.17-11-generic (recovery mode)
root (hd0,2)
kernel /vmlinuz-2.6.17-11-generic root=/dev/sda6 ro single
initrd /initrd.img-2.6.17-11-generic
boot
##注释:检测内存的,默认的,没动它。
title Ubuntu, memtest86+
root (hd0,2)
kernel /memtest86+.bin
boot

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
##注释:dos在sda2,对gurb来说,就是(hd0,1)。首先要unhide,然后再makeactive,这样dos就可以启动了。这是关键。
title DOS 7.1
unhide (hd0,1)
rootnoverify (hd0,1)
makeactive
chainloader +1

# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
##注释:windows在sda1,对grub来说,就是(hd0,0)。为了防止在windows下看到dos分区,首先要把dos分区hide了。然后再把windows分区给makeactive了。记得在makeactive之前和rootnoverify之后加上savedefault。这样经常进windows时,不用每次都手动选择了。
title Microsoft Windows XP Professional
hide (hd0,1)
rootnoverify (hd0,0)
savedefault
makeactive
chainloader +1
nox
帖子: 44
注册时间: 2007-03-08 16:03

#2

帖子 nox » 2007-04-26 23:01

好帖,帮了我的大忙了,呵呵
swordfish
帖子: 125
注册时间: 2007-04-01 8:36

#3

帖子 swordfish » 2007-04-27 12:21

grub 里居然有‘unhide’命令,我晕,用了那么久没发现。
以前每次加载img文件,恢复完后再手动隐藏,
后来发现ghost支持hiddenFAT/NTFS的读取。 :lol:
wzhy
帖子: 165
注册时间: 2007-04-24 21:43
联系:

#4

帖子 wzhy » 2007-04-30 12:48

很好的帖子!我用的是联想的机器,它也有那个隐藏分区,现在决定全面使用Linux,您的这篇文章真是太有用了!
谢谢!!!
头像
Fly1945
帖子: 35
注册时间: 2006-09-19 16:38

#5

帖子 Fly1945 » 2007-05-08 4:47

不加精没道理阿!!
野天
帖子: 3
注册时间: 2007-07-04 13:12

#6

帖子 野天 » 2007-07-04 13:59

对于初学者来说,有点不太容易操作,不过还是谢谢作者。

期待更加通俗易懂的操作指南
ttyever
帖子: 139
注册时间: 2007-10-06 0:56

Re: [原创]grub实现多系统启动和隐藏分区备份恢复功能。

#7

帖子 ttyever » 2008-11-07 20:22

我按楼主的方式作了,虽然可以在桌面上隐藏,但是在文件系统哪里仍然会有这样一个盘符,还算不上隐藏啊,有什么办法真正隐藏,就像备份分区一样???
billbear
帖子: 3681
注册时间: 2008-05-03 23:42

Re: [原创]grub实现多系统启动和隐藏分区备份恢复功能。

#8

帖子 billbear » 2008-11-08 1:05

我不会为 dos 浪费一个主分区。 dos 使用一个软盘镜像文件用 grub 加载就行了。弄一个隐藏的 fat/ntfs 逻辑分区存 ghost 备份镜像文件,不用 unhide,ghost 可以读写隐藏的 fat/ntfs。
头像
南风夜雨
帖子: 840
注册时间: 2007-01-04 9:49
系统: ubuntu-gnome

Re: [原创]grub实现多系统启动和隐藏分区备份恢复功能。

#9

帖子 南风夜雨 » 2009-04-30 11:16

受教了,我的9.04是从测试睡到一路升级上来的,grub菜单是一直显示的。昨天帮一同事安装上ubuntu,但要按esc才能进入菜单。我这人很菜,还以为出问题了呢。今天搜索到你这里,才发出grub中居然可以设置隐藏,于是把自己的设成隐藏了,把同事的隐藏选项注释掉了。
真是太感谢了。
asd5381
帖子: 26
注册时间: 2009-03-11 20:11

Re: [原创]grub实现多系统启动和隐藏分区备份恢复功能。

#10

帖子 asd5381 » 2009-04-30 15:11

菜鸟受教了,可是如果再详细点就更好了
asd5381
帖子: 26
注册时间: 2009-03-11 20:11

Re: [原创]grub实现多系统启动和隐藏分区备份恢复功能。

#11

帖子 asd5381 » 2009-04-30 15:15

菜鸟受教了,可是如果再详细点就更好了
回复