1.查看一下磁盘文件的结构:# fdisk -l /data/vm/123/123.img
last_lba(): I don't know how to handle files with mode 81ed
You must set cylinders.
You can do this from the extra functions menu.
Disk /data/vm/123/123.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/data/vm/123/123.img1 * 1 13 104391 83 Linux
/data/vm/123/123.img2 14 6527 52323705 8e Linux LVM
Partition 2 has different physical/logical endings:
phys=(1023, 254, 63) logical=(6526, 254, 63)
我们看到有两个分区可供使用,一个是普通的linux分区,一个是lvm分区
2.查看回环设备占用情况
# losetup -a
/dev/loop0: [fd00]:36274183 (/data/vm/abc/abc.img)
loop0被占用着,那就用loop1,将虚拟磁盘文件映射到loop1上:
# losetup /dev/loop1 /data/vm/123/123.img
# losetup -a
/dev/loop0: [fd00]:36274183 (/data/vm/abc/abc.img)
/dev/loop1: [fd00]:36274181 (/data/vm/123/123.img)
3.根据回环设备创建物理设备节点:
# kpartx -a /dev/loop1
# kpartx -l /dev/loop1
loop1p1 : 0 208782 /dev/loop1 63
loop1p2 : 0 104647410 /dev/loop1 208845
# ll /dev/mapper/
total 0
crw------- 1 root root 10, 59 Dec 26 01:14 control
brw-r----- 1 root disk 253, 2 Dec 27 16:18 loop1p1
brw-r----- 1 root disk 253, 3 Dec 27 16:18 loop1p2
brw-rw---- 1 root disk 253, 0 Dec 25 17:14 VolGroup00-LogVol00
brw-rw---- 1 root disk 253, 1 Dec 26 01:14 VolGroup00-LogVol01
我们看到/dev/mapper下多了两个块设备,对应前面看到的linux分区和lvm分区
4.对于linux分区,可以直接进行挂载:
# mount /dev/mapper/loop1p1 /mnt/
# cd /mnt/
/mnt# ls
config-2.6.18-274.el5xen grub initrd-2.6.18-274.el5xen.img lost+found message symvers-2.6.18-274.el5xen.gz System.map-2.6.18-274.el5xen vmlinuz-2.6.18-274.el5xen xen.gz-2.6.18-274.el5 xen-syms-2.6.18-274.el5
5.对于lvm分区,可以使用如下方式:
扫描vg
# vgscan
扫描lv
# lvscan
激活vg分区
# vgchange -a y
查看lv
# lvdisplay
然后就可以直接挂载lv了
6.卸载虚拟磁盘文件:
umount后,执行:
kpartx -d /dev/loop1
losetup d /dev/loop1
就可以了
阅读(2818) | 评论(0) | 转发(0) |