Linux CentOS分区扩容

# /分区当前容量:
#根分区为lvm环境,lvm为/dev/mapper/centos-root,卷组为centos
[root@localhost ~]# df -hT
文件系统                    类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root     xfs        50G   46G  4.9G   91% /
devtmpfs                    devtmpfs   16G     0   16G    0% /dev
tmpfs                       tmpfs      16G     0   16G    0% /dev/shm
tmpfs                       tmpfs      16G  938M   15G    6% /run
tmpfs                       tmpfs      16G     0   16G    0% /sys/fs/cgroup
/dev/vda1                   xfs      1014M  286M  729M   29% /boot
/dev/mapper/vgdata1-lvdata1 xfs       6.0T  4.0T  2.0T   67% /data
/dev/mapper/centos-home     xfs        42G  799M   41G    2% /home
tmpfs                       tmpfs     3.2G   12K  3.2G    1% /run/user/42
tmpfs                       tmpfs     3.2G  4.0K  3.2G    1% /run/user/0
tmpfs                       tmpfs      60M     0   60M    0% /var/log/rtlog
#当前磁盘状态,vdc 100GB磁盘为新增磁盘
[root@localhost ~]# lsblk
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                   8:0    0 10.9T  0 disk 
└─sda1                8:1    0 10.9T  0 part 
sr0                  11:0    1  8.1G  0 rom  
vda                 252:0    0    4T  0 disk 
├─vda1              252:1    0    1G  0 part /boot
├─vda2              252:2    0   99G  0 part 
│ ├─centos-root     253:0    0   50G  0 lvm  /
│ ├─centos-swap     253:1    0  7.9G  0 lvm  [SWAP]
│ └─centos-home     253:3    0 41.1G  0 lvm  /home
└─vda3              252:3    0  1.9T  0 part 
  └─vgdata1-lvdata1 253:2    0  5.9T  0 lvm  /data
vdb                 252:16   0    4T  0 disk 
└─vdb1              252:17   0    4T  0 part 
  └─vgdata1-lvdata1 253:2    0  5.9T  0 lvm  /data
vdc                 252:32   0  100G  0 disk
#创建vdc分区
[root@localhost ~]# fdisk /dev/vdc
欢迎使用 fdisk (util-linux 2.23.2)。

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

Device does not contain a recognized partition table
使用磁盘标识符 0x7f8701c0 创建新的 DOS 磁盘标签。

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

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

Calling ioctl() to re-read partition table.
正在同步磁盘。
#vdc1分区创建成功
[root@localhost ~]# lsblk
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                   8:0    0 10.9T  0 disk 
└─sda1                8:1    0 10.9T  0 part 
sr0                  11:0    1  8.1G  0 rom  
vda                 252:0    0    4T  0 disk 
├─vda1              252:1    0    1G  0 part /boot
├─vda2              252:2    0   99G  0 part 
│ ├─centos-root     253:0    0   50G  0 lvm  /
│ ├─centos-swap     253:1    0  7.9G  0 lvm  [SWAP]
│ └─centos-home     253:3    0 41.1G  0 lvm  /home
└─vda3              252:3    0  1.9T  0 part 
  └─vgdata1-lvdata1 253:2    0  5.9T  0 lvm  /data
vdb                 252:16   0    4T  0 disk 
└─vdb1              252:17   0    4T  0 part 
  └─vgdata1-lvdata1 253:2    0  5.9T  0 lvm  /data
vdc                 252:32   0  100G  0 disk 
└─vdc1              252:33   0  100G  0 part 
#将vdc1格式化为xfs文件系统(LVM环境无需格式化)
[root@localhost ~]# mkfs.xfs /dev/vdc1
meta-data=/dev/vdc1              isize=512    agcount=4, agsize=6553536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
#将vdc1创建为物理卷
[root@localhost ~]# pvcreate /dev/vdc1
WARNING: xfs signature detected on /dev/vdc1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/vdc1.
  Physical volume "/dev/vdc1" successfully created.

[root@localhost ~]# 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               ylDKJ4-qKEK-69aA-2yJZ-zoWG-jaTx-KcLoRy
   
  --- Physical volume ---
  PV Name               /dev/vdb1
  VG Name               vgdata1
  PV Size               <4.00 TiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1048575
  Free PE               0
  Allocated PE          1048575
  PV UUID               adxq7p-UYuH-lycJ-i7LE-qYb1-xpu4-wxDGG3
   
  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               vgdata1
  PV Size               1.90 TiB / not usable <4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              498687
  Free PE               0
  Allocated PE          498687
  PV UUID               0z2o5A-R1xs-SmRI-01Wv-2HLH-J0oe-FGE31v
   
  "/dev/vdc1" is a new physical volume of "<100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vdc1
  VG Name               
  PV Size               <100.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               j4kXv3-ID9o-bDoc-y1g1-5gn4-dq1T-ANzLU

#当前卷组信息
[root@localhost ~]# 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               3
  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               jutp2k-tiS4-W4Z0-mqOX-4pW5-yiX3-lo2bBH
   
  --- Volume group ---
  VG Name               vgdata1
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               5.90 TiB
  PE Size               4.00 MiB
  Total PE              1547262
  Alloc PE / Size       1547262 / 5.90 TiB
  Free  PE / Size       0 / 0   
  VG UUID               2rSQXq-JC7S-e2Us-GDBb-xZ6g-vGJC-CSOX3X

#卷组扩容后vg信息,centos卷组容量从<99GB变成了198.99GB,增加了100GB
[root@localhost ~]# vgextend centos /dev/vdc1
  Volume group "centos" successfully extended
[root@localhost ~]# 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               3
  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               jutp2k-tiS4-W4Z0-mqOX-4pW5-yiX3-lo2bBH
   
  --- Volume group ---
  VG Name               vgdata1
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               5.90 TiB
  PE Size               4.00 MiB
  Total PE              1547262
  Alloc PE / Size       1547262 / 5.90 TiB
  Free  PE / Size       0 / 0   
  VG UUID               2rSQXq-JC7S-e2Us-GDBb-xZ6g-vGJC-CSOX3X

#查看当前lvm状态
 --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                rh2Z88-P0Xx-yIMi-72th-bXW7-bge6-hxESQU
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-07-09 18:39:12 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

扩容后的lvm状态,lvm也增加了100GB
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root 
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents).
  Logical volume centos/root successfully resized.
[root@localhost ~]# lvdisplay 
 --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                rh2Z88-P0Xx-yIMi-72th-bXW7-bge6-hxESQU
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-07-09 18:39:12 +0800
  LV Status              available
  # open                 1
  LV Size                150.00 GiB
  Current LE             38400
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
#刷新分区
[root@localhost ~]# xfs_growfs /
刷新逻辑卷信息:xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 39321600
[root@localhost ~]# df -hT
文件系统                    类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root     xfs       150G   46G  105G   31% /
devtmpfs                    devtmpfs   16G     0   16G    0% /dev
tmpfs                       tmpfs      16G     0   16G    0% /dev/shm
tmpfs                       tmpfs      16G  938M   15G    6% /run
tmpfs                       tmpfs      16G     0   16G    0% /sys/fs/cgroup
/dev/vda1                   xfs      1014M  286M  729M   29% /boot
/dev/mapper/vgdata1-lvdata1 xfs       6.0T  4.0T  2.0T   67% /data
/dev/mapper/centos-home     xfs        42G  796M   41G    2% /home
tmpfs                       tmpfs     3.2G   12K  3.2G    1% /run/user/42
tmpfs                       tmpfs     3.2G  4.0K  3.2G    1% /run/user/0
tmpfs                       tmpfs      60M     0   60M    0% /var/log/rtlog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vavevcvg

用实操解决你的问题

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值