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

How to mount VHD and other virtual disk files in linux

Jan 09, 2024 am 10:17 AM
Disk mount

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

What are the 5 basic components of Linux? What are the 5 basic components of Linux? Apr 06, 2025 am 12:05 AM

The five basic components of Linux are: 1. The kernel, managing hardware resources; 2. The system library, providing functions and services; 3. Shell, the interface for users to interact with the system; 4. The file system, storing and organizing data; 5. Applications, using system resources to implement functions.

What is basic Linux administration? What is basic Linux administration? Apr 02, 2025 pm 02:09 PM

Linux system management ensures the system stability, efficiency and security through configuration, monitoring and maintenance. 1. Master shell commands such as top and systemctl. 2. Use apt or yum to manage the software package. 3. Write automated scripts to improve efficiency. 4. Common debugging errors such as permission problems. 5. Optimize performance through monitoring tools.

How to learn Linux basics? How to learn Linux basics? Apr 10, 2025 am 09:32 AM

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

What is the most use of Linux? What is the most use of Linux? Apr 09, 2025 am 12:02 AM

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

What is a Linux device? What is a Linux device? Apr 05, 2025 am 12:04 AM

Linux devices are hardware devices running Linux operating systems, including servers, personal computers, smartphones and embedded systems. They take advantage of the power of Linux to perform various tasks such as website hosting and big data analytics.

How much does Linux cost? How much does Linux cost? Apr 04, 2025 am 12:01 AM

Linuxisfundamentallyfree,embodying"freeasinfreedom"whichallowsuserstorun,study,share,andmodifythesoftware.However,costsmayarisefromprofessionalsupport,commercialdistributions,proprietaryhardwaredrivers,andlearningresources.Despitethesepoten

What are the disadvantages of Linux? What are the disadvantages of Linux? Apr 08, 2025 am 12:01 AM

The disadvantages of Linux include user experience, software compatibility, hardware support, and learning curve. 1. The user experience is not as friendly as Windows or macOS, and it relies on the command line interface. 2. The software compatibility is not as good as other systems and lacks native versions of many commercial software. 3. Hardware support is not as comprehensive as Windows, and drivers may be compiled manually. 4. The learning curve is steep, and mastering command line operations requires time and patience.

See all articles