CentOS系统盘扩容

作者:zhangyunlong 发布时间: 2023-08-10 阅读量:4 评论数:0

1 查看可用设备信息

[root@YYCPYFZX-4 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  492K  0 rom  
vda             252:0    0   50G  0 disk 
├─vda1          252:1    0    1G  0 part /boot
└─vda2          252:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
vdb             252:16   0  300G  0 disk

其中vdb为需要挂载使用的磁盘

2 格式化磁盘

[root@YYCPYFZX-4 /]# mkfs.ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78643200 blocks
3932160 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2227175424
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616
​
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     
​
[root@YYCPYFZX-4 /]#

3 磁盘分区

[root@YYCPYFZX-4 /]# 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 0xd268e58e.
​
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)
​
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-629145599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): 
Using default value 629145599
Partition 1 of type Linux and of size 300 GiB is set
​
Command (m for help): w
The partition table has been altered!
​
Calling ioctl() to re-read partition table.
Syncing disks.
[root@YYCPYFZX-4 /]#

4 创建物理卷

[root@YYCPYFZX-4 /]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created.
[root@YYCPYFZX-4 /]#

如果有警告信息如下:

[root@appli-29 ~]# pvcreate /dev/vdb1
  WARNING: Device for PV qdp443-BlHU-rjf4-u7fd-eoW4-0pHX-C4fZTf not found or rejected by a filter.
  Couldn't find device with uuid qdp443-BlHU-rjf4-u7fd-eoW4-0pHX-C4fZTf.
  Physical volume "/dev/vdb1" successfully created.
[root@appli-29 ~]#

原因是磁盘未卸载引起的, 需要卸载磁盘后从第一步重新执行, 且在分区后执行以下命令清理未知的vg, 命令中的centos为第5步中VG Name的值

[root@appli-29 ~]# vgreduce --removemissing centos
  WARNING: Device for PV qdp443-BlHU-rjf4-u7fd-eoW4-0pHX-C4fZTf not found or rejected by a filter.
  Couldn't find device with uuid qdp443-BlHU-rjf4-u7fd-eoW4-0pHX-C4fZTf.
  Wrote out consistent volume group centos.
[root@appli-29 ~]# 
[root@appli-29 ~]# 
[root@appli-29 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created.
[root@appli-29 ~]#

5 查看卷分组

[root@YYCPYFZX-4 /]# vgdisplay -v
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               0NnNoU-AOBX-tAmD-wKrg-hBxb-QYww-uX1ffX
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                zneuwA-aMid-kLI9-0n5K-DM5S-D2Fj-bEjDcE
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-30 15:20:50 +0800
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                sJxNvX-JNsY-Kyct-Rvav-QKWQ-QqAe-CoQn4R
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-06-30 15:20:50 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/vda2     
  PV UUID               loBcOa-4Uo3-Alex-nR3o-YbcF-FXFe-0XLGNZ
  PV Status             allocatable
  Total PE / Free PE    4863 / 0
   
[root@YYCPYFZX-4 /]#

6 扩展卷分组

命令中的'centos'为上一步看到的卷分组中的VG Name的值

[root@YYCPYFZX-4 /]# vgextend centos /dev/vdb1
  Volume group "centos" successfully extended
[root@YYCPYFZX-4 /]#

7 扩展逻辑卷

其中卷的大小需要小于磁盘大小

[root@YYCPYFZX-4 /]# lvextend -L +299G /dev/centos/root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <316.00 GiB (80895 extents).
  Logical volume centos/root successfully resized.
[root@YYCPYFZX-4 /]#

8 同步文件系统

[root@YYCPYFZX-4 /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 82836480
[root@YYCPYFZX-4 /]#

9 查看磁盘信息

[root@YYCPYFZX-4 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.8M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  316G  1.7G  315G   1% /
/dev/vda1               1014M  150M  865M  15% /boot
[root@YYCPYFZX-4 /]#

10 重启系统确认磁盘状态是否正常

[root@YYCPYFZX-4 /]# reboot

评论