Details about mounting and formatting Virtual Disks in Linux

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.