Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to mount virtual disk files such as VHD under linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you how to mount virtual disk files such as VHD under linux, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

1. RAW format virtual disk

Under linux, you can mount raw virtual disk image files directly.

For example, here you create a file with dd, format it in ext4 format (with only one partition), and mount it in/mnt directory.

The raw.img disk image file below is a single partition, so offset= is not used to specify the offset. If there are multiple partitions, you can mount them by specifying an offset. For details, please refer to the relevant parameter information of mount command.

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

Read 512+0

512+0 is written.

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

2. VHD/VHDX disk file mount

Linux does not directly support mounting VHD disk image files. It can be mounted via tools such as vmware's vmware-mount. Vmware does not provide this tool directly, but it is available in both vmware player and vmware workstation. But this is not intended to be the case here.

Qemu-nbd is used here to mount disk image files.

a) Install qemu

First, install qemu-kvm, I use Fedora 25 here, the installation command is as follows

sudo dnf install qemu-kvm

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

archlinux can be installed using sudo pacman -S qemu.

b) Load nbd driver

NBD(Network Block Device) stands for Network Block Device. This module allows disk space on a remote host (as distinct from mounting nfs) to be used as a local block device.

NBD is a kernel module that is already included in most Linux distributions, so 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, 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 message says that the number of initialized network block devices is 16, which means 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 files to nbd devices

qemu-nbd is used here to connect (connect with-c and disconnect with-d)

/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

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

d) Mount partition

You can mount nbd0p1 directly by using mount command

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

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

[sudo] o's password:

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.

The specific installation process is briefly described

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 extract the src.rpm package.

sudo dnf install fuse-devel rpmbuild

sudo dnf install scons #build exfat-utils required

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

After decompression, you can see the rpmbuild directory under 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

Once the build is complete, go to the rpmbuild/RPMS/x86_64 directory (where x86_64 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

In preparation... ################################# [100%]

Upgrading/installing...

1:fuse-exfat-1.0.1-1.fc25 ################################# [ 50%]

2:exfat-utils-1.0.1-2.fc25 ################################# [100%]

sudo apt install exfat-utils exfat-fuse

3. Mounting of other virtual disk files

The rest will not be said, and the above VHD mount is the same, provided that it is a supported disk image format.

The above is all the content of this article "How to mount VHD and other virtual disk files under Linux", thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report