Answers:
根据这篇文章:
Linux和其他类似Unix的主机可以使用环回设备挂载以原始格式类型创建的映像。通过root登录(或使用sudo),安装偏移量为32,256的环回。
mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
对于其他类型的qemu图像,可以使用qemu-nbd
modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 image.qcow2
partprobe /dev/nbd0
mount /dev/nbd0p1 /mnt/image
另外,通常,您可以将图像从一种格式转换为另一种格式。
raw - (default) the raw format is a plain binary image of the disc
image, and is very portable.
On filesystems that support sparse files,
images in this format only use the
space actually used by the data recorded in them.
cloop - Compressed Loop format, mainly used for reading Knoppix
and similar live CD image formats
cow - copy-on-write format, supported for historical reasons only and
not available to QEMU on Windows
qcow - the old QEMU copy-on-write format, supported for
historical reasons and superseded by qcow2
qcow2 - QEMU copy-on-write format with a range of special features,
including the ability to take multiple snapshots, smaller
images on filesystems that don't support sparse files,
optional AES encryption, and optional zlib compression
vmdk - VMware 3 & 4, or 6 image format, for exchanging images
with that product
vdi - VirtualBox 1.1 compatible image format, for exchanging
images with VirtualBox.
尝试谷歌,我在一秒钟内找到(VirtualBox).VDI的解决方案:
modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 /path/to/some.vdi
mount -o loop /dev/nbd0p1 /mnt
# do stuff
umount /mnt
qemu-nbd -d /dev/nbd0
rmmod nbd
与“ Qemu的方式”命令相同。无国界!
这是在Ubuntu 16.04上。
apt-get install afflib-tools
affuse /path/file.vmdk /mnt/vmdk
fdisk -l /mnt/vmdk/file.vmdk.raw
# example
Disk file.vmdk.raw: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x000da525
Device Boot Start End Sectors Size Id Type
/mnt/vmdk/file.vmdk.raw1 * 2048 41943039 41940992 20G 83 Linux
echo 2048*512 | bc
1048576
mount -o ro,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdisk
mount -o ro,loop,offset=1048576 ./foo.raw /mnt/foo
失败only root can use "--options" option
。使用sudo
,则失败failed to setup loop device: Permission denied
。
您也可以使用qemu:
.vdi
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd1 ./linux_box/VM/image.vdi
如果未安装,则可以安装它们(在Ubuntu上是此命令)
sudo apt install qemu-utils
然后挂载
mount /dev/nbd1p1 /mnt
.vmdk
sudo modprobe nbd
sudo qemu-nbd -r -c /dev/nbd1 ./linux_box/VM/image.vmdk
请注意,我使用该选项-r
是因为VMDK版本3必须只读才能被qemu挂载
然后我将其安装
mount /dev/nbd1p1 /mnt
我使用nbd1
是因为nbd0
有时会给出“ mount:特殊设备/ dev / nbd0p1不存在”
tar -tf image.ova
tar -xvf image.ova
上面将提取.vmdk
磁盘,然后将其挂载。
对于vmdk
和vhd
文件,仅使用以下kpartx
命令我很幸运:
sudo kpartx -a -v <image-flat.vmdk>
检查输出是否为losetup
,它应该包含回路设备/dev/loop0
; 还检查sudo blkid
分区/dev/mapper/loop0p1
,然后在mount命令中使用它:
sudo mount -o rw /dev/mapper/loop0p1 /mnt/vmdk
/ mnt / vmdk是您的挂载点,sudo mkdir /mnt/vmdk
如果不存在,则使用该挂载点创建。
源于commandlinefu.com(kpartx和mount命令)
卸载:
sudo umount /mnt/vmdk
sudo kpartx -d -v <image-flat.vmdk>
vhd
,就可以了!