Introduction to LVM Logical Volume Management

Source: Internet
Author: User
To create a logical volume, run the vgscan command (run on all RAC nodes in the cluster) to create the/etc/lvmtab file. Use pvcreate to create a physical volume used by the Logical Volume Manager (LVM. Use vgcreate as the drive or for the RAW device

Create logical volume

The following commands are required to create a logical volume:

Run the vgscan command (run on all RAC nodes in the cluster) to create the/etc/lvmtab file.

Use pvcreate to create a physical volume used by the Logical Volume Manager (LVM.

Use vgcreate to create a volume group for the drive or for the partition you want to use for RAW devices. Here we create a volume for the entire drive. In our example (as shown below), this command will allow the creation of 256 logical partitions and 256 physical partitions in the range of 128 K.

Use lvcreate to create a logical volume in the volume group.

Note: As mentioned above, I need to run the vgscan command on all nodes so that this command can create the/etc/lvmtab file. You should execute the following command before running it.

Place the following command in a schell script, change the execution permission, and run the script with "root" UNIX User id:

Vgscan

Pvcreate-d/dev/sda

Vgcreate-l 256-p 256-s 128 k/dev/pv1/dev/sda

Lvcreate-L 5 m/dev/pv1

Lvcreate-L 100 m/dev/pv1

Lvcreate-L 10 m/dev/pv1

Lvcreate-L 200 m/dev/pv1

Lvcreate-L 200 m/dev/pv1

Lvcreate-L 200 m/dev/pv1

Lvcreate-L 55 m/dev/pv1

Lvcreate-L 25 m/dev/pv1

Lvcreate-L 255 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 55 m/dev/pv1

Lvcreate-L 805 m/dev/pv1

Lvcreate-L 255 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 405 m/dev/pv1

Lvcreate-L 405 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 155 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

Lvcreate-L 105 m/dev/pv1

This script (as shown above) will create/dev/pv1/lvol1-/dev/pv1/lvol23.

I usually useLvsCan command to check the status of the logical volume:

[Root @ linux2 root] # lvscan

Lvscan -- ACTIVE "/dev/pv1/lvol1" [5 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol2" [100 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol3" [10 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol4" [200 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol5" [200 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol6" [200 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol7" [55 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol8" [25 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol9" [255 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol10" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol11" [55 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol12" [805 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol13" [255 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol14" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol15" [405 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol16" [405 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol17" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol18" [155 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol19" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol20" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol21" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol22" [105 MB]

Lvscan -- ACTIVE "/dev/pv1/lvol23" [105 MB]

Lvscan -- 23 logical volumes with 3.88 GB total in 1 volumegroup

Lvscan -- 23 active logical volumes

Restart all nodes in the RAC cluster

After creating a partition, we recommend that you restart the kernel on all RAC nodes to ensure that all new partitions are identified by the kernel on all RAC nodes:
1. add a logical volume
After a volume group is created, you can use the lvcreate command to create a logical volume on the volume group. For example, to create a MB logical volume lv_data1 on the volume group vg_data, run the following command.

# Lvcreate-L 1000 m-n lv_data1 vg_data

Logical volume "lv_data1" created

In addition to general units such as KB, MB, and GB, the lvcreate command can also use the number of PES as the unit. Vgdisplay shows that the PE size of the volume group vg_data is 4 MB. if you want to create a logical volume of 250 MB, you need PEs. the command is as follows.

# Lvcreate-l 250-n lv_data2 vg_data

Logical volume "lv_data2" created

After a volume Group and logical volume are created, a directory named VG is created under the/dev directory, and a device file named LV is created under the Directory, as shown below.

# Ll/dev/vg_data

Total 0

Lrwxrwxrwx 1 root 28 Aug 24 lv_data1->/dev/mapper/vg _ data-lv_data1

Lrwxrwxrwx 1 root 28 Aug 24 lv_data2->/dev/mapper/vg _ data-lv_data2

2. change the logical volume size
You can use the lvresize command to change the size of an existing logical volume. Generally, it is not recommended to reduce the space of the logical volume, because this may cause data loss in the file system on the logical volume, therefore, unless the user has determined that the data in the reduced space is no longer required or has backed up important data, do not reduce the space of the logical volume to avoid irreparable losses. To increase the logical volume lv_data1 to 1500 MB, run the following command.

# Lvresize-L 1500 m/dev/vg_data/lv_data1

Extending logical volume lv_data1 to 1.46 GB

Logical volume lv_data1 successfully resized

3. View logical volume information
You can use the lvdisplay command to view the information of a specified logical volume. for example, to view the information of the logical volume lv_data1, the command and running result are as follows.

# Lvdisplay/dev/vg_data/lv_data1

--- Logical volume ---

LVName/dev/vg_data/lv_data1 // logical volume name

VGName vg_data // volume group to which the logical volume belongs

LVUUID 3CrIH1-rZr6-UkNZ-1Z5n-gHw2-SM5T-by5fKg

LV Write Access read/write

LVStatus available

# Open 0

LVSize 1.46 GB // logical volume size

CurrentLE 375 // number of logical blocks of the logical volume

Segments 1

Allocation inherit

Read ahead sectors auto

-Currently sets to 256

Blockdevice 253: 0

The logical volume/dev/vg_data/lv_data1 belongs to a vg_data volume group. The access permission is read/write, the volume group status is available, and the logical volume size is 1.46 GB, the total number of logical blocks is 375.

4. delete a logical volume
You can use the lvremove command to delete a specified logical volume. the system prompts you to confirm the deletion. For example, to delete the logical volume lv_data2, the command and running result are as follows.

# Lvremove/dev/vg_data/lv_data2

Do you really want to remove active logical volume "lv_data2 "? [Y/n]: y

Logical volume "lv_data2" successfully removed

After deletion, all data on the logical volume is cleared.

Related Article

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.