1 创建image文件
软盘, 80磁道,2磁头,每磁道18扇区,每扇区512字节。 80*2*18=2880
dd if=/dev/zero of=floopy.img bs=512 count=2880
硬盘,比如要建立一个 柱面数520,磁头数16,每磁道扇区63的硬盘文件。 520*16*63=524160
dd if=/dev/zero of=hdc.img bs=512 count=524160
2 访问镜像文件内容
软盘
mount -t minix rootimage-0.12 /mnt -o loop
cd /mnt
ls
硬盘
$losetup /dev/loop1 rootimage-0.12-hd
$fdisk /dev/loop1
Command (m for help): x
Expert command (m for help): p
Disk /dev/loop1: 16 heads, 63 sectors, 487 cylinders
Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID
1 80 1 1 0 15 63 130 1 132047 81
Partition 1 has different physical/logical beginnings (non-Linux?):
phys=(0, 1, 1) logical=(0, 0, 2)
2 00 0 1 131 15 63 261 132048 132048 81
3 00 0 1 262 15 63 392 264096 132048 81
4 00 0 1 393 15 63 474 396144 82656 82
Expert command (m for help): q
注意start对应的值,这个值乘以512是下次losetup的输入
$losetup -d /dev/loop1
$losetup -o 512 /dev/loop1 rootimage-0.12-hd
$mount -t minix /dev/loop1 /mnt/
$ls /mnt/
上面的步骤太麻烦了,用下面这个吧。
richard@richard:~/kvm$ parted ubuntu.imgWARNING: You are not superuser. Watch out for permissions.
GNU Parted 2.3
Using /home/richard/kvm/ubuntu.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit
Unit? [compact]? B
(parted) print
Model: (file)
Disk /home/richard/kvm/ubuntu.img: 32212254720B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1048576B 31676432383B 31675383808B primary ext4 boot
2 31677479936B 32211206143B 533726208B extended
5 31677480960B 32211206143B 533725184B logical linux-swap(v1)
(parted) q
richard@richard:~/kvm$ sudo mount -o loop,offset=1048576 ubuntu.img loop
richard@richard:~/kvm$ ls loop/
bin cdrom etc initrd.img lost+found mnt proc sbin srv tmp var
boot dev home lib media opt root selinux sys usr vmlinuz
richard@richard:~/kvm$ ls
loop run.sh
RHEL6.0-20100922.1-Server-x86_64-DVD1.iso ubuntu-11.04-desktop-i386.iso
RHEL6.1-20110510.1-Server-i386-DVD1.iso ubuntu.img