磁盘扩容

作者: Habit_1027 | 来源:发表于2022-02-28 14:38 被阅读0次

    一、常用命令

    1.1、查看磁盘挂载与磁盘使用空间

    [root@es1_node ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        26G  1.4G   25G   6% /
    devtmpfs                devtmpfs  901M     0  901M   0% /dev
    tmpfs                   tmpfs     912M     0  912M   0% /dev/shm
    tmpfs                   tmpfs     912M  8.6M  904M   1% /run
    tmpfs                   tmpfs     912M     0  912M   0% /sys/fs/cgroup
    /dev/sda1               xfs      1014M  143M  872M  15% /boot
    tmpfs                   tmpfs     183M     0  183M   0% /run/user/0
    

    1.2、查看磁盘设备

    [root@es1_node ~]# lsblk 
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0    1G  0 part /boot
    └─sda2            8:2    0   19G  0 part 
      ├─centos-root 253:0    0   26G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0    9G  0 disk 
    └─centos-root   253:0    0   26G  0 lvm  /
    sr0              11:0    1  4.2G  0 rom  
    

    1.3、查看磁盘分区信息

    [root@es1_node ~]# fdisk -l
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000a80ee
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    
    Disk /dev/sdb: 9663 MB, 9663676416 bytes, 18874368 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: 27.9 GB, 27908898816 bytes, 54509568 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: 2147 MB, 2147483648 bytes, 4194304 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
    
    

    二、实战扩容

    2.1刚在虚拟机上添加了一个9G的磁盘,用lsblk查看

    [root@es1_node ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0    1G  0 part /boot
    └─sda2            8:2    0   19G  0 part 
      ├─centos-root 253:0    0   17G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0    9G  0 disk 
    sr0              11:0    1  4.2G  0 rom  
    

    2.2、把新增的磁盘sdb做成pv卷(pvcreate命令)

    上面lsblk命令可以看到新加的磁盘设备名是sdb,大小是9G

    [root@es1_node ~]# pvcreate  /dev/sdb
      Physical volume "/dev/sdb" successfully created.
    

    然后pvdisplay命令查看pv

    [root@es1_node ~]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <19.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              4863
      Free PE               0
      Allocated PE          4863
      PV UUID               0kYqOo-Huh0-GUze-1Oxx-GxUf-FLCT-Ggc3Jx
       
      "/dev/sdb" is a new physical volume of "9.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb
      VG Name               
      PV Size               9.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               WeSiK4-eKlK-D4Ba-p1rS-w91Y-rDTW-q3fxMi
    

    或者pvs查看

    可以看到pv有9G的free空闲

    [root@es1_node ~]# pvs
      PV         VG     Fmt  Attr PSize   PFree
      /dev/sda2  centos lvm2 a--  <19.00g    0 
      /dev/sdb          lvm2 ---    9.00g 9.00g
    
    

    2.3、查看vg(vgs或者vgdisplay命令)

    vgs查看,已有vg卷,vg卷名是centos,可以直接在此vg下扩容

    [root@es1_node ~]# vgs
      VG     #PV #LV #SN Attr   VSize   VFree
      centos   1   2   0 wz--n- <19.00g    0 
    
    

    2.4、vg扩容

    [root@es1_node ~]# vgextend centos /dev/sdb
      Volume group "centos" successfully extended
    [root@es1_node ~]# vgs
      VG     #PV #LV #SN Attr   VSize  VFree 
      centos   2   2   0 wz--n- 27.99g <9.00g
    

    vgextend: centos---vg卷组名 将/dev/sdb扩展到centos中
    vg扩容完成后,vgs查看,vg有9G的free空闲

    2.5、lv扩容

    lvextend扩容lv,此处是把所有的空间都扩容,lvs查看

    [root@es1_node ~]# lvextend  -l +100%FREE -n /dev/mapper/centos-root 
      Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 25.99 GiB (6654 extents).
      Logical volume centos/root successfully resized.
    [root@es1_node ~]# lvs
      LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root centos -wi-ao---- 25.99g                                                    
      swap centos -wi-ao----  2.00g 
    

    2.6、文件系统扩容

    df -Th 可以看到文件系统类型是xfs,所以需要用xfs_growfs命令
    ps:如果是ext4类型 用resize2fs 命令

    [root@es1_node ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        17G  1.4G   16G   9% /
    devtmpfs                devtmpfs  901M     0  901M   0% /dev
    tmpfs                   tmpfs     912M     0  912M   0% /dev/shm
    tmpfs                   tmpfs     912M  8.6M  904M   1% /run
    tmpfs                   tmpfs     912M     0  912M   0% /sys/fs/cgroup
    /dev/sda1               xfs      1014M  143M  872M  15% /boot
    tmpfs                   tmpfs     183M     0  183M   0% /run/user/0
    [root@es1_node ~]# 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 6813696
    
    

    到此已完成磁盘扩容的全部步骤,可以df -Th再次查看磁盘,可以看到/dev/mapper/centos-root 从17G扩展到了26G

    [root@es1_node ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        26G  1.4G   25G   6% /
    devtmpfs                devtmpfs  901M     0  901M   0% /dev
    tmpfs                   tmpfs     912M     0  912M   0% /dev/shm
    tmpfs                   tmpfs     912M  8.6M  904M   1% /run
    tmpfs                   tmpfs     912M     0  912M   0% /sys/fs/cgroup
    /dev/sda1               xfs      1014M  143M  872M  15% /boot
    tmpfs                   tmpfs     183M     0  183M   0% /run/user/0
    [root@es1_node ~]# 
    
    

    相关文章

      网友评论

        本文标题:磁盘扩容

        本文链接:https://www.haomeiwen.com/subject/qzslrrtx.html