一、挂载iso格式镜像
1、将镜像文件拷贝到linux系统上。
2、执行命令:mount -t iso9660 -o loop /root/xxx.iso /mnt
[root@h07d07184.sqa.eu95 /root]#mount -t iso9660 -o loop alinux-test.iso /mnt
mount: /root/alinux-test.iso is already mounted
3、查看/mnt文件夹,即可查看到镜像的文件。
[root@h07d07184.sqa.eu95 /root]#ls /mnt
apptmp_run.over boot dev home lib64 media opt root run srv tmp varbin data etc lib lost+found mnt proc rr_moved sbin sys usr
4、卸载:umount /mnt
二、挂载qcow2格式镜像
1. 首先检查当前系统的kernel对NBD模块的支持(NBD:network block device),加载nbd这个module
[root@jay-linux kvm_demo]# grep NBD /boot/config-3.5.0
CONFIG_BLK_DEV_NBD=m
[root@jay-linux kvm_demo]# modinfo nbd
filename: /lib/modules/3.5.0/kernel/drivers/block/nbd.ko
license: GPL
description: Network Block Device
srcversion: 56F31584CC2EB73E6F1DA69
depends:
intree: Y
vermagic: 3.5.0 SMP mod_unload modversions
parm: nbds_max:number of network block devices to initialize (default: 16) (int)
parm: max_part:number of partitions per device (default: 0) (int)
parm: debugflags:flags for controlling debug output (int)
[root@jay-linux kvm_demo]# modprobe nbd max_part=16
[root@jay-linux kvm_demo]# lsmod | grep nbd
nbd 7593 0
2. 将qcow2镜像映射为网络块设备(nbd),命令如下:
[root@h07d07184.sqa.eu95 /mnt]#qemu-nbd -c /dev/nbd0 /root/Alinux-2.1.0-OUT-1220.qcow2
[root@h07d07184.sqa.eu95 /mnt]# ll /dev/nbd0*
brw-rw---- 1 root disk 43, 0 Jan 10 10:17 /dev/nbd0
brw-rw---- 1 root disk 43, 1 Jan 10 10:17 /dev/nbd0p1
3. 像普通block设备那样使用刚才映射好的网络块设备的分区即可,命令行如下:
[root@h07d07184.sqa.eu95 /mnt]#mount /dev/nbd0p1 /mnt/[root@h07d07184.sqa.eu95 /mnt]#ls /mnt/
apptmp_run.over boot dev home lib64 media opt root sbin sys usrbin data etc lib lost+found mnt proc run srv tmp var
4. 使用完这个qcow2镜像后,卸载已挂载的nbd设备,解除qcow2镜像与nbd设备的关联。
[root@jay-linux kvm_demo]# umount /mnt/
[root@jay-linux kvm_demo]# qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected
三、挂载vhd格式镜像(与qcow2方法相似)
[root@h07d07184.sqa.eu95 /root]#ll /dev/nbd0*
brw-rw---- 1 root disk 43, 0 Jan 10 10:31 /dev/nbd0
[root@h07d07184.sqa.eu95 /root]#qemu-nbd -c /dev/nbd0 aliyun-test.vhd[root@h07d07184.sqa.eu95 /root]#ll /dev/nbd0*
brw-rw---- 1 root disk 43, 0 Jan 10 10:32 /dev/nbd0
brw-rw---- 1 root disk 43, 1 Jan 10 10:32 /dev/nbd0p1
[root@h07d07184.sqa.eu95 /root]#mount /dev/nbd0p1 /mnt[root@h07d07184.sqa.eu95 /root]#ls /mnt/
bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@h07d07184.sqa.eu95 /root]#umount /mnt/
[root@h07d07184.sqa.eu95 /root]#qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected
[root@h07d07184.sqa.eu95 /root]#