aliyunEC云主机磁盘安全扩容

云主机磁盘(块设备),实际是虚拟文件,当磁盘空间不够时,可以在云服务提供商后台增加磁盘容量,下面是用户需要做的操作。

  • 系统版本:CentOS6
  • 数据盘文件系统:xfs
  • 数据盘挂载点:/mount_point
  • 数据盘设备名:/dev/xvdb
  • 当前容量: df -lh
    /dev/xvdb1 27G 23G 4.0G 85% /mount_point
  • 扩容后容量:

步骤:

  • 停止服务 service nginx stop
  • 查看是否有其他程序正在打开分区lsof /mount_point
  • umount分区 umount /mount_point
  • 查看磁盘信息,可看到这块盘已经是100GB大小,但是系统还不能使用。

    # fdisl -l /dev/xvdb
    Disk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
    Device Start End Blocks Id System
    /dev/xvdb1 7999488 62914559 27457536 83 Linux
  • 修改分区表

    # fdisk /dev/xvdb
    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/xvdb: 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: 0x000dc675
    Device Boot Start End Blocks Id System
    /dev/xvdb1 7999488 62914559 27457536 83 Linux
    Command (m for help): d
    Selected partition 1
    Partition 1 is deleted
    Command (m for help): p
    Disk /dev/xvdb: 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: 0x000dc675
    Device Boot Start End Blocks Id System
    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):
    First sector (2048-209715199, default 2048): 7999488
    Last sector, +sectors or +size{K,M,G} (7999488-209715199, default 209715199):
    Using default value 209715199
    Partition 1 of type Linux and of size 96.2 GiB is set
    Command (m for help): p
    Disk /dev/xvdb: 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: 0x000dc675
    Device Boot Start End Blocks Id System
    /dev/xvdb1 7999488 209715199 100857856 83 Linux
    Command (m for help): wq
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.
  • 查看修改结果

    # fdisk -l /dev/xvdb
    Disk /dev/xvdb: 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: 0x000dc675
    Device Boot Start End Blocks Id System
    /dev/xvdb1 7999488 209715199 100857856 83 Linux
  • 使用xfs_growfs命令对xfs文件系统进行扩容

    # xfs_growfs /dev/xvdb1
    meta-data=/dev/xvdb1 isize=256 agcount=4, agsize=1716096 blks
    = sectsz=512 attr=2, projid32bit=0
    = crc=0
    data = bsize=4096 blocks=6864384, imaxpct=25
    = sunit=0 swidth=0 blks
    naming =version 2 bsize=4096 ascii-ci=0 ftype=0
    log =internal bsize=4096 blocks=3351, version=2
    = sectsz=512 sunit=0 blks, lazy-count=1
    realtime =none extsz=4096 blocks=0, rtextents=0
    data blocks changed from 6864384 to 25214464
  • 挂载分区# mount -a

  • 查看目前可用空间
    # df -lh
    Filesystem Size Used Avail Use% Mounted on
    /dev/xvdb1 97G 23G 74G 24% /mount_point

aliyun磁盘原地扩容官方说明

aliyun磁盘原地扩容官方操作说明