在Ubuntu上是否可以挂载虚拟硬盘(VHD、HDD、VDI、VMDK)?如何操作?
Linux and other Unix-like hosts can mount images created with the raw format type using a loopback device. From a root login (or using sudo), mount a loopback with an offset of 32,256.
mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
通常情况下,您可以将图像从一种格式转换为另一种格式。For other types of qemu images, you can use 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.
与“Qemu的方式”命令相同。没有边界!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
ls /dev/nbd0*
,然后逐个尝试挂载它们(如果得到不想要的结果,请执行umount /mnt/image
)。 - Pawelsudo apt-get install afflib-tools
sudo affuse /path/file.vmdk /mnt/vmdk
sudo 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
sudo mount -o ro,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdisk
mount -o ro,loop,offset=1048576 ./foo.raw /mnt/foo
失败,并显示只有root用户可以使用“--options”选项
。如果使用sudo
,则会显示设置回环设备失败:权限被拒绝
。 - Theodore Murdockaffuse
不支持vmdk
文件。 - Daniel Aldersudo modprobe nbd
sudo qemu-nbd -c /dev/nbd1 ./linux_box/VM/image.vdi
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: special device /dev/nbd0p1 does not exist' 的错误。
tar -tf image.ova
tar -xvf image.ova
vmdk
和 vhd
文件,我只能依靠下面的 kpartx
命令来运气。sudo kpartx -a -v <image-flat.vmdk>
losetup
的输出,它应该包含循环设备/dev/loop0
;还要检查sudo blkid
中的分区/dev/mapper/loop0p1
,然后在挂载命令中使用它。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>