lvreduce ext4 example
An lvreduce ext4 example to show you how to shrink an ext4 filesystem? The example below is a quick guide with a basic safe approach to reducing the size of an logical volume. Hopefully the raw disk was used with pvcreate and not a partition. Doing so would defeat the purpose of having LVM, which is to use the “logical” portion of the volume manager. Growing and shrinking. When you are shrinking a filesystem under control of LVM, you have to tell the filesystem first that you want it to be smaller. And then you have to reduce the size of the logical volume. So below are the basic steps to reducing the size of an ext4 filesystem.
In this example, the /var/lib/mysql-data filesystem is too big. I need to take some of this space on that volume group and give to another lv. it is 170GB, and I want to shrink it to 100GB.
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-root-root_lv
2.0G 398M 1.5G 22% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
/dev/sda1 194M 48M 137M 26% /boot
/dev/mapper/vg-root-home_lv
485M 11M 449M 3% /home
/dev/mapper/vg-opt_lv
9.9G 611M 8.8G 7% /opt
/dev/mapper/vg-root-tmp_lv
2.9G 171M 2.6G 7% /tmp
/dev/mapper/vg-root-usr_lv
4.9G 2.8G 1.9G 61% /usr
/dev/mapper/vg-root-var_lv
2.0G 773M 1.1G 42% /var
/dev/mapper/vg-data-mysql-data_lv
183G 3.3G 170G 2% /var/lib/mysql-data
Unmount the filesystem
I use the unmount command to unmount the filesystem. Remember I sai safe way :)
# umount /var/lib/mysql-data
# e2fsck -f /dev/mapper/vg-data-mysql-data_lv
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg-data-mysql-data_lv: 68666/12124160 files (5.4% non-contiguous), 1623264/48496640 blocks
Resize the ext4 filesystem
Resize or shrink the ext4 filesystem
# resize2fs -p /dev/mapper/vg-data-mysql-data_lv 100G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg-data-mysql-data_lv to 26214400 (4k) blocks.
Begin pass 2 (max = 5713)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1480)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 1547)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg-data-mysql-data_lv is now 26214400 blocks long.
Shrink the Logical Volume
Resize or shrink the logical volume using the lvreduce command, which is part of the LVM suite of commands. We give the lvreduce command the size argument is Gigabits.
# lvreduce -L 100G /dev/mapper/vg-data-mysql-data_lv
WARNING: Reducing active logical volume to 100.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mysql-data_lv? [y/n]: y
Reducing logical volume mysql-data_lv to 100.00 GiB
Logical volume mysql-data_lv successfully resized
Remount the logical volume
# mount /var/lib/mysql-data
And now that the filesystem is remounted and no errors were seen, you can run the df comnand and see that the logical volume is now 100GB.
# df -h /var/lib/mysql-data
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg-data-mysql-data_lv
99G 3.3G 91G 4% /var/lib/mysql-data
It’s that easy. The only LVM on the market that is easier is ZFS which is a combination filesystem and LVM. A 2 for 1 type of deal. ZFS is king in my world. End of tangent.
'Operating System > LINUX' 카테고리의 다른 글
Ubuntu root 계정 활성화 (0) | 2019.03.04 |
---|---|
쉘스크립트 (0) | 2019.03.04 |
Custom Kernel on Fedora 20 (0) | 2019.03.04 |
Linux command (0) | 2019.03.04 |
Ubuntu Hostname 변경 (0) | 2019.03.04 |