虚拟盘的使用

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.img
WARNING: 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值