我有一个磁盘映像文件,我正在尝试使用循环设备在本地安装。使用parted我可以看到图像有两个分区,但是,我无法安装第一个分区并losetup
认为第二个分区不存在。有人知道如何安装第二个分区吗?
/m/sf_VMShare ❯❯❯ sudo losetup /dev/loop0 ./imm_image-2017-05-28.img
/m/sf_VMShare ❯❯❯ sudo losetup -a
/dev/loop0: [0023]:99 (/media/sf_VMShare/imm_image-2017-05-28.img)
/m/sf_VMShare ❯❯❯ sudo parted /dev/loop0 print
Model: Loopback device (loop)
Disk /dev/loop0: 1206MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 10.5MB 360MB 349MB primary ext4
2 361MB 1205MB 844MB primary ext4
/m/sf_VMShare ❯❯❯ sudo mount -t ext4 /dev/loop0p2 /tmp/vdisk
mount: special device /dev/loop0p2 does not exist
/m/sf_VMShare ❯❯❯ sudo mount -t ext4 /dev/loop0p1 /tmp/vdisk
mount: wrong fs type, bad option, bad superblock on /dev/loop0p1,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
/m/sf_VMShare ❯❯❯ mount | grep /tmp/vdisk
/m/sf_VMShare ❯❯❯
/m/sf_VMShare ❯❯❯ ls /dev/loop*
/dev/loop0 /dev/loop1 /dev/loop3 /dev/loop5 /dev/loop7
/dev/loop0p1 /dev/loop2 /dev/loop4 /dev/loop6 /dev/loop-control
/m/sf_VMShare ❯❯❯ lsblk -f
NAME FSTYPE LABEL MOUNTPOINT
sda
├─sda1 /
├─sda2
└─sda5 [SWAP]
sdb
└─sdb1 /home/foo/workspace
sr0
loop0
└─loop0p1
答案1
如何在包含 msdos 分区表的完整磁盘映像中安装分区。
工具:
fdisk
mount
- 计算器
获取图像的分区布局。
sudo fdisk -l -u=sectors /work/loop_test/disk_image.img
输出示例:
Disk /work/loop_test/disk_image.img: 29 MB, 29629952 bytes
255 heads, 63 sectors/track, 3 cylinders, total 57871 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009d7e5
Device Boot Start End Blocks Id System
/work/loop_test/disk_image.img1 2048 18431 8192 83 Linux
/work/loop_test/disk_image.img2 18432 57343 19456 7 HPFS/NTFS/exFAT
计算从图像开始到分区开始的偏移量。在本例中为 ntfs 分区。
公式:
Sector size * Start = Offset
512 * 18432 = 9437184
挂载映像,传递所需分区的偏移量。
本例中为 ntfs 分区。
sudo mount -o loop,offset=9437184 /work/loop_test/disk_image.img /mnt/ntfs_partition
答案2
运行时losetup -P
将自动检测分区并/dev/loop0pX
为您创建合适的设备。无需手动执行计算。