LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 4435|回复: 7

·[教程]挂载archlinux的img文件

[复制链接]
发表于 2008-8-8 19:56:20 | 显示全部楼层 |阅读模式
1. 先查看第一个空闲loop设备
  1. sudo losetup -f
  2. /dev/loop0
复制代码


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


3. 查看信息
  1. sudo fdisk -lu /dev/loop0

  2. Disk /dev/loop0: 322 MB, 322469376 bytes
  3. 53 heads, 12 sectors/track, 990 cylinders, total 629823 sectors
  4. Units = sectors of 1 * 512 = 512 bytes
  5. Disk identifier: 0x00000000

  6.       Device Boot      Start         End      Blocks   Id  System
  7. /dev/loop0p1   *          63      629822      314880   83  Linux
  8. Partition 1 has different physical/logical beginnings (non-Linux?):
  9.      phys=(0, 1, 1) logical=(0, 5, 4)
  10. Partition 1 has different physical/logical endings:
  11.      phys=(39, 52, 12) logical=(990, 15, 3)
复制代码

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


4. mout
  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. 查看信息
  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. Disk archlinux-2008.06-core-i686.img: 0 MB, 0 bytes
  5. 53 heads, 12 sectors/track, 0 cylinders, total 0 sectors
  6. Units = sectors of 1 * 512 = 512 bytes
  7. Disk identifier: 0x00000000

  8.                           Device Boot      Start         End      Blocks   Id  System
  9. archlinux-2008.06-core-i686.img1   *          63      629822      314880   83  Linux
  10. Partition 1 has different physical/logical beginnings (non-Linux?):
  11.      phys=(0, 1, 1) logical=(0, 5, 4)
  12. Partition 1 has different physical/logical endings:
  13.      phys=(39, 52, 12) logical=(990, 15, 3)
复制代码

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

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


参考Loop-mounting partitions from a disk image
发表于 2008-8-8 23:00:35 | 显示全部楼层
可以修改不?我的1G优盘。。被活活阉割了。。
然后自己把后面空间分区了。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-8-9 11:19:21 | 显示全部楼层
想怎么修改?想使它占据1G?那好象有点浪费啊
回复 支持 反对

使用道具 举报

发表于 2009-3-28 11:50:13 | 显示全部楼层
img也是grub的,看看它的参数,文件复制过去参数启动就ok啦,正宗的硬盘安装。

测试成功
回复 支持 反对

使用道具 举报

发表于 2009-3-28 16:07:11 | 显示全部楼层
赞一个!我还真是不知道怎样挂载它。
回复 支持 反对

使用道具 举报

发表于 2009-3-28 17:11:41 | 显示全部楼层
挂载
mount -o loop /path/to/img /where/to/mount

安装
dd if=/path/to/img of=/dev/sdX
回复 支持 反对

使用道具 举报

发表于 2009-3-28 19:10:31 | 显示全部楼层
楼上的,没有指定偏移值选项,你就能把archlinux的img文件挂载成功?!
回复 支持 反对

使用道具 举报

发表于 2009-4-13 12:31:40 | 显示全部楼层
完全能行,验证过了,不过有网友用这种方法挂 monoWall的img没成功
我测试用的是archlinux liveusb image完全OK
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表