We can use the dd command to create a raw virtual disk. Usually Xen is a virtual disk in this format. Today we will discuss how to mount the virtual disk to a local disk.
There are three cases: Only one partition, multiple partitions but not lvm, and lvm;
Create a raw virtual hard disk for use in the following experiment.
One Partition
Format and Mount
Multiple partitions (excluding lvm)
Map to the loopback device, and then use the fdisk partition.
Losetup maps the file to the loop device. In this case,/dev/loop0 is like/dev/sdb,/dev/hdc. You can use fdisk for partitioning. img is divided into two zones and not formatted yet.
In fact, adding the-o loop option to mount a single partition is equivalent to the following operations:
Losetup/dev/loop0 test. img
Mount/dev/loop0/mnt (mount/dev/sdb/mnt can be used to mount a disk as a partition)
But it does not work when multiple partitions exist, because mount/dev/sdb1/mnt is required.
Therefore, use kpartx-av/dev/loop0 to list the partitions of the virtual disk.
If/dev/loop0 is equivalent to/dev/sdb,/dev/mapper/loop0p1 and/dev/mapper/loop0p2 are equivalent to/dev/sdb2
Mount
How to uninstall it? Reverse Review
Including lvm
Similarly, first map to the loopback device, then create a pv, a vg, and then create two lv
In this way, there is actually only one physical partition, which is too simple and complicated.
Create two physical partitions, one for direct formatting, one for lvm, and then create a vg and two for lv.
First losetup, then fdisk, and then kpartx, And then/dev/mapper/loop0p1 and/dev/mapper/loop0p2
Direct mkfs. ext3 to/dev/mapper/loop0p1
Create an lvm partition on/dev/mapper/loop0p2
Activate the volume group when uninstalling it.
How can I mount a virtual disk with lvm? Take the above for example. After kpartx-av, use vgchange-a y vgg to activate the volume group, and then you can see vgg in/dev/. Otherwise, you cannot see it.
Why is this partition format used as an example? This is because the default partition format is like this when linux is installed,
Two partitions
/Dev/sda1 ==>/boot
/Dev/sdb2 ==>/dev/VolGroup00 ==> root, home, swap (or no home)
From Niu GE's blog