How to divide the home space to root under CentOS

Time:2020-2-12

The following operation is completed through actual operation.

The following example tries to divide 5g of 20g of home space into root space

[[email protected] ~]# df -h

File system capacity used available used%% mount point

/dev/mapper/VolGroup-lv_root

                       75G   50G  22G  70% /

tmpfs                 3.9G   88K 3.9G   1% /dev/shm

/dev/sda1             485M   30M 430M   7% /boot

/dev/mapper/VolGroup-lv_home

                       20G  174M  19G   1% /home

[[email protected] ~]# umount /home

[[email protected] ~]# e2fsck -f/dev/mapper/VolGroup-lv_home

e2fsck 1.41.12 (17-May-2010)

Step 1: check inode, block, and size

Step 2: check the directory structure

Step 3: check directory connectivity

Pass 4: Checking reference counts

Step 5: check the cluster profile

/dev/mapper/VolGroup-lv_home: 158/1310720files (0.0% non-contiguous), 126581/5242880 blocks

[[email protected] ~]# resize2fs -p/dev/mapper/VolGroup-lv_home 15G

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on/dev/mapper/VolGroup-lv_home to 3932160 (4k) blocks.

Begin pass 3 (max = 160)

Scanning inode table xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The filesystem on/dev/mapper/VolGroup-lv_home is now 3932160 blocks long.

[[email protected] ~]# mount /home

[[email protected] ~]# df -h

File system capacity used available used%% mount point

/dev/mapper/VolGroup-lv_root

                       75G   50G  22G  70% /

tmpfs                 3.9G   88K 3.9G   1% /dev/shm

/dev/sda1             485M   30M 430M   7% /boot

/dev/mapper/VolGroup-lv_home

                       15G  170M  14G   2% /home

[[email protected] ~]#  lvreduce -L 15G /dev/mapper/VolGroup-lv_home

WARNING: Reducing active and open logical volume to 15.00 GiB

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce lv_home?[y/n]: y

Reducing logical volume lv_home to 15.00 GiB

Logical volume lv_home successfully resized

[[email protected] ~]# vgdisplay

—Volume group —

VGName               VolGroup

System ID            

Format                lvm2

Metadata Areas        1

Metadata Sequence No  7

VGAccess             read/write

VGStatus             resizable

MAXLV                0

CurLV                3

Open LV               3

MaxPV                0

CurPV                1

ActPV                1

VGSize               99.51 GiB

PESize               4.00 MiB

Total PE              25474

Alloc PE / Size       24194 /94.51 GiB

Free  PE / Size       1280 / 5.00 GiB

VGUUID              cxzV5u-cG1f-HvPd-pE8c-eKrR-dBjN-H07k3I

[[email protected] ~]# lvextend -L +5.00G/dev/mapper/VolGroup-lv_root

Extending logical volume lv_root to 80.57 GiB

Logical volume lv_root successfully resized

[[email protected] ~]# resize2fs -p/dev/mapper/VolGroup-lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/mapper/VolGroup-lv_rootis mounted on /; on-line resizing required

old desc_blocks = 5, new_desc_blocks = 6

Performing an on-line resize of/dev/mapper/VolGroup-lv_root to 21121024 (4k) blocks.

The filesystem on/dev/mapper/VolGroup-lv_root is now 21121024 blocks long.

[[email protected] ~]# df -h

File system capacity used available used%% mount point

/dev/mapper/VolGroup-lv_root

                       80G   50G  27G  66% /

tmpfs                 3.9G   88K 3.9G   1% /dev/shm

/dev/sda1             485M   30M 430M   7% /boot

/dev/mapper/VolGroup-lv_home

                       15G  170M  14G   2% /home