准备在 Debian 系统上安装虚拟化支持,由于我的 Debian 使用了双硬盘组成的 fake raid 0,它使用 /dev/mapper 这样的设备名,因此要用到 kpartx 支持才能正确识别。而恰恰是 Debian 生成的 initrd 映像文件中不包含 kpartx,于是要修改 initrd 文件才能让系统正确启动。对于 Debian 的虚拟化来说,有几种方式,kvm xen openvz vserver,每种都要修改 initrd。
解压缩
1
2
3
4
5
6
7
|
debian:~
# cd /boot
debian:
/boot
# mkdir initrd-openvz
debian:
/boot/initrd-openvz
# cp /boot/initrd.img-2.6.32-5-openvz-amd64 initrd.img.gz
debian:
/boot/initrd-openvz
# gunzip initrd.img.gz
debian:
/boot/initrd-openvz
# cpio -ivmd < initrd.img
debian:
/boot/initrd-openvz
# ls
bin conf etc init initrd.img lib lib64 sbin scripts
|
比较
1
2
3
4
5
6
|
debian:
/boot/initrd
# find ./ |grep kpartx
.
/sbin/kpartx
.
/lib/udev/kpartx_id
.
/lib/udev/rules
.d
/60-kpartx
.rules
debian:
/boot/initrd
# find . |xargs grep 'kpartx'
.
/scripts/local-top/dmraid
:
/sbin/kpartx
-a
/dev/mapper/isw_
*
|
添加支持
1
2
3
|
cp
/boot/initrd/sbin/kpartx
sbin/
cp
/boot/initrd/lib/udev/kpartx_id
lib
/udev/
cp
/boot/initrd/lib/udev/rules
.d
/60-kpartx
.rules lib
/udev/rules
.d/
|
接下来编辑 ./scripts/local-top/dmraid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
debian:
/boot/initrd-vserver
# vim scripts/local-top/dmraid
#!/bin/sh
# local-top script for dmraid.
PREREQS=
""
prereqs()
{
echo
$PREREQS
}
case
$1
in
# get pre-requisites
prereqs)
prereqs
exit
0
;;
esac
/sbin/udevadm
settle --timeout=30
modprobe -Q dm-mod
modprobe -Q dm-mirror
modprobe -Q dm_raid
modprobe -Q dm_multipath
modprobe -Q raid456
# Activate any dmraid arrays that were not identified by udev and vol_id.
if
devices=$(dmraid -r -c);
then
for
dev
in
$devices;
do
dmraid-activate $dev
done
fi
/sbin/kpartx
-a
/dev/mapper/isw_
*
|
打包
1
|
find
. | cpio -o -H newc |
gzip
>
/boot/initrd
.img-2.6.32-5-openvz-amd64
|
编辑 /boot/grub/grub.cfg,去掉最顶部自动生成的 xen 项,保留 /etc/grub.d/20_linux_xen 生成的 xen 项。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
menuentry
'Debian GNU/Linux, with Xen 4.0-amd64 and Linux 2.6.32-5-xen-amd64'
--class debian --class gnu-linux --class gnu --class os --class xen {
insmod part_gpt
insmod ext2
set
root=
'(hd2,gpt2)'
search --no-floppy --fs-uuid --
set
=root d2e90c41-5e4b-4857-8108-738bee9dad5f
echo
'Loading Xen 4.0-amd64 ...'
multiboot
/boot/xen-4
.0-amd64.gz placeholder
echo
'Loading Linux 2.6.32-5-xen-amd64 ...'
module
/boot/vmlinuz-2
.6.32-5-xen-amd64 placeholder root=UUID=d2e90c41-5e4b-4857-8108-738bee9dad5f ro
echo
'Loading initial ramdisk ...'
module
/boot/initrd
.img-2.6.32-5-xen-amd64
}
menuentry
'Debian GNU/Linux, with Xen 4.0-amd64 and Linux 2.6.32-5-xen-amd64 (recovery mode)'
--class debian --class gnu-linux --class gnu --class os --class xen {
insmod part_gpt
insmod ext2
set
root=
'(hd2,gpt2)'
search --no-floppy --fs-uuid --
set
=root d2e90c41-5e4b-4857-8108-738bee9dad5f
echo
'Loading Xen 4.0-amd64 ...'
multiboot
/boot/xen-4
.0-amd64.gz placeholder
echo
'Loading Linux 2.6.32-5-xen-amd64 ...'
module
/boot/vmlinuz-2
.6.32-5-xen-amd64 placeholder root=UUID=d2e90c41-5e4b-4857-8108-738bee9dad5f ro single
echo
'Loading initial ramdisk ...'
module
/boot/initrd
.img-2.6.32-5-xen-amd64
}
|
xen 的其它操作请参考 http://wiki.xen.org/wiki/Xen_Beginners_Guide http://www.virtuatopia.com/index.php/Installing_and_Running_Windows_7_as... 需要注意的是,桥接后,网卡 IP 就会失效,这时可以使用网桥的 IP 做为管理 IP。