最新消息:

mount xen虚拟机的镜像文件

未分类 admin 3096浏览 0评论

昨天,在给一台xen虚拟机重装系统的时候,由于ks文件中的配置出错,结果导致xen虚拟机启动失败。可实际上,虚拟机文件还是完好的,只需要修改虚拟机中的ks文件即可。没有办法,只得尝试mount虚拟机的镜像文件。结果,提示如下错误

[Copy to clipboard]View Code TXT
# mount test.img /mnt
mount: test.img is not a block device (maybe try `-o loop'?)

尝试使用-o loop来mount,提示如下

[Copy to clipboard]View Code TXT
# mount -o loop test.img /mnt
mount: you must specify the filesystem type

使用file命令查看这个img文件,结果如下

[Copy to clipboard]View Code TXT
# file test.img

test.img: x86 boot sector;
partition 1: ID=0x83, active, starthead 1, startsector 63, 208782 sectors;
partition 2: ID=0x82, starthead 0, startsector 208845, 4096575 sectors;
partition 3: ID=0x83, starthead 0, startsector 4305420, 205407090 sectors, code offset 0x48

在网上找了一下相关资料,要想mount xen的镜像文件,只需要一下几个步骤

1,查看镜像文件分区

[Copy to clipboard]View Code TXT
# fdisk -ul test.img

last_lba(): I don't know how to handle files with mode 81ed
You must set cylinders.
You can do this from the extra functions menu.

Disk test.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
test.img1   *          63      208844      104391   83  Linux
test.img2          208845     4305419     2048287+  82  Linux swap / Solaris
test.img3         4305420   209712509   102703545   83  Linux
Partition 3 has different physical/logical endings:

     phys=(1023, 254, 63) logical=(13053, 254, 63)

由此能看到这个虚拟机磁盘被分了三个区,分别是/boot,/,swap,如果需要修改/boot分区内容,就只需要挂载test.img1分区就行了

2,挂载需要的分区

此处以挂载/boot分区举例

# mount –o loop,offset=$((63*512)) /PATH/TO/test.img /mnt,offset中的63就是分区的Start标记的数字。

[Copy to clipboard]View Code TXT
# ll /mnt/

总计 7498
-rw-r--r-- 1 root root   67250 07-22 18:02 config-2.6.18-274.el5xen
drwxr-xr-x 2 root root    1024 10-31 16:04 grub
-rw------- 1 root root 2510056 10-31 16:03 initrd-2.6.18-274.el5xen.img
drwx------ 2 root root   12288 10-31 15:58 lost+found
-rw-r--r-- 1 root root   80032 2009-03-13 message
-rw-r--r-- 1 root root  115821 07-22 18:02 symvers-2.6.18-274.el5xen.gz
-rw-r--r-- 1 root root 1230739 07-22 18:02 System.map-2.6.18-274.el5xen
-rw-r--r-- 1 root root 2196594 07-22 18:02 vmlinuz-2.6.18-274.el5xen
-rw-r--r-- 1 root root  424545 07-22 16:35 xen.gz-2.6.18-274.el5
-rwxr-xr-x 1 root root  986192 07-22 18:55 xen-syms-2.6.18-274.el5

当修改完之后,只需要umount目录,在启动虚拟机就行了,这样,如果clone了很多虚拟机,修改clone出来的虚拟机ip就不用非得启动虚拟机了,可以修改完之后再启动虚拟机。

注:此方法对于分区是lvm的不适用。

转载请注明:爱开源 » mount xen虚拟机的镜像文件

您必须 登录 才能发表评论!