Shrink ext2 ext3 and ext4 file system and reduce the size of a logical volume with only one command.

preview_player
Показать описание
Shrink ext2 ext3 and ext4 file system and reduce the size of a logical volume with only one command in Linux.

Red Hat Enterprise Linux v7, RHCSA EX200 exam task: reduce the size of a file system.

Reducing or increasing the size of a file system is one of the RHCSA exam tasks so you have 50% chance that you will get file system shrinking task on your EX200 exam.

If you will be shrinking file system in your production Environment in work there are two things which you have to consider:

1) File system type musts support shrinking - XFS which is the default file system in Red Hat 7 does not support shrinking at all.
2) ext2, ext3 and ext4 file systems must be unmounted during shrinking. ext2, ext3 and ext4 file systems don't support on-line shrinking.

Also best practise is to have up to date backup before you perform file system shrinking. On your RHCSA exam you will have to shrink file system which will be very small in size so copy data to some other file system on your exam will be very quick and command like "cp -av" will do the job. And even in unlikely case if you loose the file system you can easily recreate it with smaller requested size - restore files from backup and you will get full points for this task on your RHCSA exam.

Our given task is to shrink file system /u03 to 1GB.
----------------------------------------------------
1) Verify the file system size and file system utilization:
df -h /u03
So we are going to reduce the size of a file system /u03 from 4GB to 1GB.

2)Verify what is the file system type.
mount | grep u03
file system type is ext4 which supports shrinking.

3) Command to reduce the size of a logical volume together with a size of file system.
lvresize -L 1G -r /dev/mapper/datavg-lv_u03

where:
-L (upper case L) 1G : will set the size of logical volume to 1GB
you can use M for Megabytes or K for Kilobytes and so on ...

-r option will resize the file system together with the logical volume.

command "lvresize -L 1G -r /dev/mapper/datavg-lv_u03" performed following steps:
- unmounted our file system
- performed file system check
- shrank file system to 1GB
- and also reduced size of logical volume to 1GB as well.

4) Confirm the new size of a file system with command:
df -h /u03

Note: Some room is taken for a file system meta-data which is not any problem at all on your RHCSA exam.

Related Video Tutorials:
RHCSA Fast Track course:
Reset forgotten root password in Redhat 7:

Network Interface naming convention in Red Hat 7:

Setting up network without NetworkManager in Redhat 7:

Setting up network using NetworkManager and network scripts in Redhat 7:

Setting up network using a NetworkManager text user interface (nmtui) in Red Hat 7 - EASY!!!

Setting up network in Red Hat 7 in less than a minute - QUICK & EASY!!!

Setting up network using a NetworkManager command line interface (nmcli) in Red Hat 7

nmcli cheat! Setting up network using nmcli in Red Hat 7 in less than a 30 seconds - QUICK & EASY!!!

Setting up network using a NetworkManager connection editor GUI tool in Red Hat 7 - EASY!!!

The Complete Beginners Guide to Linux Network Configuration - GUI & Easy!

Shrink ext2 ext3 and ext4 file system and reduce the size of a logical volume with only one command.

Complete guide to file system shrinking and reducing the size of the underlying logical volume.

Other related video tutorials:
Calculate netmask, network and broadcast address - EASY!:

NetworkManager connection priority - manage network profile priority in Linux:

RHCE EX300 exam:
RHCE EX300 exam: Configure an iSCSI target on Red Hat Enterprise Linux
===
I am currently working on:

Shrink ext2 ext3 and ext4 file system and recreate underlying disk partition with smaller size.
Рекомендации по теме
Комментарии
Автор

Thank you for the excellent explanation. I will be doing a shrinking as well on my system but mine is in TiB so I think it will take a much longer time. I can see lvreduce along with the -r option will resize both FS and LV at the same time and that the command will automatically unmount/remount the FS once successful . Thank you for the video.

grailph