分享

How to mount *.img file on ubuntu system?

 智慧书仓 2017-01-22
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/

转自:http://blog.sina.com.cn/s/blog_48e344da0101a3mj.html

文章摘自: http://www./bbs/thread334903.html 感谢原创作者。

1. 先查看第一个空闲loop设备 

Shell代码 
  1. sudo losetup -f  
  2. /dev/loop0  


2. 使用上一步得到的设备名,第一次创建loop设备 
Shell代码 
  1. sudo losetup /dev/loop0 archlinux-2008.06-core-i686.img  


3. 查看信息 
Shell代码 
  1. sudo fdisk -lu /dev/loop0  
  2.   
  3. Disk /dev/loop0: 322 MB, 322469376 bytes  
  4. 53 heads, 12 sectors/track, 990 cylinders, total 629823 sectors  
  5. Units sectors of 1 512 512 bytes  
  6. Disk identifier: 0x00000000  
  7.   
  8.       Device Boot      Start         End      Blocks   Id  System  
  9. /dev/loop0p1            63      629822      314880   83  Linux  
  10. Partition 1 has different physical/logical beginnings (non-Linux?):  
  11.      phys=(011logical=(054 
  12. Partition 1 has different physical/logical endings:  
  13.      phys=(395212logical=(990153 

我们可以看到,该镜像只有一个分区(loop0p1),从第63扇区开始(Start列),每扇区512字节(Units = sectors of 1 * 512 = 512 bytes),我们算出offset,下面mout命令会用到: 
Shell代码 
  1. 63*512=32256  


4. mout 
Shell代码 
  1. sudo losetup -o 32256 /dev/loop1 archlinux-2008.06-core-i686.img  
  2. sudo mount -o loop /dev/loop1 /mnt/  
  3. ls /mnt/  
  4. addons  archlive.sqfs  boot  lost+found  


事实上,fdisk可以直接查看img文件(虽然功能不全,下面会说到),mount可以自动创建loop设备,所以上面步骤可以简化为: 
I. 查看信息 
Shell代码 
  1. sudo fdisk -lu archlinux-2008.06-core-i686.img  
  2. You must set cylinders.  
  3. You can do this from the extra functions menu.  
  4.   
  5. Disk archlinux-2008.06-core-i686.img: 0 MB, 0 bytes  
  6. 53 heads, 12 sectors/track, 0 cylinders, total 0 sectors  
  7. Units sectors of 1 512 512 bytes  
  8. Disk identifier: 0x00000000  
  9.   
  10.                           Device Boot      Start         End      Blocks   Id  System  
  11. archlinux-2008.06-core-i686.img1            63      629822      314880   83  Linux  
  12. Partition 1 has different physical/logical beginnings (non-Linux?):  
  13.      phys=(011logical=(054 
  14. Partition 1 has different physical/logical endings:  
  15.      phys=(395212logical=(990153 

第一行抱怨不能得到cylinders,原因是普通文件上没有实现ioctl操作,我们可以看到0 cylinders,但这对我们不重要,关键是我们依然可以得到第一个分区(archlinux-2008.06-core-i686.img1)的偏移值 

II. 直接mount 
Shell代码 
  1. sudo mount -o loop,offset=32256 archlinux-2008.06-core-i686.img /mnt/  
  2. ls /mnt/  
  3. addons  archlive.sqfs  boot  lost+found  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多