zl程序教程

您现在的位置是:首页 >  系统

当前栏目

linux centos7完整记录对根目录的磁盘扩容过程(扩容99G)

Linuxcentos7 过程 记录 完整 磁盘 扩容 根目录
2023-09-14 09:01:52 时间

改变磁盘大小之后需要重启才能生效。

[root@k8s-nfs ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk 
sda               8:0    0  200G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part 
  ├─centos-root 253:0    0   88G  0 lvm  /
  ├─centos-swap 253:1    0 1016M  0 lvm  
  └─centos-home 253:2    0   10G  0 lvm  /home
sr0              11:0    1 1024M  0 rom  
[root@k8s-nfs ~]# 
[root@k8s-nfs ~]# 
[root@k8s-nfs ~]# 
[root@k8s-nfs ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): 
Using default response p
分区号 (3,4,默认 3):
起始 扇区 (209715200-419430399,默认为 209715200):
将使用默认值 209715200
Last 扇区, +扇区 or +size{K,M,G} (209715200-419430399,默认为 419430399):+100G
值超出范围。
Last 扇区, +扇区 or +size{K,M,G} (209715200-419430399,默认为 419430399):+99G
分区 3 已设置为 Linux 类型,大小设为 99 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@k8s-nfs ~]# partprobe 
[root@k8s-nfs ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk 
sda               8:0    0  200G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   99G  0 part 
│ ├─centos-root 253:0    0   88G  0 lvm  /
│ ├─centos-swap 253:1    0 1016M  0 lvm  
│ └─centos-home 253:2    0   10G  0 lvm  /home
└─sda3            8:3    0   99G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@k8s-nfs ~]# lvm
lvm> pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  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               efjCC5-9SmV-uA13-o0vW-uumQ-HuE2-VvvsEw
   
  "/dev/sda3" is a new physical volume of "99.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               99.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               yyfutw-19wS-Jegf-SX8Q-IAY0-4fZQ-R1qsHW
   
lvm> vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               sv7bTd-obHA-xJwy-YvzC-f0NV-v8xG-rwmfiK
   
lvm> vgextend centos /dev/sda3
  Volume group "centos" successfully extended
lvm> vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               197.99 GiB
  PE Size               4.00 MiB
  Total PE              50686
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       25344 / 99.00 GiB
  VG UUID               sv7bTd-obHA-xJwy-YvzC-f0NV-v8xG-rwmfiK
   
lvm> lvextend -l +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from 88.00 GiB (22528 extents) to 187.00 GiB (47872 extents).
  Logical volume centos/root successfully resized.
lvm> ^C
[root@k8s-nfs ~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=5767168 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=23068672, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=11264, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 23068672 to 49020928
[root@k8s-nfs ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 7.9G     0  7.9G    0% /dev
tmpfs                    7.9G     0  7.9G    0% /dev/shm
tmpfs                    7.9G  8.9M  7.9G    1% /run
tmpfs                    7.9G     0  7.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root  187G  2.6G  185G    2% /
/dev/sda1               1014M  137M  878M   14% /boot
/dev/mapper/centos-home   10G   33M   10G    1% /home
tmpfs                    1.6G     0  1.6G    0% /run/user/0
[root@k8s-nfs ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk 
sda               8:0    0  200G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   99G  0 part 
│ ├─centos-root 253:0    0  187G  0 lvm  /
│ ├─centos-swap 253:1    0 1016M  0 lvm  
│ └─centos-home 253:2    0   10G  0 lvm  /home
└─sda3            8:3    0   99G  0 part 
  └─centos-root 253:0    0  187G  0 lvm  /
sr0              11:0    1 1024M  0 rom  
[root@k8s-nfs ~]#

参考链接:
https://blog.csdn.net/qq_24871519/article/details/86243571
https://blog.csdn.net/harryxxxxx/article/details/81114613
https://blog.csdn.net/nimasike/article/details/53729499