Home  >  Article  >  System Tutorial  >  How to mount VHD and other virtual disk files in linux

How to mount VHD and other virtual disk files in linux

王林
王林forward
2024-01-09 10:17:381411browse

1. RAW format virtual disk

Under Linux, virtual disk image files in raw format can be directly mounted.

For example, here first use the dd command to create a file, then format it into ext4 format (only one partition), and then mount it to the /mnt directory.

The raw.img disk image file below is only one partition, so offset= is not used to specify the offset. If there are multiple partitions, they can be mounted by specifying offsets. For specific information, please refer to the relevant parameter information of the mount command.

> dd if=/dev/zero of=raw.img bs=1M count=512

Recorded the read of 512 0

Recorded the writing of 512 0

536870912 bytes (537 MB, 512 MiB) copied, 0.207045 s, 2.6 GB/s

/home/o [o@o-pc] [10:29]

> mkfs.ext4 -q raw.img

/home/o [o@o-pc] [10:30]

> sudo mount -o loop raw.img /mnt

/home/o [o@o-pc] [10:30]

> df -h

How to mount VHD and other virtual disk files in linux

2. VHD/VHDX disk file mounting

Linux cannot directly support mounting VHD disk image files. It can be mounted through tools such as vmware's vmware-mount. VMware does not provide this tool directly, but it is available in vmware player and vmware workstation. But that's not the way to go here.

Qemu-nbd is used here to mount the disk image file.

a) Install qemu

First of all, you need to install qemu-kvm. I am using Fedora 25 here. The installation command is as follows

sudo dnf install qemu-kvm

If you are using debian/ubuntu, etc., you can use sudo apt-get install qemu-kvm to install.

archlinux can be installed using sudo pacman -S qemu.

b) Load nbd driver

NBD (Network Block Device) is the abbreviation of Network Block Device. This module can use the disk space of a remote host (different from mounting nfs) as a local block device.

NBD is a kernel module. Most Linux distributions already include it. There is no need to install it here.

Use modprobe to load nbd driver

/media/o/data [o@o-pc] [11:04]

> sudo modprobe nbd max_part=8

After loading is complete, you can use the modinfo command to view module information

/media/o/data [o@o-pc] [11:05]

> modinfo nbd

filename: /lib/modules/4.9.6-200.fc25.x86_64/kernel/drivers/block/nbd.ko.xz

license: GPL

description: Network Block Device

depends:    

intree: Y

vermagic: 4.9.6-200.fc25.x86_64 SMP mod_unload

signat: PKCS#7

signer:      

sig_key:  

sig_hashalgo: md4

parm: nbds_max:number of network block devices to initialize (default: 16) (int)

parm: max_part:number of partitions per device (default: 0) (int)

The above information says that the number of initialized network block devices is 16, indicating that it creates 16 nbd devices under /dev/.

/media/o/data [o@o-pc] [11:05]

> ls /dev/nbd*

/dev/nbd0 /dev/nbd0p1 /dev/nbd1 /dev/nbd10 /dev/nbd11 /dev/nbd12 /dev/nbd13 /dev/nbd14 /dev/nbd15 /dev/nbd2 /dev/nbd3 /dev/ nbd4 /dev/nbd5 /dev/nbd6 /dev/nbd7 /dev/nbd8 /dev/nbd9

c) Connect vhdx file to nbd device

Use qemu-nbd here to connect (use the -c parameter to connect, use the -d parameter to disconnect)

/media/o/data [o@o-pc] [11:05]

> sudo qemu-nbd -c /dev/nbd0 VS2017RC-offline.vhdx

After connecting, use fdisk to check the device information.

/media/o/data [o@o-pc] [11:05]

> sudo fdisk -l /dev/nbd0

Disk /dev/nbd0: 100 GiB, 107374182400 bytes, 209715200 sectors

Unit: sector / 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xa373e501

How to mount VHD and other virtual disk files in linux

In fact, the disk has only one partition, the partition format is exFAT, and the disk size grows dynamically.

d)Mount partition

Just use the mount command to mount nbd0p1

/media/o/data [o@o-pc] [11:36]

> sudo mount -t exfat -o rw /dev/nbd0p1 /mnt

[sudo] Password for o:

FUSE exfat 1.0.1

/media/o/data [o@o-pc] [12:05]

> ls /mnt/

'$RECYCLE.BIN' 'System Volume Information' vs2017rc Installation Instructions.txt

Install exFAT support

Because the partition is in exFAT format, it cannot be mounted directly.

First install fuse-exfat and exfat-utils.

Let’s briefly talk about the specific installation process

First download two rpm source packages.

wget http://download1.rpmfusion.org/free/el/updates/6/SRPMS/exfat-utils-1.0.1-2.el6.src.rpm

wget http://download1.rpmfusion.org/free/el/updates/6/SRPMS/exfat-utils-1.0.1-2.el6.src.rpm

Then install fuse-devel and rpmbuild, and decompress the src.rpm package.

sudo dnf install fuse-devel rpmbuild

sudo dnf install scons #Required to build exfat-utils

rpm -ivh exfat-utils-1.0.1-2.el6.src.rpm exfat-utils-1.0.1-2.el6.src.rpm

After decompression is completed, you can see the rpmbuild directory in the current user's home directory and enter the SPECS directory under this directory.

Then use rpmbuild to build the rpm package.

rpmbuild -ba exfat-utils.spec

rpmbuild -ba fuse-exfat.spec

After the build is completed, enter the rpmbuild/RPMS/x86_64 directory (x86_64 here is related to your system architecture) and install the generated rpm package.

/home/o/rpmbuild/RPMS/x86_64 [o@o-pc] [12:04]

> sudo rpm -ivh exfat-utils-1.0.1-2.fc25.x86_64.rpm fuse-exfat-1.0.1-1.fc25.x86_64.rpm

Preparing...                                                                                                                                                                                                                            

#[100%]

Upgrading/installing...

###1:fuse-exfat-1.0.1-1.fc25 ################################ [ 50%]### ###2:exfat-utils-1.0.1-2.fc25 ################################ [ 100%]### ###On ubuntu, you can directly use apt to install sudo apt install exfat-utils exfat-fuse### ###3. Mounting of other virtual disk files### ###I won’t say anything else anymore. It is the same as the VHD mounting above, provided that it is a supported disk image format. ###

The above is the detailed content of How to mount VHD and other virtual disk files in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete