非lvm分区挂载方法:
mount -o loop xxx.img /mnt/xxx
系统提示:
“mount: you must specify the filesystem type”
执行:fdisk -ul xxx.img,和显示一大堆信息,如:
Disk 3059.img: 4294 MB, 4294967296 bytes 255 heads, 63 sectors /track , 522 cylinders, total 8388608 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 identifier: 0x000bdbdc Device Boot Start End Blocks Id System 3059.img1 * 63 7903979 3951958+ 83 Linux 3059.img2 7903980 8385929 240975 5 Extended 3059.img5 7904043 8385929 240943+ 82 Linux swap / Solaris |
看到这行,发现linux的文件系统是从第63块开始的,所以挂载的时候应该从这个地方开始挂载
3059.img1 * 63 7903979 3951958+ 83 Linux
由这条信息可以的出,扇区大小为512
Units = sectors of 1 * 512 = 512 bytes
所以我们需要从512*63出开始挂载
最后执行:
mount -o loop,offset=32256 xxx.img /mnt/xxx……
lvm分区挂载方法:
[root@jay-linux image]# fdisk -lu rhel6u2.img You must set cylinders. You can do this from the extra functions menu. Disk rhel6u2.img: 0 MB, 0 bytes 255 heads, 63 sectors/track, 0 cylinders, total 0 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 identifier: 0x00048b34 Device Boot Start End Blocks Id System rhel6u2.img1 * 2048 1026047 512000 83 Linux Partition 1 does not end on cylinder boundary. rhel6u2.img2 1026048 104857599 51915776 8e Linux LVM Partition 2 has different physical/logical endings: phys=(1023, 254, 63) logical=(6527, 21, 22) [root@jay-linux image]# echo $((1026048*512)) 525336576 [root@jay-linux image]# losetup /dev/loop0 rhel6u2.img -o 525336576 [root@jay-linux image]# pvscan PV /dev/loop0 VG VolGroup lvm2 [49.51 GiB / 0 free] Total: 1 [49.51 GiB] / in use: 1 [49.51 GiB] / in no VG: 0 [0 ] [root@jay-linux image]# vgchange -ay VolGroup 2 logical volume(s) in volume group "VolGroup" now active [root@jay-linux image]# lvs LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert lv_root VolGroup -wi-a--- 45.57g lv_swap VolGroup -wi-a--- 3.94g [root@jay-linux image]# mount /dev/VolGroup/lv_root /media/ [root@jay-linux image]# ls /media/ bin cgroup etc lib lost+found misc net proc sbin srv tmp var boot dev home lib64 media mnt opt root selinux sys usr (使用完后的卸载操作,如下) [root@jay-linux image]# umount /media/ [root@jay-linux image]# vgchange -an VolGroup 0 logical volume(s) in volume group "VolGroup" now active [root@jay-linux image]# losetup -d /dev/loop0
总结:
参考了如下博客:
https://my.oschina.net/toyandong/blog/65002
http://blog.csdn.net/lucien_cc/article/details/11158055