Chinaunix首页 | 论坛 | 博客
  • 博客访问: 617171
  • 博文数量: 486
  • 博客积分: 10125
  • 博客等级: 上将
  • 技术积分: 5842
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-27 18:34
文章分类

全部博文(486)

文章存档

2011年(52)

2010年(107)

2009年(289)

2008年(38)

我的朋友

分类: LINUX

2009-04-20 19:00:27

标题: ·[教程]挂载archlinux的img文件
转自linuxsir:


1. 先查看第一个空闲loop设备
代码:
sudo losetup -f
/dev/loop0
2. 使用上一步得到的设备名,第一次创建loop设备
代码:
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命令会用到:
代码:
63*512=32256
4. mout
代码:
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
参考Loop-mounting partitions from a disk image
阅读(443) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~