一、重新读取磁盘信息

  1. 由于不知道新增硬盘挂载的位置,可以先查看现有硬盘挂载的适配器。
    • [root@localhost ~]# ls -l /sys/block/sda
    • lrwxrwxrwx. 1 root root 0 Jun 15 11:47 /sys/block/sda -> ../devices/pci0000:00/0000:00:10.0/host2/target32:0:0/32:0:0:0/block/sda
  2. 发现正在磁盘挂载到host32,可以尝试使用下边命令,重新扫描host32信息

    • echo “- - -“ > /sys/class/scsi_host/host2/scan

      二、扩容操作

  3. 查看现有磁盘信息,可以看出根分区有45G

    • [root@DEV-CMDB-DB02 ~]# df -h
    • Filesystem Size Used Avail Use% Mounted on
    • /dev/mapper/centos_mb—centos7-root 45G 9.8G 35G 23% /
    • devtmpfs 5.9G 0 5.9G 0% /dev
    • tmpfs 5.9G 84K 5.9G 1% /dev/shm
    • tmpfs 5.9G 8.9M 5.9G 1% /run
    • tmpfs 5.9G 0 5.9G 0% /sys/fs/cgroup
    • /dev/sda1 497M 142M 356M 29% /boot
    • tmpfs 1.2G 16K 1.2G 1% /run/user/42
    • tmpfs 1.2G 0 1.2G 0% /run/user/0
  4. 查看新增加的磁盘信息
    • [root@DEV-CMDB-DB02 ~]# fdisk -l
  5. 根据以上信息,对新增加的磁盘进行分区
    • [root@DEV-CMDB-DB02 ~]# fdisk /dev/sdb
  • Command (m for help): p
  • 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): 1
  • First sector (2048-209715199, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
    Using default value 209715199
    Partition 1 of type Linux and of size 100 GiB is set
  1. 分区完成后修改分区类型为lvm
  • Command (m for help): t
  • Hex code (type L to list all codes): L
  • Hex code (type L to list all codes): 8e
  • Command (m for help): p
  • Command (m for help): w
  1. 创建物理卷
    • [root@DEV-CMDB-DB02 ~]# pvcreate /dev/sdb1
    • Physical volume “/dev/sdb1” successfully created
  2. 查看物理卷信息
    • [root@DEV-CMDB-DB02 ~]# pvs
    • [root@DEV-CMDB-DB02 ~]# df -h
  3. 将新增加的分区/dev/sdb1加入到根目录分区centos_mb-centos7中
    • [root@DEV-CMDB-DB02 ~]# vgextend centos /dev/sdb1
  4. 重新查看卷组信息
    • [root@DEV-CMDB-DB02 ~]# vgs
  5. 进行卷扩容
    • [root@DEV-CMDB-DB02 ~]# lvextend -l +100%FREE /dev/mapper/centos-root
  6. 调整卷分区大小
    • [root@DEV-CMDB-DB02 ~]# xfs_growfs /dev/mapper/centos_mb—centos7-root
  7. 查看磁盘信息可以看出根目录分区大小已成功扩容
    • [root@DEV-CMDB-DB02 ~]# df -h