通过loop方式挂载raw格式镜像
本文档介绍 通过loop方式挂载raw格式镜像 的相关内容。
[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方式挂载raw格式镜像 1、挂载镜像 1、losetup -f #查看哪个loop设备是空闲的 /dev/loop0 #loop0这个设备是空闲的 2、losetup /dev/loop0 /var/lib/libvirt/images/ubuntu.img 3、kpartx -av /dev/loop0 # 输出结果如下 add map loop0p1 (253:0): 0 18380800 linear /dev/loop0 2048 add map loop0p2 (253:1): 0 2 linear /dev/loop0 18384894 add map loop0p5 (253:2): 0 2093056 linear /dev/loop0 18384896 4、mkdir /vmdisk 5、mount /dev/mapper/loop0p1 /vmdisk/ #把第一个分区挂载到/vmdisk 这样就可以查看和编辑镜像中的内容了 2、卸载镜像 1、umount /vmdisk 2、kpartx -dv /dev/loop0 # 输出如下 del devmap : loop0p5 del devmap : loop0p2 del devmap : loop0p1 3、losetup -d /dev/loop0 注意:使用这个方式只能挂载raw格式镜像,不能处理qcow2格式镜像 如要处理qcow2格式镜像,需要使用qemu-ndb或者guestfs 本文由作者按照 CC BY 4.0 进行授权