1. 先查看第一個空閒loop設備
- sudo losetup -f
/dev/loop0
linux
2. 使用上一步獲得的設備名,第一次建立loop設備 shell
- sudo losetup /dev/loop0 archlinux-2008.06-core-i686.img
3. 查看信息
- sudo fdisk -lu /dev/loop0
- Disk /dev/loop0: 322 MB, 322469376 bytes
- 53 heads, 12 sectors/track, 990 cylinders, total 629823 sectors
- Units = sectors of 1 * 512 = 512 bytes
- Disk identifier: 0x00000000
-
- Device Boot Start End Blocks Id System
- /dev/loop0p1 * 63 629822 314880 83 Linux
- Partition 1 has different physical/logical beginnings (non-Linux?):
- phys=(0, 1, 1) logical=(0, 5, 4)
- Partition 1 has different physical/logical endings:
- phys=(39, 52, 12) logical=(990, 15, 3)
咱們能夠看到,該鏡像只有一個分區(loop0p1),從第63扇區開始(Start列),每扇區512字節(Units = sectors of 1 * 512 = 512 bytes),咱們算出offset,下面mout命令會用到:
4. mount
- sudo losetup -o 32256 /dev/loop1 archlinux-2008.06-core-i686.img
- sudo mount -o loop /dev/loop1 /mnt/
- ls /mnt/
- addons archlive.sqfs boot lost+found
事實上,fdisk能夠直接查看img文件(雖然功能不全,下面會說到),mount能夠自動建立loop設備,因此上面步驟能夠簡化爲:
I. 查看信息
- sudo fdisk -lu archlinux-2008.06-core-i686.img
- You must set cylinders.
- You can do this from the extra functions menu.
-
- Disk archlinux-2008.06-core-i686.img: 0 MB, 0 bytes
- 53 heads, 12 sectors/track, 0 cylinders, total 0 sectors
- Units = sectors of 1 * 512 = 512 bytes
- Disk identifier: 0x00000000
-
- Device Boot Start End Blocks Id System
- archlinux-2008.06-core-i686.img1 * 63 629822 314880 83 Linux
- Partition 1 has different physical/logical beginnings (non-Linux?):
- phys=(0, 1, 1) logical=(0, 5, 4)
- Partition 1 has different physical/logical endings:
- phys=(39, 52, 12) logical=(990, 15, 3)
第一行抱怨不能獲得cylinders,緣由是普通文件上沒有實現ioctl操做,咱們能夠看到0 cylinders,但這對咱們不重要,關鍵是咱們依然能夠獲得第一個分區(archlinux-2008.06-core-i686.img1)的偏移值
II. 直接mount
- sudo mount -o loop,offset=32256 archlinux-2008.06-core-i686.img /mnt/
- ls /mnt/
- addons archlive.sqfs boot lost+found
再來一個複雜點的: ide
$ /sbin/fdisk -lu disk.img
You must set cylinders.
You can do this from the extra functions menu.
Disk disk.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
disk.imgp1 * 63 96389 48163+ 83 Linux
disk.imgp2 96390 2056319 979965 82 Linux swap / Solaris
disk.imgp3 2056320 78140159 38041920 5 Extended
disk.imgp5 2056383 3052349 497983+ 83 Linux
disk.imgp6 3052413 10859939 3903763+ 83 Linux
disk.imgp7 10860003 68372639 28756318+ 83 Linux
disk.imgp8 68372703 76180229 3903763+ 83 Linux
disk.imgp9 76180293 78140159 979933+ 83 Linux
計算disk.imgp7的偏移,也就是文件系統的起始位置:
10860003 * 512 = 5560321536
losetup後就能夠mount了: oop
# losetup /dev/loop0 disk.img -o $((10860003 * 512))
# file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext3 filesystem data
# mount /dev/loop0 /mnt
[...]
# umount /mnt
# losetup -d /dev/loop0
若是啓動區後真的是一個文件系統的話,能夠直接mount: this
# mount -o loop,offset=$((10860003 * 512)) disk.img /mnt
[...]
# umount /mnt