fdisk -lu CentOS-aarch64.img
mount -o loop,offset=2622488576 CentOS-aarch64.img ./tmpd/
mount -o loop,offset=105906176 CentOS-aarch64.img ./tmp1/
umount ./tmpd/
轉(zhuǎn)自:http://blog.sina.com.cn/s/blog_48e344da0101a3mj.html
文章摘自: http://www.linuxsir.org/bbs/thread334903.html 感謝原創(chuàng)作者。
1. 先查看第一個(gè)空閑loop設(shè)備
Shell代碼
sudo losetup -f
/dev/loop0
2. 使用上一步得到的設(shè)備名,第一次創(chuàng)建loop設(shè)備
Shell代碼
sudo losetup /dev/loop0 archlinux-2008.06-core-i686.img
3. 查看信息
Shell代碼
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)
我們可以看到,該鏡像只有一個(gè)分區(qū)(loop0p1),從第63扇區(qū)開始(Start列),每扇區(qū)512字節(jié)(Units = sectors of 1 * 512 = 512 bytes),我們算出offset,下面mout命令會(huì)用到:
Shell代碼
63*512=32256
4. mout
Shell代碼
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
事實(shí)上,fdisk可以直接查看img文件(雖然功能不全,下面會(huì)說到),mount可以自動(dòng)創(chuàng)建loop設(shè)備,所以上面步驟可以簡化為:
I. 查看信息
Shell代碼
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,原因是普通文件上沒有實(shí)現(xiàn)ioctl操作,我們可以看到0 cylinders,但這對我們不重要,關(guān)鍵是我們依然可以得到第一個(gè)分區(qū)(archlinux-2008.06-core-i686.img1)的偏移值
II. 直接mount
Shell代碼
sudo mount -o loop,offset=32256 archlinux-2008.06-core-i686.img /mnt/
ls /mnt/
addons archlive.sqfs boot lost+found