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

Basic tutorial on controlling Turtlebot3 mobile robot with ROS

Chinese Tutorial https://www.ncnynl.com/category/...

A brief introduction to Tomcat's overall structure

Tomcat is widely known as a web container. It has...

25 Ways and Tips to Increase Web Page Loading Speed

Introduction <br />Not everyone has access t...

Detailed explanation of JavaScript function introduction

Table of contents Function Introduction function ...

Detailed explanation of the use of bus in Vue

Vue bus mechanism (bus) In addition to using vuex...

Vue implements drag progress bar

This article example shares the specific code of ...

VUE implements a Flappy Bird game sample code

Flappy Bird is a very simple little game that eve...

Example of how rem is adapted for mobile devices

Preface Review and summary of mobile terminal rem...

MySQL variable declaration and stored procedure analysis

Declaring variables Setting Global Variables set ...

Tools to convert static websites into RSS

<br /> This article is translated from allwe...

10 Website Usability Tips Everyone Should Know

Let’s not waste any more time and get straight to...

Analysis of the use of Linux vulnerability scanning tool lynis

Preface: Lynis is a security audit and hardening ...

Solve the problem of docker log mounting

The key is that the local server does not have wr...