In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
When we install the system, due to the lack of reasonable allocation of partition space, in the follow-up maintenance process, we found that some partition space is not used enough, while some partition space has a lot of remaining space. If these partitions use lvm when installing the system (provided that these partitions are lvm logical volume partitions), then you can easily expand or scale down! Different file system types have different creation, check and adjustment commands. Here is a record of the expansion and reduction of lvm partition space of xfs and ext2/3/4 file systems:
-
Special attention is paid to:
The resize2fs command is for ext2, ext3, and ext4 file systems. The xfs_growfs command is for xfs file systems.
-
1) the adjustment command for ext2/ext3/ext4 file system is resize2fs (both increase and decrease are supported)
Lvextend-L 120g / dev/mapper/centos-home / / increase to 120Glvextend-L + 20g / dev/mapper/centos-home / / increase 20Glvreduce-L 50g / dev/mapper/centos-home / / decrease to 50Glvreduce-L-8G / dev/mapper/centos-home / / decrease 8Gresize2fs / dev/mapper/centos-home / / perform adjustment
2) the adjustment command for xfs file system is xfs_growfs (only growing is supported)
Lvextend-L 120g / dev/mapper/centos-home / / increase to 120Glvextend-L + 20g / dev/mapper/centos-home / / add 20Gxfs_growfs / dev/mapper/centos-home / / perform adjustment
That is to say: the xfs file system only supports the increase of partition space, not the reduction of the partition space (remember! ).
If you want to reduce it, you can only mount the logical partition by reformatting it with the mkfs.xfs command after the reduction, so that the original data on the logical partition is lost. If there are important documents, then stop eating.
Example 1 (when there is free space on the system)
1) View the partition space. This is the xfs file system (the file format can be seen by the-T parameter of df).
[root@localhost ~] # df-hT File system Type capacity available available mount point / dev/mapper/centos-root xfs 200G 2.2G 198G 2% / devtmpfs devtmpfs 32G 032G 0% / devtmpfs tmpfs 32G 032G 0% / dev/shmtmpfs tmpfs 32G 49M 32G 1% / runtmpfs tmpfs 32G 032G 0% / sys/fs/cgroup/dev/sda1 xfs 197m 139m 59m 71% / boottmpfs tmpfs 6.3G 0 6.3G 0% / run/user/0/dev/mapper/centos-home xfs 628G 33m 718G 1% / home
2) use the vgdisplay command to view the free space on the system
Root@localhost ~] # vgdisplay-Volume group-VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 930.80 GiB PE Size 4.00 MiB Total PE 238285 Alloc PE / Size 212736 / 831.00 GiB Free PE / Size 25549 / 99.80 GiB / / this item indicates that it still exists on the system. In 99.80g of free space (25549) VG UUID a5hiAh-LB8M-9lRv-Ps1a-z35L-J4fk-sP3KrF
3) add or subtract 90g of the free space found above to the / home partition
[root@localhost] # lvextend-L + 90G / dev/mapper/centos-home / / or use the-l parameter (with the number of PE), that is, lvextend-l + 25500 / dev/mapper/centos-home Size of logical volume centos/home changed from 628.00 GiB (160768 extents) to 718.00 GiB (183808 extents). Logical volume centos/home successfully resized. [root@localhost] # xfs_growfs / dev/mapper/centos-homemeta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=41156608 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=164626432, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal bsize=4096 blocks=80384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0, rtextents=0data blocks changed from 164626432 to 188219392
4) look at the system partition again and find that the home partition has been increased by 90G (after this increase, the data before the home partition will not be lost)
[root@localhost ~] # df-h File system capacity used available mount point / dev/mapper/centos-root 200G 2.2G 198G 2% / devtmpfs 32G 032G 0% / devtmpfs 32G 032G 0% / dev/shmtmpfs 32G 49M 32G 1% / runtmpfs 32G 032G 0% / sys/fs/cgroup/dev/sda1 197m 139m 59m 71% / boottmpfs 6.3G 0 6.3G 0 % / run/user/0/dev/mapper/centos-home 718G 33m 718G 1% / home
Although the xfs file system only supports increments, not decreases. But this does not mean that it cannot be reduced under the xfs system file, but after the reduction, it needs to be reformatted before it can be mounted. In this way, the original data is lost!
Example 2: this situation only applies when the system has just been installed and there is no data or data in the logical partition that is not important and can be deleted or copied.
After the system is installed, it is found that the home partition is too large. I want to take 100g out of the home partition to / partition.
[root@localhost ~] # df-hT File system Type capacity available available mount point / dev/mapper/centos-root xfs 205G 2.2G 203G 2% / devtmpfs devtmpfs 32G 032G 0% / devtmpfs tmpfs 32G 032G 0% / dev/shmtmpfs tmpfs 32G 49M 32G 1% / runtmpfs tmpfs 32G 032G 0% / sys/fs/cgroup/dev/sda1 xfs 197m 139m 59m 71% / boottmpfs tmpfs 6.3G 0 6.3G 0% / run/user/0/dev/mapper/centos-home xfs 718G 33M 718G 1% / home [root@localhost ~] # umount / home/ [root@localhost ~] # lvreduce-L-100G / dev/mapper/centos-home WARNING: Reducing active logical volume to 618.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce centos/home? Y Size of logical volume centos/home changed from 718.00 GiB (183808 extents) to 618.00 GiB (158208 extents). Logical volume centos/home successfully resized.
As follows, it is obvious that the xfs file system cannot perform partition reduction adjustments!
[root@localhost ~] # xfs_growfs / dev/mapper/centos-homexfs_growfs: / dev/mapper/centos-home is not a mounted XFS filesystem [root@localhost ~] # mount / dev/mapper/centos-home / home/mount: / dev/mapper/centos-home: cannot read super block
In this way, you can only reformat the partition and mount it to home again after formatting.
[root@localhost ~] # mkfs.xfs / dev/mapper/centos-home-fmeta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=41156608 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=164626432, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=80384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0, rtextents=0 [root@localhost ~] # mount / dev/mapper/centos-home / home/
When you look at the partition again, you can see that the home partition has been reduced by 100G, but there is no previous data in this partition.
[root@localhost ~] # df-hT File system Type capacity available available mount point / dev/mapper/centos-root xfs 205G 2.2G 203G 2% / devtmpfs devtmpfs 32G 032G 0% / devtmpfs tmpfs 32G 032G 0% / dev/shmtmpfs tmpfs 32G 49M 32G 1% / runtmpfs tmpfs 32G 032G 0% / sys/fs/cgroup/dev/sda1 xfs 197m 139m 59m 71% / boottmpfs Tmpfs 6.3G 0 6.3G 0% / run/user/0/dev/mapper/centos-home xfs 618G 73M 578G 1% / home
When reformatting above, you can also format this into ext4 format.
[root@localhost ~] # mkfs.ext4 / dev/mapper/centos-home [root@localhost ~] # cat / etc/fstab / / change the xfs in the boot mount setting of the home partition to ext4
Then put the 100g taken out from home partition above into / partition.
[root@localhost] # vgdisplay-Volume group-VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 9 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 930.80 GiB PE Size 4.00 MiB Total PE 238285 Alloc PE / Size 211456 / 826.00 GiB Free PE / Size 26829 / 104.80 GiB VG UUID a5hiahashi SP3KrF [root@localhost] # lvextend-L + 100G / dev/mapper/centos-root Size of logical volume centos/root changed from 205.00 GiB (52480 extents) to 305.00 GiB (78080 extents). Logical volume centos/root successfully resized. [root@localhost ~] # xfs_growfs / dev/mapper/centos-rootmeta-data=/dev/mapper/centos-root isize=256 agcount=5, agsize=13107200 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 spinodes=0data = bsize=4096 blocks=53739520, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=0log = internal bsize=4096 blocks=25600, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0 Rtextents=0data blocks changed from 53739520 to 79953920 [root@localhost ~] # df-hT File system Type capacity available available mount point / dev/mapper/centos-root xfs 305G 2.2G 203G 2% / devtmpfs devtmpfs 32G 032G 0% / devtmpfs tmpfs 32G 032G 0% / dev/shmtmpfs tmpfs 32G 49M 32G 1% / runtmpfs tmpfs 32G 032G 0% / sys/fs/cgroup/dev/sda1 xfs 197m 139m 59m 71% / boottmpfs tmpfs 6.3G 0 6.3G 0% / run/user/0/dev/mapper/centos-home xfs 618G 73M 578G 1% / hom
-warm reminder-
If you reduce the partition space, you must uninstall the partition before reducing it. If the problem is unloaded, the solution is as follows:
[root@localhost ~] # umount / home/umount: / home: device is busy. (In some cases useful info about processes that usethe device is found by lsof (8) or fuser (1))
If the prompt cannot be uninstalled, the / home is occupied by a process. Use the following command to terminate the occupied process:
[root@localhost] # fuser-m-k / home/home: 1409 1519ce 1531e 1532e 1533e 1535e 1536e 1537e 1538e 1539e 1541e 1543e 1544e 1546e 1547e 1548e 154950e 1601m
Uninstall the home partition again and it will be successful.
[root@localhost ~] # umount / home/
-k means to automatically kill the process occupying the home partition!
If you are not sure whether to kill all the programs that occupy the device, you can also add a-I parameter, so that you will be asked before each program is killed! (i.e. fuser-m-v-I-k / home)
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.