How to reduce the root directory of XFS partition format in Linux

How to reduce the root directory of XFS partition format in Linux

Preface

This article describes how to shrink the​ / ​​​​directory of an XFS partition. If you need to shrink the XFS file system on a logical volume, you need to back up, restore, and recreate the logical volume to achieve it.

System environment

CentOS 8

Current system partition layout

This is the current file system layout. The current mount point / capacity is 17G. Our aim is to reduce / capacity.

How to reduce the root directory of an XFS partition?

Backing up your data

Be sure to back up important data before shrinking the partition. If something goes wrong, you can restore the data.

Note: You need to add an extra hard disk to the server to back up the system partition.

Enter rescue mode

In VMware Workstation, load the CD and start the machine. Press F2 when booting, enter BIOS, and switch to the Boot tab. Move the CD-ROM Drive to the Hard Drive. Press F10 to save and reboot.

How to reduce the root directory of XFS partition format_Logical Volume_02

Select Troubleshooting, then choose Enter Rescue Mode.

How to reduce the root directory of XFS partition format_Logical Volume_03

How to reduce the root directory of XFS partition format_Logical Volume_04

When you enter the following interface, select 3 to enter the shell interface directly.

How to reduce the root directory of XFS partition format_html_05

After entering the rescue mode, you can see that the /mnt/sysimage directory does not have a mounted system partition.

# ls -al /mnt/sysimage/ 

How to reduce the root directory of XFS partition format_html_06

Activate Logical Volume Group

Before mounting the partition, you need to activate the logical volume. To activate the volume group:

# vgchange -ay 2 logical volume(s) in volume group "cl" now active # vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 wz--n- <19.00g 0 

How to reduce the root directory of XFS partition format_Logical Volume_07

Mount the system partition and the partition used to backup data

First starting with the backup, we need to mount the logical volume somewhere. By temporarily mounting it we can back up ​/​ partition to any other location and need to access it when performing a restore.

Now, create two directories under /mnt/sysimage/. One to mount the actual ​/​ partition of this server, and the other will be used to store backups of ​/​ partition.

# mkdir /mnt/sysimage/root # mkdir /mnt/sysimage/backup # mount /dev/cl/root /mnt/sysimage/root # mount /dev/sda /mnt/sysimage/backup/ 

How to reduce the root directory of XFS partition format_Logical Volume_08

Backing up the / partition using xfsdump

Perform the backup by running ​xfsdump​ .

# xfsdump -l 0 -L "root lv backup" -M "backup" -f /mnt/sysimage/backup/root_backup.img /mnt/sysimage/root 

How to reduce the root directory of XFS partition format

When dump uses level 0 (backing up all files), you will be prompted for a backup session label and a media label. We can avoid this prompt by adding -L and -M to the following -f :

​-l 0​​​ Set the backup level to 0. Level 0 means all files will be backed up.

​-L​ Specifies the label for the backup session

​-M​ specifies the label of the first medium

​-f​ specifies the backup destination file.

Unmounting the file system

Once the backup is complete, we can unmount the file system.

# umount /mnt/sysimage/root/

Reduction/Partitioning

Use the ​lvremove​ command to remove logical volumes and use ​lvcreate​ to create new volumes.

# lvremove /dev/cl/root Do you really want to remove active logical volume cl/root? [y/n]: y Logical volume "root" successfully removed 

How to reduce the root directory of XFS partition format_Logical Volume_10

After that, create the required logical volume size. Below we create a logical volume of size 15G.

# lvcreate -Zy -L 15G -n root cl 

How to reduce the root directory of XFS partition format

Use -Zy to zero out the first 4KiB of data in the new logical volume.

Create a New XFS Partition

# mkfs.xfs /dev/cl/root 

How to reduce the root directory of XFS partition format_File system_12

Mount and restore data

Once the file system is ready, mount it in the /mnt/sysimage/root directory:

# mount /dev/cl/root /mnt/sysimage/root/

Use the ​xfsrestore​ command to restore the previously backed up data:

# xfsrestore -f /mnt/sysimage/backup/root_backup.img /mnt/sysimage/root 

How to reduce the root directory of XFS partition format_logical volume_13

Restart the system and check whether it is normal. Disconnect the CD-ROM drive of the virtual machine, press F2 to start the computer, enter BIOS, set the boot order, put the hard disk in the first boot, press F10 to save and restart:

How to shrink the root directory of an XFS partition

After entering the system, check whether the partition size has been reduced:

[root@localhost ~]# df -hT / Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 15G 1.7G 14G 11% / 

How to reduce the root directory of an XFS partition

Summarize

That’s it, with the help of ​xfsdump​ and ​xfsrestore​ utilities, we have completed the work of shrinking XFS file systems and logical volumes.

This is the end of this article about reducing the root directory of the XFS partition format in Linux. For more relevant content about reducing the root directory of the XFS partition format in Linux, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Tutorial on adjusting the size of lvm logical volume partition in Linux (for different file systems such as xfs and ext4)
  • Using XFS file system in Linux environment

<<:  Let IE support CSS3 Media Query to achieve responsive web design

>>:  Detailed explanation of angular content projection

Recommend

A simple LED digital clock implementation method in CSS3

This should be something that many people have do...

Detailed explanation of common methods of JavaScript arrays

Table of contents Common array methods pop() unsh...

Docker installation and configuration steps for RabbitMQ

Table of contents Single-machine deployment Onlin...

Specific method to delete mysql service

MySQL prompts the following error I went to "...

HTML table markup tutorial (16): title horizontal alignment attribute ALIGN

By default, the table title is horizontally cente...

mySql SQL query operation on statistical quantity

I won't say much nonsense, let's just loo...

Complete step record of vue encapsulation TabBar component

Table of contents Implementation ideas: Step 1: C...

The most comprehensive explanation of the locking mechanism in MySQL

Table of contents Preface Global Lock Full databa...

Use the more, less, and cat commands in Linux to view file contents

In Linux, the commands cat, more, and less can al...

A detailed introduction to the CSS naming specification BEM from QQtabBar

BEM from QQtabBar First of all, what does BEM mea...

10 Popular Windows Apps That Are Also Available on Linux

According to data analysis company Net Market Sha...

JS, CSS style reference writing

CSS: 1. <link type="text/css" href=&q...