Linux uses lvresize to expand or reduce the LV size

Source: Internet
Author: User

Linux uses lvresize to expand or reduce the LV size

Environment: CentOS 6.7

1. Create and mount the directory/u01 and/data

1. create directory Mount node/u01,/data

mkdir -p /{u01,data}

2. Create an lv named lv_u01 with a size of 10 Gb. Divide the space from vg_bkjia. vg_bkjia here is the vg name.

lvcreate -L 10g -n lv_u01 vg_bkjia

3. format it as an ext4 File System

mkfs.ext4 /dev/mapper/vg_bkjia-lv_u01

4. Similarly, create lv_data

lvcreate -L 10g -n lv_data vg_bkjiamkfs.ext4 /dev/mapper/vg_bkjia-lv_data

5. Add mounting information to/etc/fstab to enable automatic mounting upon startup.

vi /etc/fstab/dev/mapper/vg_bkjia-lv_u01      /u01                    ext4    defaults        1 1/dev/mapper/vg_bkjia-lv_data      /data                    ext4    defaults        1 1
Ii. lv resizing:

Method 1: Increase 5 GB directly and write "+ 5 GB"
1. lv expansion 5 GB

lvresize -L +5G /dev/mapper/vg_bkjia-lv_root

2. File System size change

resize2fs /dev/mapper/vg_bkjia-lv_root

Method 2: It turns out to be 10 Gb. Increasing 5 GB is "15 GB"
1. lv expansion to 15 GB

lvresize -L 15G /dev/mapper/vg_bkjia-lv_u01

2. File System size change

resize2fs  /dev/mapper/vg_bkjia-lv_u01

Note: The preceding lvresize command can also be implemented using the lvextend command.

Iii. lv reduction:

1. Uninstall the directory first.

umount /u01

2. Whether this step is determined based on the execution result returned by the next step. See the example below.

e2fsck -f /dev/mapper/vg_bkjia-lv_u01

3. File System size change

resize2fs  /dev/mapper/vg_bkjia-lv_u01 10G

4. lv reduction

lvresize -L 10G /dev/mapper/vg_bkjia-lv_u01

5. Mount all directories recorded in/etc/fstab

mount -a

Appendix: an actual operation process for lv reduction:

[root@LINUXIDC-DB ~]# umount /u01[root@LINUXIDC-DB ~]# resize2fs  /dev/mapper/vg_bkjia-lv_u01 10Gresize2fs 1.41.12 (17-May-2010)Please run 'e2fsck -f /dev/mapper/vg_bkjia-lv_u01' first.[root@LINUXIDC-DB ~]# e2fsck -f /dev/mapper/vg_bkjia-lv_u01e2fsck 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/mapper/vg_bkjia-lv_u01: 12/983040 files (0.0% non-contiguous), 100865/3932160 blocks[root@LINUXIDC-DB ~]# resize2fs  /dev/mapper/vg_bkjia-lv_u01 10Gresize2fs 1.41.12 (17-May-2010)Resizing the filesystem on /dev/mapper/vg_bkjia-lv_u01 to 2621440 (4k) blocks.The filesystem on /dev/mapper/vg_bkjia-lv_u01 is now 2621440 blocks long.[root@LINUXIDC-DB ~]# lvresize -L 10G /dev/mapper/vg_bkjia-lv_u01  WARNING: Reducing active logical volume to 10.00 GiB  THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce lv_u01? [y/n]: y  Size of logical volume vg_bkjia/lv_u01 changed from 15.00 GiB (3840 extents) to 10.00 GiB (2560 extents).  Logical volume lv_u01 successfully resized[root@LINUXIDC-DB ~]# mount -a[root@LINUXIDC-DB ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/vg_bkjia-lv_root                       15G  1.8G   13G  13% /tmpfs                 499M     0  499M   0% /dev/shm/dev/sda1             190M   36M  145M  20% /boot/dev/mapper/vg_bkjia-lv_data                      9.8G   23M  9.2G   1% /data/dev/mapper/vg_bkjia-lv_u01                      9.8G   23M  9.2G   1% /u01[root@LINUXIDC-DB ~]#

Similarly, the lvreduce command can reduce the lv.
The lvresize Command actually contains the functions of lvextend and lvreduce.

-- Swap extensions managed by LVM, such as increasing by 1024 M:

[Root @ bkjia-DB ~] # Swapoff/dev/mapper/vg_bkjia-lv_swap

[Root @ bkjia-DB ~] # Lvextend-L + 1024 m/dev/mapper/vg_bkjia-lv_swap

[Root @ bkjia-DB ~] # Mkswap/dev/mapper/vg_bkjia-lv_swap

[Root @ bkjia-DB ~] # Swapon/dev/mapper/vg_bkjia-lv_swap

This article permanently updates the link address:

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.