实际应用中发现root目录下的磁盘空间消耗比较大,本篇文章记录下给root目录磁盘增加存储空间的过程。
操作演示环境为CentOS、openEuler系统,其他操作系统例如中标麒麟(NeoKylin)也可作为参考。
操作系统版本如下
名称 | 版本 |
---|---|
CentOS | 7.6+ |
df -h 查看磁盘空间
可以看到 /dev/mapper/centos-root 只有72G的分配,而且已经使用了12G,日后使用肯定不够
[root@host ~]# df -H
Filesystem Size Used Avail Use% Mounted on
devtmpfs 34G 0 34G 0% /dev
tmpfs 34G 0 34G 0% /dev/shm
tmpfs 34G 18M 34G 1% /run
tmpfs 34G 0 34G 0% /sys/fs/cgroup
/dev/mapper/centos-root 72G 12G 61G 17% /
/dev/vda1 1.1G 182M 882M 18% /boot
tmpfs 6.8G 0 6.8G 0% /run/user/0
lsblk 查看磁盘状况
可以看到已经挂载了两个磁盘,分别是vda(100G)、vdb(2T),vda有2个分区
centos卷下的root已经分配了部分vda下的vda2分区存储空间,且整个vda已经没有额外空间可以分配
但vdb仍有2T存储空间可以使用
[root@host ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 99G 0 part
├─centos-root 253:0 0 67G 0 lvm /
└─centos-swap 253:1 0 32G 0 lvm [SWAP]
vdb 252:16 0 2T 0 disk
如果当前分区还有额外空间可以分配
可以直接参考2.2扩容
如果当前磁盘还有额外空间可以分区
可以直接参考2.1分区,没必要使用新磁盘分区
- 使用 fdisk vdb 指令对vdb磁盘分区
输入 m 查看帮助,可以看到具体指令详情
[root@host ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe6a957ff.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
- 输入 n 添加一个新的分区
输入 p 或者 直接回车 选择分区类型为primary
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
- 输入 1 或者 直接回车 选择分区号
接来下2步是选择分区开始和结束位置,这里也可以直接回车选择默认值
输入 t 改变分区格式
输入 L 展示分区格式列表
因为上面通过 lsblk 查看到 root 为 LVM 格式
这里继续输入 8e 选择分区格式为 Linux LVM
Partition number (1-4, default 1): 1
First sector (2048-4194303999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303999, default 4194303999):
Using default value 4194303999
Partition 1 of type Linux and of size 2 TiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
- 输入 w 保存
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
- lsblk 查看
可以看到 vdb 下 有了新的vdb1分区
[root@host ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 99G 0 part
├─centos-root 253:0 0 67G 0 lvm /
└─centos-swap 253:1 0 32G 0 lvm [SWAP]
vdb 252:16 0 2T 0 disk
└─vdb1 252:17 0 2T 0 part
- pvdisplay 查看
vda2的VG Name 为 centos卷
root在centos卷
因此需要将/dev/vdb1加入到centos卷里面去
[root@host ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25343
Free PE 0
Allocated PE 25343
PV UUID X3TDHh-Lh07-jHEi-UMSs-Z6cR-DDVX-BgqrvT
- 指令 vgextend centos /dev/vdb1
将新建的vdb1分区加入到centos卷
[root@host ~]# vgextend centos /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
Volume group "centos" successfully extended
- 扩充文件夹指令 lvextend -L +1T /dev/mapper/centos-root
这里我们选择root
[root@host ~]# lvextend -L +1T /dev/mapper/centos-root
Size of logical volume centos/root changed from <67.00 GiB (17151 extents) to <1.07 TiB (279295 extents).
Logical volume centos/root successfully resized.
- 扩充后正式分配空间指令 xfs_growfs /dev/mapper/centos-root
[root@host ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=4390656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=17562624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=8575, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 17562624 to 285998080
- df -H 再次查看 已经为 /dev/mapper/centos-root 1.2T
[root@host ~]# df -H
Filesystem Size Used Avail Use% Mounted on
devtmpfs 34G 0 34G 0% /dev
tmpfs 34G 0 34G 0% /dev/shm
tmpfs 34G 18M 34G 1% /run
tmpfs 34G 0 34G 0% /sys/fs/cgroup
/dev/mapper/centos-root 1.2T 12G 1.2T 2% /
/dev/vda1 1.1G 182M 882M 18% /boot
tmpfs 6.8G 0 6.8G 0% /run/user/0
- lsblk 再次确认查看 centos-root 已经在vdb1下
至此扩容完毕
[root@host ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 99G 0 part
├─centos-root 253:0 0 1.1T 0 lvm /
└─centos-swap 253:1 0 32G 0 lvm [SWAP]
vdb 252:16 0 2T 0 disk
└─vdb1 252:17 0 2T 0 part
└─centos-root 253:0 0 1.1T 0 lvm /
同理一样可以扩展其他目录
例如有的会有centos-home
一样可以扩展home