Vmware虚拟机根盘扩容

磁盘情况

  • 查看扩容前的磁盘容量
    1
    2
    3
    4
    5
    6
    7
    8
    [root@k8s-node2 ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    devtmpfs 2.9G 0 2.9G 0% /dev
    tmpfs 2.9G 0 2.9G 0% /dev/shm
    tmpfs 2.9G 279M 2.7G 10% /run
    tmpfs 2.9G 0 2.9G 0% /sys/fs/cgroup
    /dev/mapper/centos-root 17G 13G 4.5G 75% / <-- 17G
    /dev/sda1 1014M 187M 828M 19% /boot
  • 查看磁盘分区情况
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    [root@k8s-node2 ~]# fdisk -l

    Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors <-- 107.4 GB
    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: 0x000a6a43

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

    Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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

对扩容的磁盘分区操作

  • 磁盘分区命令
    1
    fdisk /dev/sda
    eOFJrd
  • 分区设置分区格式,在Fdisk命令处输入:t,分区号用默认 3(或回车),Hex代码输入:8e (代表适用Linux LVM分区类型),最后写入分区表,在Fdisk命令位置输入:w
    FjBB1t
  • fdisk -l 查看我们新创建的dev/sda3分区了,分区格式为Linux LVM类型。
    HUBP0A
  • 不重启的情况下重读分区,马上生效,格式化新增磁盘并分区
    1
    2
    partprobe /dev/sda
    mkfs.ext3 /dev/sda3
    WuzwSV
  • 进入lvm中合并磁盘
    1
    2
    3
    4
    5
    6
    #进入lvm
    lvm
    #初始化/dev/sda3
    pvcreate /dev/sda3
    #将新分区添加进系统默认的Volume group,centOS的默认Volume group为centos
    vgextend centos /dev/sda3
    deaNOu
    1
    2
    3
    4
    5
    #查看一下当前的Volume卷详情
    vgdisplay -v
    #将系统盘/dev/mapper/centos-root与sda3的5119空余容量合并,输入如下命令:
    lvextend -l +20479 /dev/mapper/centos-root
    quit
    IVbZMN
  • 最后查看扩容及磁盘状态
    1
    2
    #文件系统进行扩容,以让系统识别,输入如下命令(只适用于CentOS7)
    xfs_growfs /dev/mapper/centos-root
    h61lCm
    1
    fdisk -l
    s72ybS
  • 查看系统容量
    1
    df -h
    6U5k7Z