Stretching and shrinking of Linux logical volumes

Source: Internet
Author: User

The advantage relative to the ordinary disk is that the logical volume can be dynamically stretched online (without first unmount operation), as long as there is enough space in the VG to

1: First check if the VG has enough space

[Email protected] mapper]# Vgdisplay

2: Online Stretching of logical volumes

[Email protected] mapper]# lvextend-l +2g/dev/vg_gechong/lv_swap

3: View the size of the logical volume

[Email protected] ~]# df-h

The size does not change because the size of the logical volume is expanded and the file system is not updated, the operating system does not recognize the stretched dimensions, so the file system must be updated.

4: Update file system

[Email protected] ~]# Resize2fs/dev/vg_gechong/lv_swap

5: Re-viewing the file system size

[Email protected] ~]# df-h

6: What if the volume group is not enough? How do I fix it?

Re-add PV, i.e. add disk to

[Email protected] ~]# VGS

7: Stretch a volume group

1: Create Pv[[email protected] ~]# pvcreate/dev/sdd2: Add PV to VG [[email protected] ~]# vgextend VG_GECHONG/DEV/SDD3: Re-view the size of the VG [Email protected] ~]# VGS

Shrink a logical volume

The reduction of logical volumes cannot be performed online

1: Unload a logical volume that is already mounted

[Email protected] ~]# Umount/dev/vg_gechong/lv_swap

2: Check the file system

e2fsck-f/dev /vg_gechong/lv_swap

3: Shrink File system

[Email protected] ~]# Resize2fs/dev/vg_gechong/lv_swap 1G

Reduce file system space to 1G

4: Shrink the logical volume

[Email protected] ~]# lvreduce-l 1g/dev/vg_gechong/lv_swap

5: View the reduced logical volume

[Email protected] ~]# Lvdisplay

6: Mount the Logical volume

[Email protected] ~]# mount/dev/vg_gechong/lv_swap/mnt

Shrink a volume group

[Email protected] ~]# vgreduce VG_GECHONG/DEV/SDD

View

[Email protected] ~]# Vgdisplay
[Email protected] ~]# PVREMOVE/DEV/SDD

Delete a physical volume

----------------------------------------------------

Pvscan: Search the current system inside anything what has PV disk

[Email protected] ~]# Pvscan

Pv/dev/hda6 lvm2 [1.40 GB]

Pv/dev/hda7 lvm2 [1.40 GB]

Pv/dev/hda8 lvm2 [1.40 GB]

Total:4 [5.61 GB]/in use:0 [0]/In no vg:4 [5.61 GB]

The last line shows the total PV quantity/amount of PV that has been used to the VG/remaining PV amount

Pvdisplay: Shows the PV form above the current system

? Vgcreate: is the main establishment of VG
? Vgscan: Is there a VG on the search system?
? Vgdisplay: Displays the current system above the VG State;
? Vgextend: Add additional PV within the VG, e.g. Vgextend oyxtvg/dev/hda8
? Vgreduce: Removing PV within the VG;
? Vgchange: Sets whether the VG starts (active);
? Vgremove: Delete a VG

---------------------------------------

Enlarge LV Capacity

1. Create a new partition with the 8e system ID with Fdisk
2. Using Pvcreate to build PV
3. Use Vgextend to add PV to our OYXTVG
4. Use Lvresize to add the PE in the newly added PV into the OYXTLV
5. The capacity of the filesystem is actually increased through RESIZE2FS!

# capacity does not seem to be able to write the number of decimal places, so 6.9G is wrong, it is recommended to use 6900M

---------------------------------------

Snapshot snapshot (mainly used for real-time online backup)

Principle: Through LVM snapshot to the LVM to take a picture, when the LVM host changes, the LVM snapshot of the LVM changes the content before the change in the snapshot, so that in the time of the LVM snapshot is valid, What we see on the LVM snapshot is always the content of LVM in the creation of LVM snapshots, which can be achieved by backing up LVM snapshots to online backup LVM. It should be noted that when LVM snapshot is more than LVM, if the change of LVM is greater than LVM snapshot, the LVM snapshot will become unreadable and fail; If the LVM snapshot is greater than or equal to the LVM true, the preceding situation does not occur.

Using Lvcreate to establish a system corporate, we named OYXTSS and gave 60 PE

[Email protected] ~]# lvcreate-l 60-s-N OYXTSS/DEV/OYXTVG/OYXTLV

Logical volume "OYXTSS" created

The most important of the above commands is the-s selection! The representative is the snapshot snapshot function meaning!

-N is followed by the name of the snapshot area,/dev/.... is the full name of the LV to be taken by the snapshot.

The number of PE to use for this snapshot area is followed by-L, or you can specify the space size of the snapshot directly later, such as-l 60M

#mkdir/snap//Create a directory as the mount point of the snapshot volume #tar-jcf/tmp/snap.tar.gz/snap/*//backup the contents of the snapshot volume to/tmp this time no matter what changes you make on the logical volume Do not worry about data loss, from the backup snapshot file can be recovered from the previous files, this is the strength of the snapshot volume ...

#lvdisplay

.......LV Size 6.97 GB <== the original LV disk capacity of the snapshotCurrent LE 446 cow-table size 960.00 MB <== The actual capacity of the snapshot areacow-table LE <== The number of PE occupied in the snapshot area........ Note two points:1, the snapshot is actually a logical volume, snapshot This method is only valid for LVM, invalid for non-LVM file system2. Snapshots can only be backed up by logical volume LVM, and only logical volumes of the same volume group can be backed up. In addition, because the snapshot area and the original LV share a lot of PE chunks, so the snapshot area and the snapshot of the LV must be on the same VG

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.