直接挂载虚拟机内为LVM分区的镜像

来源:互联网 发布:雷洋死亡真相 知乎 编辑:程序博客网 时间:2024/06/06 13:04

如果虚拟机内部做了LVM,则直接挂载LVM分区有点麻烦

详细命令如下

[root@centos images]# fdisk -lu lvm-ubuntu.img You must set cylinders.You can do this from the extra functions menu.Disk lvm-ubuntu.img: 0 MB, 0 bytes255 heads, 63 sectors/track, 0 cylinders, total 0 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000c848f         Device Boot      Start         End      Blocks   Id  Systemlvm-ubuntu.img1   *        2048      499711      248832   83  LinuxPartition 1 does not end on cylinder boundary.lvm-ubuntu.img2          501758    20969471    10233857    5  ExtendedPartition 2 has different physical/logical endings:     phys=(1023, 254, 63) logical=(1305, 73, 48)lvm-ubuntu.img5          501760    20969471    10233856   8e  Linux LVM


通过上面的命令可以看到这个虚拟机镜像内做了LVM


通过下面命令可以挂载LVM分区


[root@centos images]# echo $((501760*512))256901120[root@centos images]# losetup -f/dev/loop0[root@centos images]# losetup /dev/loop0 lvm-ubuntu.img -o 256901120[root@centos images]# pvscan   PV /dev/loop0   VG ubuntu-vg   lvm2 [9.76 GiB / 0    free]  Total: 1 [9.76 GiB] / in use: 1 [9.76 GiB] / in no VG: 0 [0   ][root@centos images]# vgchange -ay  2 logical volume(s) in volume group "ubuntu-vg" now active[root@centos images]# mount /dev/mapper/ubuntu--vg-root /image/

卸载分区的命令如下:

[root@centos images]# umount /image/[root@centos images]# vgchange -an ubuntu-vg  0 logical volume(s) in volume group "ubuntu-vg" now active[root@centos images]# losetup -d /dev/loop0




1 0
原创粉丝点击