虚拟机的镜像可以直接通过loop的方式来进行挂载,这种方式你必须先计算出镜像中每个分区的偏移量(fdisk -lu可查看),然后通过loop的方式的挂载,加上偏移量
详细命令如下
[root@centos images]# cd /var/lib/libvirt/images/
[root@centos images]# fdisk -lu ubuntu.raw
You must set cylinders.
You can do this from the extra functions menu.
Disk ubuntu.raw: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ccae5
Device Boot Start End Blocks Id System
ubuntu.raw1 * 2048 38862847 19430400 83 Linux
Partition 1 has different physical/logical endings:
phys=(1023, 254, 63) logical=(2419, 25, 38)
ubuntu.raw2 38864894 40957951 1046529 5 Extended
Partition 2 has different physical/logical beginnings (non-Linux?):
phys=(1023, 254, 63) logical=(2419, 58, 6)
Partition 2 has different physical/logical endings:
phys=(1023, 254, 63) logical=(2549, 131, 14)
ubuntu.raw5 38864896 40957951 1046528 82 Linux swap / Solaris
[root@centos images]# echo $((2048*512))
1048576
[root@centos images]# mount -o loop,offset=1048576 ubuntu.raw /image/
[root@centos images]# umount /image/
PS:这个方式的镜像必须是Raw格式的。
当然你也可以通过kpartx的方式进行挂载,详见 通过kpartx方式挂载raw格式镜像