云主机磁盘(块设备),实际是虚拟文件,当磁盘空间不够时,可以在云服务提供商后台增加磁盘容量,下面是用户需要做的操作。
- 系统版本: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/xvdbDisk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsDevice Start End Blocks Id System/dev/xvdb1 7999488 62914559 27457536 83 Linux修改分区表
# fdisk /dev/xvdbWelcome 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): pDisk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000dc675Device Boot Start End Blocks Id System/dev/xvdb1 7999488 62914559 27457536 83 LinuxCommand (m for help): dSelected partition 1Partition 1 is deletedCommand (m for help): pDisk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000dc675Device Boot Start End Blocks Id SystemCommand (m for help): nPartition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): pPartition number (1-4, default 1):First sector (2048-209715199, default 2048): 7999488Last sector, +sectors or +size{K,M,G} (7999488-209715199, default 209715199):Using default value 209715199Partition 1 of type Linux and of size 96.2 GiB is setCommand (m for help): pDisk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000dc675Device Boot Start End Blocks Id System/dev/xvdb1 7999488 209715199 100857856 83 LinuxCommand (m for help): wqThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.查看修改结果
# fdisk -l /dev/xvdbDisk /dev/xvdb: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000dc675Device Boot Start End Blocks Id System/dev/xvdb1 7999488 209715199 100857856 83 Linux使用xfs_growfs命令对xfs文件系统进行扩容
# xfs_growfs /dev/xvdb1meta-data=/dev/xvdb1 isize=256 agcount=4, agsize=1716096 blks= sectsz=512 attr=2, projid32bit=0= crc=0data = bsize=4096 blocks=6864384, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal bsize=4096 blocks=3351, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 6864384 to 25214464挂载分区
# mount -a
- 查看目前可用空间# df -lhFilesystem Size Used Avail Use% Mounted on/dev/xvdb1 97G 23G 74G 24% /mount_point