zoukankan      html  css  js  c++  java
  • vcenter环境下对vmware虚拟机lvm磁盘扩容

    服务器环境:

    [root@ws-cdp04 ~]# df -Th
    Filesystem                          Type      Size  Used Avail Use% Mounted on
    devtmpfs                            devtmpfs   63G     0   63G   0% /dev
    tmpfs                               tmpfs      63G     0   63G   0% /dev/shm
    tmpfs                               tmpfs      63G   20M   63G   1% /run
    tmpfs                               tmpfs      63G     0   63G   0% /sys/fs/cgroup
    /dev/mapper/Centos7--vGroup001-root xfs        44G  2.5G   42G   6% /
    /dev/sda1                           xfs      1014M  232M  783M  23% /boot
    tmpfs                               tmpfs      13G     0   13G   0% /run/user/0
    [root@ws-cdp04 ~]# fdisk -l
    
    Disk /dev/sdb: 3221.2 GB, 3221225472000 bytes, 6291456000 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/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009b07b
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    
    Disk /dev/sdc: 3221.2 GB, 3221225472000 bytes, 6291456000 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/Centos7--vGroup001-root: 47.2 GB, 47240445952 bytes, 92266496 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/Centos7--vGroup001-swap: 5368 MB, 5368709120 bytes, 10485760 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
    
    [root@ws-cdp04 ~]# vgs
      VG                #PV #LV #SN Attr   VSize   VFree
      Centos7-vGroup001   1   2   0 wz--n- <49.00g    0 
    [root@ws-cdp04 ~]# pvs
      PV         VG                Fmt  Attr PSize   PFree
      /dev/sda2  Centos7-vGroup001 lvm2 a--  <49.00g    0 
    [root@ws-cdp04 ~]# lvs
      LV   VG                Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root Centos7-vGroup001 -wi-ao---- <44.00g                                                    
      swap Centos7-vGroup001 -wi-ao----   5.00g 

    场景一:

    sdb sdc 两块磁盘通过 lvm 扩容挂载到 /data 同一个目录的方法

    # 对sdb 的处理

    pvcreate /dev/sdb
    vgcreate centos7_vGroup002 /dev/sdb
    lvcreate -l 100%VG -n lv_data centos7_vGroup002
    mkfs.xfs -f /dev/centos7_vGroup002/lv_data
    mkdir /data
    mount /dev/mapper/centos7_vGroup002-lv_data /data

    # sdc 的处理

    pvcreate /dev/sdc
    vgextend centos7_vGroup002 /dev/sdc
    lvextend -l +100%FREE /dev/mapper/centos7_vGroup002-lv_data
    xfs_growfs /dev/mapper/centos7_vGroup002-lv_data

    # 开机自动挂载
    echo "/dev/mapper/centos7_vGroup002-lv_data /data xfs     defaults        0 0" >> /etc/fstab

    场景二:

    添加单块磁盘挂载到 /data 目录的方法

    pvcreate /dev/sdb
    vgcreate centos7_vGroup002 /dev/sdb
    lvcreate -l 100%VG -n lv_data centos7_vGroup002
    mkfs.xfs -f /dev/centos7_vGroup002/lv_data
    mount /dev/mapper/centos7_vGroup002-lv_data /data
    
    # 开机自动挂载
    # vim /etc/fstab
    /dev/mapper/centos7_vGroup002-lv_data /data xfs     defaults        0 0

    场景三:

    # 扩容系统盘

    在vcenter界面中直接把50G修改为100G,然后重启操作系统

    fdisk -l 可以看到 sda 变成了 100G

    # 通过fdisk 操作删除已经存在的 sda2 分区
    fdisk /dev/sda 删除 sda2 然后重新创建 sda2并且把剩余空间全部分配给 sda2

    [root@ws-cdp04 ~]# fdisk /dev/sda
    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.
    
    
    Command (m for help): p
    
    Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009b07b
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   104857599    51379200   8e  Linux LVM
    
    Command (m for help): d
    Partition number (1,2, default 2): 2
    Partition 2 is deleted
    
    Command (m for help): p
    
    Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x0009b07b
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): p
    Partition number (2-4, default 2): 
    First sector (2099200-209715199, default 2099200): 
    Using default value 2099200
    Last sector, +sectors or +size{K,M,G} (2099200-209715199, default 209715199): 
    Using default value 209715199
    Partition 2 of type Linux and of size 99 GiB is set
    
    Command (m for help): t
    Partition number (1,2, default 2): 2
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.

    让分区生效

    [root@ws-cdp03 ~]# partprobe
    
    [root@ws-cdp03 ~]# partprobe /dev/sda2
    [root@ws-cdp04 ~]# pvs
      PV         VG                Fmt  Attr PSize   PFree
      /dev/sda2  Centos7-vGroup001 lvm2 a--  <49.00g    0

    # 扩容pv

    [root@ws-cdp03 ~]# pvresize -v /dev/sda2
    [root@ws-cdp04 ~]# pvs
      PV         VG                Fmt  Attr PSize   PFree 
      /dev/sda2  Centos7-vGroup001 lvm2 a--  <99.00g 50.00g
    
    # 扩容lv
    lvextend -l +100%FREE /dev/mapper/Centos7--vGroup001-root
    # 扩容
    xfs_growfs  /dev/mapper/Centos7--vGroup001-root

    场景四:

    扩容非系统盘,比如 /dev/sdb,由100G扩容到3T,直接在 vcenter 中修改磁盘大小为3000G,然后在操作系统中执行如下命令,不会影响已有数据

    # 扩容pv
    pvresize -v /dev/sdb
    # 扩容lv
    lvextend -l +100%FREE /dev/mapper/centos7_vGroup002-lv_data
    xfs_growfs /dev/mapper/centos7_vGroup002-lv_data

    此时再添加一块磁盘并且绑定在 /data/中

    # sdc 的处理

    pvcreate /dev/sdc
    vgextend centos7_vGroup002 /dev/sdc
    lvextend -l +100%FREE /dev/mapper/centos7_vGroup002-lv_data
    xfs_growfs /dev/mapper/centos7_vGroup002-lv_data

     场景五:

    # ext4    的扩容方法,挂载新的 磁盘到根目录(扩容)
    # 在控制台添加300G磁盘
    pvcreate /dev/sdc
    vgextend VolGroup /dev/sdc
    lvextend -l +100%FREE /dev/mapper/VolGroup-root 
    resize2fs /dev/VolGroup/root
  • 相关阅读:
    PHP构造方法和析构函数
    数组的排序算法
    Swift---- 可选值类型(Optionals) 、 断言(Assertion) 、 集合 、 函数
    Swift----方法 、 下标 、 继承 、 初始化 、 析构方法 、 可选链
    Swift----函数 、 闭包 、 枚举 、 类和结构体 、 属性
    Swift-----类型转换 、 嵌套类型 、 扩展 、 协议 、 访问控制
    程序员创业-行业分析之区分易混淆的基本概念
    MSSQl分布式查询(转)
    iOS8中添加的extensions总结(一)——今日扩展
    Python Function Note
  • 原文地址:https://www.cnblogs.com/reblue520/p/14423291.html
Copyright © 2011-2022 走看看