CentOS7扩容磁盘

1、将新硬盘分区并格式化为xfs格式

查看现在磁盘情况,/dev/mapper/centos-root这个卷组已经没用空间了

[root@yumserver ~]# df -lh
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   13M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root  546G  546G  1.8M 100% /
/dev/sda1               1014M  185M  830M  19% /boot
tmpfs                    378M  8.0K  378M   1% /run/user/42
tmpfs                    378M     0  378M   0% /run/user/0

扩容sdc磁盘到系统,先fdisk -l 查看分区情况

[root@yumserver ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00024906

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x7b03558d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048575999   524286976   83  Linux

Disk /dev/sdc: 247.0 GB, 246960619520 bytes, 482344960 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 /dev/mapper/centos-root: 585.3 GB, 585310928896 bytes, 1143185408 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 /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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

使用fdisk /dev/sdc命令对sdc磁盘进行分区

[root@yumserver ~]# fdisk /dev/sdc 
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 0x688d2707.

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): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-482344959, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-482344959, default 482344959): 
Using default value 482344959
Partition 1 of type Linux and of size 230 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

再次查看分区效果 fdisk -l

[root@yumserver ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00024906

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x7b03558d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1048575999   524286976   83  Linux

Disk /dev/sdc: 247.0 GB, 246960619520 bytes, 482344960 sectors

格式化/dev/sdc1分区 mkfs.xfs -f /dev/sdc1

[root@yumserver ~]# mkfs.xfs -f /dev/sdc
sdc   sdc1  
[root@yumserver ~]# mkfs.xfs -f /dev/sdc1 
meta-data=/dev/sdc1              isize=512    agcount=4, agsize=15073216 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=60292864, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=29439, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

2、 将/dev/sdc1创建新PV

使用pvcreate /dev/sdc1命令对sdc1进行物理卷创建

[root@yumserver ~]# pvcreate /dev/sdc1
WARNING: xfs signature detected on /dev/sdc1 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sdc1.
  Physical volume "/dev/sdc1" successfully created.

3、在当前VG下扩容VG容量,将第二步创建的PV加入现有VG中

查看vg名称为centos

[root@yumserver ~]# 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                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               548.99 GiB
  PE Size               4.00 MiB
  Total PE              140542
  Alloc PE / Size       140541 / <548.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               M13Van-AHzi-WHYr-Og55-VvfM-v3c3-WyYnva

扩容vg卷组,vgextend centos /dev/sdc1

[root@yumserver ~]# vgextend centos /dev/sdc1
  Volume group "centos" successfully extended

4、将新建分区容量全部扩容给指定LV

查看lv名称为/dev/centos/root

[root@yumserver ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                2GrD1V-Ayem-v1Cx-Yu43-RkXq-V6De-t0OzMK
  LV Write Access        read/write
  LV Creation host, time yumserver, 2021-08-03 16:03:20 +0800
  LV Status              available
  # open                 2
  LV Size                <3.88 GiB
  Current LE             992
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2FybeS-8wNJ-mH9u-diI0-CE6A-4mr5-xyEahf
  LV Write Access        read/write
  LV Creation host, time yumserver, 2021-08-03 16:03:20 +0800
  LV Status              available
  # open                 1
  LV Size                545.11 GiB
  Current LE             139549
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

使用lvextend扩容逻辑卷,lvextend /dev/centos/root /dev/sdc1

[root@yumserver ~]# lvextend /dev/centos/root /dev/sdc1 
  Size of logical volume centos/root changed from 545.11 GiB (139549 extents) to <775.11 GiB (198428 extents).
  Logical volume centos/root successfully resized.

5、调整文件系统的大小,以便新分区可利用这个额外的空间

使用xfs_growfs /dev/centos/root命令进行磁盘扩容

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

6、查看扩容后的磁盘情况

[root@yumserver ~]# df -lh
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   13M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root  776G  546G  230G  71% /
/dev/sda1               1014M  185M  830M  19% /boot
tmpfs                    378M   12K  378M   1% /run/user/42
tmpfs                    378M     0  378M   0% /run/user/0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值