CentOs磁盘扩容笔记

CentOs磁盘扩容笔记

  1. 查看磁盘扩容前容量 此时加起来总大小为60G

df -h

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             1.8G     0  1.8G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  9.7M  1.8G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/cs-root   37G   20G   18G  54% /
/dev/nvme0n1p1      1014M  257M  758M  26% /boot
/dev/mapper/cs-home   19G  4.5G   14G  25% /home
tmpfs                371M   12K  371M   1% /run/user/42
tmpfs                371M     0  371M   0% /run/user/0

  1. fdisk -l 查看 磁盘分区 状况 ,此时总容量变为80,但是只有两个盘使用了60G,还有20G未显示
lsblk  
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0          11:0    1 10.7G  0 rom  /run/media/root/CentOS-Stream-8-x86_64-dvd
nvme0n1     259:0    0   80G  0 disk 
├─nvme0n1p1 259:1    0    1G  0 part /boot
└─nvme0n1p2 259:2    0   59G  0 part 
  ├─cs-root 253:0    0   37G  0 lvm  /
  ├─cs-swap 253:1    0    4G  0 lvm  [SWAP]
  └─cs-home 253:2    0 18.1G  0 lvm  /home
  
fdisk -l  
Disk /dev/nvme0n1: 80 GiB, 85899345920 bytes, 167772160 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
Disklabel type: dos
Disk identifier: 0x654919f3

Device         Boot   Start       End   Sectors Size Id Type
/dev/nvme0n1p1 *       2048   2099199   2097152   1G 83 Linux
/dev/nvme0n1p2      2099200 125829119 123729920  59G 8e Linux LVM
  1. 增加分区显示增加的磁盘容量
fdisk /dev/nvme0n1

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): #默认回车
First sector (125829120-167772159, default 125829120): #默认回车
Last sector, +sectors or +size{K,M,G,T,P} (125829120-167772159, default 167772159):  #默认回车

Created a new partition 3 of type 'Linux' and of size 20 GiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

fdisk -l 查看分区

fdisk -l  
Disk /dev/nvme0n1: 80 GiB, 85899345920 bytes, 167772160 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
Disklabel type: dos
Disk identifier: 0x654919f3

Device         Boot     Start       End   Sectors Size Id Type
/dev/nvme0n1p1 *         2048   2099199   2097152   1G 83 Linux
/dev/nvme0n1p2        2099200 125829119 123729920  59G 8e Linux LVM
/dev/nvme0n1p3      125829120 167772159  41943040  20G 83 Linux   # 此为新增加的扩展盘
  1. 增加系统识别

执行 partprobe

  1. 创建物理卷 注意名称为新创建的卷 /dev/nvme0n1p3

    pvcreate /dev/nvme0n1p3
      Physical volume "/dev/nvme0n1p3" successfully created.
    
  2. 扩展卷组

    查看卷组信息:

    vgdisplay

      --- Volume group ---
      VG Name               cs
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  6
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                3
    

    扩展卷组

    vgextend cs /dev/nvme0n1p3
    Volume group “cs” successfully extended

  3. 增加home的大小,此时要注意挂载20G不一定有20G的空间,就会报Insufficient free space

    lvresize -L +19G /dev/mapper/cs-home 
      Size of logical volume cs/home changed from 18.06 GiB (4624 extents) to 37.06 GiB (9488 extents).
      Logical volume cs/home successfully resized.
    

    原因是:执行pvdisplay可以看到可用的PE数量是5119,而每个PE大小是4.00MiB,所以其实这个卷组实际的可用空间其实不是20G,而是19.99G

    1. 此时 df -h 查看没有任何变化,/dev/mapper/cs-home还是19G
    df -h
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             1.8G     0  1.8G   0% /dev
    tmpfs                1.9G     0  1.9G   0% /dev/shm
    tmpfs                1.9G  9.6M  1.8G   1% /run
    tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/mapper/cs-root   37G   20G   18G  54% /
    /dev/nvme0n1p1      1014M  257M  758M  26% /boot
    /dev/mapper/cs-home   19G  4.5G   14G  25% /home
    tmpfs                371M   12K  371M   1% /run/user/42
    tmpfs                371M     0  371M   0% /run/user/0
    

    vgdisplay 查看磁盘空间已经增加,从60G变为 78.99 GiB

vgdisplay 
  --- Volume group ---
  VG Name               cs
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  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               78.99 GiB
  PE Size               4.00 MiB
  Total PE              20222
  Alloc PE / Size       19967 / <78.00 GiB
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               fQivhZ-JtEj-97ae-iH7X-XSBA-xWh5-etfV1h

需要执行,文件系统的同步,之前只是对逻辑卷的扩容

xfs_growfs /dev/mapper/cs-home

再次df -h 查看已经变为38G

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             1.8G     0  1.8G   0% /dev
tmpfs                1.9G     0  1.9G   0% /dev/shm
tmpfs                1.9G  9.6M  1.8G   1% /run
tmpfs                1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/cs-root   37G   20G   18G  54% /
/dev/nvme0n1p1      1014M  257M  758M  26% /boot
/dev/mapper/cs-home   38G  4.6G   33G  13% /home
tmpfs                371M     0  371M   0% /run/user/0

参考:
https://blog.csdn.net/qw6r5/article/details/127167217
https://blog.51cto.com/u_7961702/5526676

你可能感兴趣的:(centos,运维)