Centos/Ubuntu Linux 系统 根目录扩容方法
一、背景
系统根目录空间少或者是通过模板做出来机器,只能按当初模板设置好的大小,超出了大小就需要给根目录做扩容
二、扩容方法
2.1、查看系统盘
- 可以看到 vda 是 200G vda2 根分区是 99G 因为机器是通过模板部署出来的
root@aka:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 252:16 0 64M 0 disk
└─vdb1 252:17 0 63M 0 part
sr0 11:0 1 1024M 0 rom
vda 252:0 0 200G 0 disk
├─vda2 252:2 0 99G 0 part
│ ├─centos-swap 253:1 0 2G 0 lvm
│ └─centos-root 253:0 0 97G 0 lvm /
└─vda1 252:1 0 1G 0 part /boot
2.2、创建分区
- 1、创建主分区
- 2、修改分区格式
- 3、保存分区
- 4、重启系统
root@aka:~$ fdisk /dev/vda
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.
# 输入 n 创建分区
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
# 输入 p 创建主分区
Select (default p): p
# 根据提示输入,不确定下面直接回车也行,因为只能穿件4个主分区已经创建2和主分区,那么现在是第3个主分区,使用我填的是3
Partition number (3,4, default 3): 3
First sector (209715200-419430399, default 209715200):
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-419430399, default 419430399):
Using default value 419430399
Partition 3 of type Linux and of size 100 GiB is set
# 更改分区格式
Command (m for help): t
# 输入刚才创建分区,1-3说明已经有3个主分区,第三个就是刚刚创建的所以输入 3
Partition number (1-3, default 3): 3
# 输入 8e 将分区改为 Linux LVM
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
# 打印创建好的分区 /dev/vda3 就是刚刚创建好的分区
Command (m for help): p
Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000afaac
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 209715199 103808000 8e Linux LVM
/dev/vda3 209715200 419430399 104857600 8e Linux LVM
# 输入 w 保存分区,下面报错信息没关系
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
2.3、创建物理卷
- 创建好的分区必须要重启系统才可以下面步骤
- 已知 /dev/vda3 是刚刚创建好的分区
root@aka:~$ pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created
2.4、查看新建的物理卷和大小
- 记住需要扩展的分区 /dev/vda2
- VG Name 为 centos
root@aka:~$ pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25343
Free PE 1
Allocated PE 25342
PV UUID n1wTfe-5Meu-I0tc-Xmzk-ylLB-aGXM-8fL4eq
"/dev/vda3" is a new physical volume of "100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size 100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID eL8EFo-CAqp-jJea-R9jS-rfEM-bMH0-RWkf9T
2.5、添加物理卷组
- 记住需要扩展的分区 /dev/vda2
- VG Name 为 centos
- 将 /dev/vda3 添加到 centos 卷上
root@aka:~$ vgextend centos /dev/vda3
Volume group "centos" successfully extended
2.6、查看卷组信息
root@aka:~$ vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 198.99 GiB
PE Size 4.00 MiB
Total PE 50942
Alloc PE / Size 25342 / 98.99 GiB
Free PE / Size 25600 / 100.00 GiB
VG UUID tzm4di-Vz3A-cNQa-fjdS-bHaV-5FJW-PnVlAG
2.7、卷组扩容
- /dev/mapper/centos-root 通过 df -h 看看系统根目录,这个是啥就填写啥
- 使用 lvextend -l +100%FREE /dev/mapper/centos-root 将空间全部扩容到 /dev/mapper/centos-root 逻辑卷中
root@aka:~$ lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from <97.00 GiB (24831 extents) to <197.00 GiB (50431 extents).
Logical volume centos/root successfully resized
2.8、查看文件系统
- 这里有个区别 需要自己看自己文件系统是啥 ext4 和 xfs
- 我这里文件系统是 xfs
root@aka3:~$ cat /etc/fstab
/dev/mapper/centos-root / xfs defaults 0 0
UUID=ddb55cda-6a30-41af-9f0c-acb092eb7178 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
2.9、刷新文件系统使扩容生效
- 注意:如果文件系统是 ext4 格式用 resize2fs ,我这里是 xfs 格式用 xfs_growfs
1) xfs 文件系统方法
root@aka:~$ xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=6356736 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25426944, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=12415, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25426944 to 51641344
2) ext4 文件系统方法
resize2fs /dev/mapper/centos-root
2.10、查看扩容是否成功
- 到这里扩容完成
root@aka:~$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 12G 9.6M 12G 1% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/mapper/centos-root 197G 15G 183G 8% /
/dev/vda1 1014M 201M 814M 20% /boot
版权声明:
作者:Akiraka
链接:https://www.akiraka.net/linux/861.html
来源:Akiraka
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
海报
Centos/Ubuntu Linux 系统 根目录扩容方法
一、背景
系统根目录空间少或者是通过模板做出来机器,只能按当初模板设置好的大小,超出了大小就需要给根目录做扩容
二、扩容方法
2.1、查看系统盘
可以看到……
文章目录
关闭