Centos Debian共用Boot分区共用Swap分区的双linux系统安装
转载请注明出处.谢谢.
个人喜欢Debian,但是由于Redhat的推广做的比较好,所以很多服务器都采用了Redhat发行版,抛开个人对Redhat的惩戒,使用和研究Centos成了有实际意义的事情,所以有了将Debian与Centos安装在同一台计算机的打算.
使用光盘引导安装:
Centos5.2 安装DVD
Debian CD1
首先安装Centos
Centos root分区安装于/dev/hda6
Centos boot分区安装与/dev/hda3
单独划分/boot的好处在于可以与debian共用一个/boot
由于debian支持root分区与boot分区在同一个分区.所以采用了让centos单独划分boot分区的步骤.
具体分区如下:
Device Boot Start End Blocks Id System /dev/hda1 * 1 2550 20480008+ 7 HPFS/NTFS # windows /dev/hda2 2550 5100 20480040 c W95 FAT32 (LBA) #fat32 d:\ /dev/hda3 5101 5112 96390 83 Linux # boot /dev/hda4 5113 9729 37086052+ 5 Extended /dev/hda5 5113 5177 522081 82 Linux swap / Solaris #swap /dev/hda6 5178 7726 20474811 83 Linux #centos / /dev/hda7 7727 9729 16089066 83 Linux #debian /
其中/dev/hda5 swap为centos与debian共用交换分区
Centos安装完毕,重新启动计算机.
此时放入debian CD.安装debian.分区划分选择/dev/hda7为root/
swap为/dev/hda5.
安装Grub至/dev/hda1上
安装完毕后重新引导计算机.
启动后发现debian与原有windows系统还在.但是Grub中已经没有Centos的引导信息了.
用Debian启动.
进入shell:
执行:
mkdir /mnt/centos_boot
mount /dev/hda3 centos_boot
将centos Boot分区加载到/mnt/centos_boot目录中.
mkdir /root/back_boot
cp /mnt/centos_boot /root/back_boot –Rf
备份centos_boot
vim /etc/fstab
改为:
ThinkPad:# cat /etc/fstab # /etc/fstab: static file system information. # # #
增加/dev/hda3 /boot ext3 defaults 0 2
cat /root/back_boot/grub/menu.lst
#boot=/dev/hda default=0 timeout=5 splashimage=(hd0,2)/grub/splash.xpm.gz hiddenmenu
title Cent OS (2.6.18-92.el5) root (hd0,2) kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.18-92.el5.img
-—————————————————————————
cp /boot /mnt/centos_boot –Rf
将debian /boot下的所有文件复制到/mnt/centos_boot下.并且覆盖原有文件.
此时/mnt/centos_boot下存在.Centos的内核文件.
大致如下:
config-2.6.18-92.el5 symvers-2.6.18-92.el5.gz vmlinuz-2.6.18-92.el5 initrd-2.6.18-92.el5.img System.map-2.6.18-92.el5
将cat /root/back_boot/grub/menu.lst中的
title Cent OS (2.6.18-92.el5) root (hd0,2) kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.18-92.el5.img
引导信息,加入/mnt/centos_boot/grub/menu.lst中.
此时注意.一定要放在debian的menu.lst的
### BEGIN AUTOMAGIC KERNELS LIST
之上.否则在apt-get升级内核时将覆盖原有centos的信息.
并且修改debian的引导信息:
title Debian GNU/Linux, kernel 2.6.26-1-686 root (hd0,6) kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/hda7 ro quiet initrd /boot/initrd.img-2.6.26-1-686
为:
title Debian GNU/Linux, kernel 2.6.26-1-686 root (hd0,2) kernel /vmlinuz-2.6.26-1-686 root=/dev/hda7 ro quiet initrd /initrd.img-2.6.26-1-686
这是由于Grub的书写要求所致.由于改变了boot的分区位置所以要做上述改动.
书写要求:
1)在menu.lst中 ,通过 root (hd[0-n],y)来指定/boot 所在的分区;
2)在menu.lst中,kernel 命令行的写法;
kernel 一行,是通指定内核及Linux的/分区所在位置;
Debian的boot为:
title Debian GNU/Linux, kernel 2.6.26-1-686 root (hd0,6) kernel /boot/vmlinuz-2.6.26-1-686 root=/dev/hda7 ro quiet initrd /boot/initrd.img-2.6.26-1-686
但是已经让debian使用Centos Boot分区.所以改为:
title Debian GNU/Linux, kernel 2.6.26-1-686 root (hd0,2) kernel /vmlinuz-2.6.26-1-686 root=/dev/hda7 ro quiet initrd /initrd.img-2.6.26-1-686
在这里以kernel 起始,指定Linux的内核的文件所处的绝对路径;
因为内核是处在/boot目录中的,如果/boot是独立的一个分区则需要把boot省略
我们这里的修改就是省略/boot.并且制定boot分区的位置为Centos的boot分区.即:
root (hd0,2)
也就是
/dev/hda3
此时可以重新引导系统,在引导过程中Grub同时存在Centos Debian windows.
并且apt-get升级内核时可以自动将升级的信息写入现有grub.完成Centos Debian无缝兼容.
apt-get升级后的grub.conf内容为:
ThinkPad:/boot/grub# cat menu.lst
# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,2) # kernel /vmlinuz-version ro root=/dev/hda6 # initrd /initrd-version.img #boot=/dev/hda default=0 timeout=5 splashimage=(hd0,2)/grub/splash.xpm.gz hiddenmenu
title Cent OS (2.6.18-92.el5) root (hd0,2) kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.18-92.el5.img
# This is a divider, added to separate the menu items below from the Debian # ones. title Microsoft Windows XP Professional: root (hd0,0) savedefault chainloader +1
### BEGIN AUTOMAGIC KERNELS LIST
title Debian GNU/Linux, kernel 2.6.26-1-686 root (hd0,2) kernel /vmlinuz-2.6.26-1-686 root=UUID=76c51794-99e7-4021-ab88-5b9a23f97379 ro initrd /initrd.img-2.6.26-1-686
title Debian GNU/Linux, kernel 2.6.26-1-686 (single-user mode) root (hd0,2) kernel /vmlinuz-2.6.26-1-686 root=UUID=76c51794-99e7-4021-ab88-5b9a23f97379 ro single initrd /initrd.img-2.6.26-1-686
title Debian GNU/Linux, kernel 2.6.18-92.el5 root (hd0,2) kernel /vmlinuz-2.6.18-92.el5 root=UUID=76c51794-99e7-4021-ab88-5b9a23f97379 ro
title Debian GNU/Linux, kernel 2.6.18-92.el5 (single-user mode) root (hd0,2) kernel /vmlinuz-2.6.18-92.el5 root=UUID=76c51794-99e7-4021-ab88-5b9a23f97379 ro single
### END DEBIAN AUTOMAGIC KERNELS LIST ThinkPad:/boot/grub#
BTW:上述过程也可以在Centos下完成.由于我的debian采用了reiserfs分区默认Centos不支持reiserfs 分区.所以在Debian下完成.
全文完.本文写的非常浅薄.希望大家能够看得明白. 如果有问题可以联系我.
gtalk:gugong.j@gmail.com
oicq:199659