KVM 虚拟机 qcow2 格式镜像文件挂载

安装前请先编译 nbd 模块 https://blog.csdn.net/mshxuyi/article/details/100610074

1、加载 nbd 模块 

modprobe nbd max_part=8

2、将镜像文件映射到 网络块设备 

qemu-nbd -c /dev/nbd0 /home/image/kvm110.qcow2

3、挂载

mount /dev/nbd0 /mnt/kvm110

#如果分区是LVM,将提示下面信息,无法挂载成功
mount: unknown filesystem type 'LVM2_member

LVM分区挂载方法

4、挂载

#格式化显示逻辑卷的概要信息,看详细可用 lvdisplay
lvs

#结果
LV   VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
root vg110       -wi-ao----  <8.00g                                                    
swap vg110       -wi-a-----   1.00g                                                    
home centos_0830 -wi-ao----  18.08g                                                    
root centos_0830 -wi-ao---- <37.04g                                                    
swap centos_0830 -wi-ao----  <3.88g 

#注意:这里的VG名称一定不能相同,虚拟机如果是默认安装,VG名称可能出现都是centos,这时要修改一下VG
本例已事先到110虚拟机上面改好vg,链接https://blog.csdn.net/mshxuyi/article/details/100740563

#激活vg110卷组状态
vgchange -ay vg110

#结果
2 logical volume(s) in volume group "vg110" now active

#扫描所有逻辑卷
lvscan

#结果
ACTIVE            '/dev/centos_0830/swap' [<3.88 GiB] inherit
ACTIVE            '/dev/centos_0830/home' [18.08 GiB] inherit
ACTIVE            '/dev/centos_0830/root' [<37.04 GiB] inherit
ACTIVE            '/dev/vg110/swap' [1.00 GiB] inherit
ACTIVE            '/dev/vg110/root' [<8.00 GiB] inherit

#挂载
mount /dev/vg110/root /mnt/kvm110

#查看
ls /mnt/kvm110

#挂载成功
lrwxrwxrwx.  1 root root    7 Sep  4 06:07 bin -> usr/bin
drwxr-xr-x.  2 root root    6 Sep  4 06:06 boot
drwxr-xr-x.  2 root root    6 Sep  4 06:06 dev
drwxr-xr-x. 74 root root 8192 Sep 11 14:43 etc
drwxr-xr-x.  2 root root    6 Apr 11  2018 home
lrwxrwxrwx.  1 root root    7 Sep  4 06:07 lib -> usr/lib
lrwxrwxrwx.  1 root root    9 Sep  4 06:07 lib64 -> usr/lib64
drwxr-xr-x.  2 root root    6 Apr 11  2018 media
drwxr-xr-x.  2 root root    6 Apr 11  2018 mnt
drwxr-xr-x.  2 root root    6 Apr 11  2018 opt
drwxr-xr-x.  2 root root    6 Sep  4 06:06 proc
dr-xr-x---.  3 root root  220 Sep  6 07:52 root
drwxr-xr-x.  2 root root    6 Sep  4 06:06 run
lrwxrwxrwx.  1 root root    8 Sep  4 06:07 sbin -> usr/sbin
drwxr-xr-x.  2 root root    6 Apr 11  2018 srv
drwxr-xr-x.  2 root root    6 Sep  4 06:06 sys
drwxrwxrwt.  8 root root  211 Sep 11 14:43 tmp
drwxr-xr-x. 13 root root  155 Sep  4 06:07 usr
drwxr-xr-x. 19 root root  267 Sep  4 06:14 var

5、取消挂载

#取消挂载
umount /mnt/kvm110/
 
#激活取消
vgchange -an vg110
 
#结果
0 logical volume(s) in volume group "vg110" now active
 
#取消关联loop设备
losetup -d /dev/loop0

#关闭网络块设备
qemu-nbd -d /dev/nbd0

 

你可能感兴趣的:(KVM)