Increase and decrease LV capacity and create snapshot volumes

Source: Internet
Author: User

1. Expand LV capacity

You do not need to detach the file system to increase the LV capacity.

The procedure is as follows:

A. Use fdisk to set partitions with 8e System ID

B. Create a PV using pvcreate

C. Use vgextend to add PV to VG to resize VG

D. Use lvresize to add the PE of the new PV to the LV.

E. Increase the file system capacity through resize2fs.


Example:

Step 1: mount the lv-01 to the/Backup Directory and copy/etc/services to the file system.

[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot/dev/mapper/DATA_01-lv--01                      155M  5.6M  142M   4% /backup[[email protected] ~]# lvs  LV    VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  lv-01 DATA_01 -wi-ao-- 160.00m                                           [[email protected] ~]# cp /etc/services /backup/[[email protected] ~]# ls -l /backup/total 638drwx------ 2 root root  12288 Jul 17 02:10 lost+found-rw-r--r-- 1 root root 641020 Jul 17 02:11 services[[email protected] ~]#


Step 2: view the VG capacity

[[email protected] ~]# vgdisplay   --- Volume group ---  VG Name               DATA_01  System ID               Format                lvm2  Metadata Areas        2  Metadata Sequence No  17  VG Access             read/write  VG Status             resizable  MAX LV                0  Cur LV                1  Open LV               1  Max PV                0  Cur PV                2  Act PV                2  VG Size               2.00 GiB  PE Size               32.00 MiB  Total PE              64  Alloc PE / Size       5 / 160.00 MiB  Free  PE / Size       59 / 1.84 GiB  VG UUID               tEVjly-icsW-Jin7-1Bmn-xil1-LvpP-3PQI5C   [[email protected] ~]# vgs  VG      #PV #LV #SN Attr   VSize VFree  DATA_01   2   1   0 wz--n- 2.00g 1.84g[[email protected] ~]#

Note:

The current VG still has a capacity of 1.84g. If there is no additional space, you need to use pvcreate to create a PV and add the PV to the VG using vgextend.


Step 3: scale up the LV. Here, scale it to around MB.

Note: here we will introduce how to increase the number of PES to increase the LV. In my system, the PE size is 32 m, and the original LV size is 160 m, if you want to increase to 340 m, you need to increase 340/32 M, 10.625 =. Here, 11 PES are added.

Specific operations:

[[email protected] ~]# lvresize -l +11 /dev/DATA_01/lv-01   Extending logical volume lv-01 to 512.00 MiB  Logical volume lv-01 successfully resized[[email protected] ~]# lvs  LV    VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  lv-01 DATA_01 -wi-ao-- 512.00m                                           [[email protected] ~]#


View the file system capacity:

[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot/dev/mapper/DATA_01-lv--01                      155M  6.2M  141M   5% /backup[[email protected] ~]#

Note: The file system capacity has not increased.


Step 4: Increase the file system capacity.

Command: resize2fs/dev/vgname/lvname

[[email protected] ~]# resize2fs /dev/DATA_01/lv-01 resize2fs 1.41.12 (17-May-2010)Filesystem at /dev/DATA_01/lv-01 is mounted on /backup; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 2Performing an on-line resize of /dev/DATA_01/lv-01 to 524288 (1k) blocks.The filesystem on /dev/DATA_01/lv-01 is now 524288 blocks long.[[email protected] ~]#


View the file system capacity:

[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot/dev/mapper/DATA_01-lv--01                      496M  6.9M  464M   2% /backup[[email protected] ~]#

Note: The file system capacity has increased.


Check whether the content in the file system has been lost:

[[email protected] ~]# ls -l /backup/total 638drwx------ 2 root root  12288 Jul 17 02:10 lost+found-rw-r--r-- 1 root root 641020 Jul 17 02:11 services[[email protected] ~]#

The file is still ......






2. Reduce LV capacity

If you want to reduce the LV capacity, you can use a graphical interface. If you cannot use a graphical interface, follow these steps strictly. Otherwise, the file system may be damaged. The graphical LVM software package is: system-config-LVM

Steps (must be strictly executed ):

A. Uninstall the file system to reduce the capacity. The root file system cannot be detached.

B. Use e2fsck-F to check the LV File System

C. Use resize2fs to reduce the file system size.

Resize2fs/dev/VG-name/LV-name <size after reduction>

D. Reduce the LV size. It is best to use the number of PES for lvreduce or lvresize.


Example:

Step 1: uninstall the file system first

[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot/dev/mapper/DATA_01-lv--01                      496M  6.9M  464M   2% /backup[[email protected] ~]# umount /backup/[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot[[email protected] ~]#


Step 2: Check the file system

[[email protected] ~]# e2fsck -f /dev/DATA_01/lv-01 e2fsck 1.41.12 (17-May-2010)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/DATA_01/lv-01: 12/131072 files (0.0% non-contiguous), 23571/524288 blocks[[email protected] ~]#


Step 3: Use resize2fs to reduce the file system size

Note: This is reduced to 50 MB.

[[email protected] ~]# resize2fs /dev/DATA_01/lv-01 50Mresize2fs 1.41.12 (17-May-2010)Resizing the filesystem on /dev/DATA_01/lv-01 to 51200 (1k) blocks.The filesystem on /dev/DATA_01/lv-01 is now 51200 blocks long.[[email protected] ~]#


Step 4: Reduce the LV size

Note: The original LV size is 512 m, which is now reduced to 50 m and 512-50 = 462 M.

[[email protected] ~]# lvresize -L -462M /dev/DATA_01/lv-01   Rounding size to boundary between physical extents: 448.00 MiB  WARNING: Reducing active logical volume to 64.00 MiB  THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce lv-01? [y/n]: y  Reducing logical volume lv-01 to 64.00 MiB  Logical volume lv-01 successfully resized[[email protected] ~]# lvs  LV    VG      Attr     LSize  Pool Origin Data%  Move Log Copy%  Convert  lv-01 DATA_01 -wi-a--- 64.00m                                           [[email protected] ~]#


Step 5: Check whether the mounting test data is still in

[[email protected] ~]# mount /dev/DATA_01/lv-01 /backup/[[email protected] ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot/dev/mapper/DATA_01-lv--01                       49M  5.7M   41M  13% /backup[[email protected] ~]# ll /backup/total 638drwx------ 2 root root  12288 Jul 17 02:10 lost+found-rw-r--r-- 1 root root 641020 Jul 17 02:11 services[[email protected] ~]#

The data is still ......


3. snapshot volume

Snapshots can retain the data at the moment before changing the data. They can be used as another channel to access the original data. snapshot volumes should not be modified by users and should be created as read-only (-p r, if you want to create a snapshot as the read/write mode, you can specify the-P w option and the create snapshot as the-s option.

1. the life cycle of the snapshot volume is the entire data duration. During the data duration, the data growth volume cannot exceed the snapshot volume size. If it exceeds the value, the snapshot volume will be damaged by itself. The safest way is to make the snapshot volume as large as the original volume.

2. the snapshot volume is read-only.


Create a snapshot:

Command: lvcreate-L 50 m-n lv-Snapshot-s-p r/dev/vgname/lvname

Example:

[[email protected] backup]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/sda2             9.9G  7.8G  1.6G  83% /tmpfs                 245M     0  245M   0% /dev/shm/dev/sda1             194M   28M  156M  16% /boot/dev/mapper/DATA_01-lv--01                       49M  5.7M   41M  13% /backup[[email protected] backup]# lvcreate -L 50M -n lv-01-snap -p r /dev/DATA_01/lv-01   Volume group name expected (no slash)  Run `lvcreate --help‘ for more information.[[email protected] backup]# lvcreate -L 50M -n lv-01-snap -s -p r /dev/DATA_01/lv-01   Rounding up size to full physical extent 64.00 MiB  Logical volume "lv-01-snap" created[[email protected] backup]# lvs  LV         VG      Attr     LSize  Pool Origin Data%  Move Log Copy%  Convert  lv-01      DATA_01 owi-aos- 64.00m                                             lv-01-snap DATA_01 sri-a-s- 64.00m      lv-01    0.02                        [[email protected] backup]#


This article is from the "Hezhang" blog, please be sure to keep this source http://hezhang.blog.51cto.com/1347601/1439647

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.