使用qemu-nbd修改qcow2格式的虚拟机镜像(三):mount挂载qcow2镜像中的lvm分区

6 篇文章 0 订阅
3 篇文章 0 订阅

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
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值