如何挂载虚拟硬盘?

是否可以在Ubuntu上安装虚拟硬盘(VHD,HDD,VDI,VMDK)? 如何才能做到这一点?

根据这篇文章 :

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. 

尝试google,我在一秒钟内找到(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上

作为根:

使用affuse安装和安装。

 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 

乘以sectorize和startsector。 在示例中,它将是2048 * 512

 echo 2048*512 | bc 1048576 

使用该偏移量安装

 mount -o ro,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdisk 

现在应该在/ mnt / vmdisk上安装和读取磁盘

你也可以使用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不存在’

对于.ova

 tar -tf image.ova tar -xvf image.ova 

以上将提取.vmdk磁盘,然后安装它。