使用qemu-nbd修改qcow2格式的虚拟机镜像(三):mount挂载qcow2镜像中的lvm分区
1、qcow2镜像中的根分区是一个lvm分区可以看到第二个分区是一个lvm分区# fdisk -l /dev/nbd0Disk /dev/nbd0: 53.7 GB, 53687091200 bytes, 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes
·
1、qcow2镜像中的根分区是一个lvm分区
可以看到第二个分区是一个lvm分区
# fdisk -l /dev/nbd0
Disk /dev/nbd0: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x00072170
Device Boot Start End Blocks Id System
/dev/nbd0p1 * 2048 2099199 1048576 83 Linux
/dev/nbd0p2 2099200 104857599 51379200 8e Linux LVM
lvm分区是无法直接mount的
# mount /dev/nbd0p2 tmp/
mount: unknown filesystem type 'LVM2_member'
2、扫描出lvm分区
qcow2镜像映射到nbd设备后,是无法看到其中的pv、vg和lv设备的
下面命令看到的都是host上的设备
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 centos lvm2 a-- 100.00g 0
/dev/sda5 centos lvm2 a-- 736.35g 66.35g
/dev/sdb1 cinder-volumes lvm2 a-- <500.00g 24.76g
# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 5 0 wz--n- 836.35g 66.35g
cinder-volumes 1 1 0 wz--n- <500.00g 24.76g
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
host-docker centos -wi-ao---- 100.00g
host-swift centos -wi-ao---- 50.00g
host-work centos -wi-ao---- 500.00g
root centos -wi-ao---- 100.00g
samba-guest centos -wi-ao---- 20.00g
cinder-volumes-pool cinder-volumes twi-a-tz-- 475.00g 0.00 10.42
执行pvscan、vgscan和lvscan后可以看到lvm设备
# pvscan --cache
# pvs
PV VG Fmt Attr PSize PFree
/dev/nbd0p2 centos lvm2 a-- <49.00g 0
/dev/sda3 centos lvm2 a-- 100.00g 0
/dev/sda5 centos lvm2 a-- 736.35g 66.35g
/dev/sdb1 cinder-volumes lvm2 a-- <500.00g 24.76g
# vgscan
Reading volume groups from cache.
Found volume group "centos4vm" using metadata type lvm2
Found volume group "cinder-volumes" using metadata type lvm2
Found volume group "centos" using metadata type lvm2
# lvscan
inactive '/dev/centos4vm/swap' [5.00 GiB] inherit
inactive '/dev/centos4vm/root' [<44.00 GiB] inherit
ACTIVE '/dev/cinder-volumes/cinder-volumes-pool' [475.00 GiB] inherit
ACTIVE '/dev/centos/root' [100.00 GiB] inherit
ACTIVE '/dev/centos/host-docker' [100.00 GiB] inherit
ACTIVE '/dev/centos/host-work' [500.00 GiB] inherit
ACTIVE '/dev/centos/samba-guest' [20.00 GiB] inherit
ACTIVE '/dev/centos/host-swift' [50.00 GiB] inherit
3、激活lv设备
扫描出来的lv设备时inactive的
# lvscan
inactive '/dev/centos4vm/swap' [5.00 GiB] inherit
inactive '/dev/centos4vm/root' [<44.00 GiB] inherit
无法直接使用
# mount /dev/centos4vm/root tmp/
mount: special device /dev/centos4vm/root does not exist
使用lvchange命令激活后,lv设备可正常使用
# lvchange -ay /dev/centos4vm/root
# lvscan
inactive '/dev/centos4vm/swap' [5.00 GiB] inherit
ACTIVE '/dev/centos4vm/root' [<44.00 GiB] inherit
ACTIVE '/dev/cinder-volumes/cinder-volumes-pool' [475.00 GiB] inherit
ACTIVE '/dev/centos/root' [100.00 GiB] inherit
ACTIVE '/dev/centos/host-docker' [100.00 GiB] inherit
ACTIVE '/dev/centos/host-work' [500.00 GiB] inherit
ACTIVE '/dev/centos/samba-guest' [20.00 GiB] inherit
ACTIVE '/dev/centos/host-swift' [50.00 GiB] inherit
# lvchange -ay /dev/centos4vm/swap
# lvscan
ACTIVE '/dev/centos4vm/swap' [5.00 GiB] inherit
ACTIVE '/dev/centos4vm/root' [<44.00 GiB] inherit
ACTIVE '/dev/cinder-volumes/cinder-volumes-pool' [475.00 GiB] inherit
ACTIVE '/dev/centos/root' [100.00 GiB] inherit
ACTIVE '/dev/centos/host-docker' [100.00 GiB] inherit
ACTIVE '/dev/centos/host-work' [500.00 GiB] inherit
ACTIVE '/dev/centos/samba-guest' [20.00 GiB] inherit
ACTIVE '/dev/centos/host-swift' [50.00 GiB] inherit
# mount /dev/centos4vm/root tmp/
# ls tmp/
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
更多推荐
已为社区贡献14条内容
所有评论(0)