Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to reduce the root directory of XFS partition format by Centos8

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to reduce the root directory of XFS partition format by Centos8". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

System environment

Centos8

Current system partition layout

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

Backup data

Be sure to back up important data before reducing partitions. If there is a problem, you can restore the data.

Note: an additional hard disk needs to be added to the server to back up the system partition.

Enter rescue mode

In VMware Workstation, load the CD and turn on the machine. Press F2 to start up, enter BIOS, and switch to the Boot tab. Move the CD-ROM Drive to the Hard Drive. Press F10 to save and restart.

Select Troubleshooting, and then select enter rescue mode.

When entering the interface below, select 3 to go directly to the shell interface.

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

# ls-al / mnt/sysimage/ activate logical volume group

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

# vgchange-ay 2 logical volume (s) in volume group "cl" now active# vgs VG # PV # LV # SN Attr VSize VFree cl 120 wz--n- mount system partition 3 and partition used to back up data

Starting with the backup, we need to mount the logical volume in a location. By temporarily mounting it, we can back up the / partition to any other location and need to access it when we perform the restore.

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

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

Use xfsdump backup / partition

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

When dump uses level 0 (backup all files), we will be prompted for the backup session label and media label, and we can avoid prompts by adding-L and-M to the following with the option-f:

The backup level of-l 0 is set to level 0, which means that all files will be backed up. -L specifies the label of the backup session-M specifies the label of the first media-f specifies the backup destination file. Unmount the file system

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

# umount / mnt/sysimage/root/ reduction / partition

Use the lvremove command to delete the logical volume and use lvcreate to create a new volume.

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

After that, create the required logical volume size, and then create a logical volume size of 15G.

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

Use-Zy to zero the pre-4KiB data in the new logical volume.

Create a new XFS partition # mkfs.xfs / dev/cl/root

Mount and restore data

When 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 previously backed up data:

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

Reboot into the system to check if it is normal. Disconnect the optical drive of the virtual machine, press F2 to boot, enter BIOS, set the boot order, put the hard disk on the first boot, and save and restart F10:

After entering the system, check to see if the partition size is reduced:

[root@localhost] # df-hT / Filesystem Type Size Used Avail Use% Mounted on/dev/mapper/cl-root xfs 15G 1.7g 14G 11% / "how Centos8 reduces the root directory of XFS partition format" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report