CentOS扩展数据盘分区容量
选项一:扩展已有MBR分区
说明 为了防止数据丢失,不建议扩容已挂载的分区和文件系统。请先取消挂载(umount)分区,完成扩容并正常使用后,重新挂载(mount)。针对不同的Linux内核版本,推荐以下操作方式:
[*]实例内核版本小于3.6:先取消挂载该分区,再修改分区表,最后扩容文件系统。
[*]实例内核版本大于等于3.6:先修改对应分区表,再通知内核更新分区表,最后扩容文件系统。
如果新增空间用于扩容已有的MBR分区,按照以下步骤在实例中完成扩容:
[*]修改分区表。
[*]运行以下命令查看分区信息,并记录旧分区的起始和结束的扇区位置。
fdisk -lu /dev/vdb
本示例中,分区/dev/vdb1的起始扇区是2048,结束扇区是41943039。
[root@ecshost ~]# fdisk -lu /dev/vdbDisk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47bDevice Boot Start End Blocks Id System/dev/vdb1 2048 41943039 20970496 83 Linux
[*]查看数据盘的挂载路径,根据返回的文件路径卸载分区,直至完全卸载已挂载的分区。
# mount | grep "/dev/vdb"/dev/vdb1 on /mnt type ext4 (rw,relatime,data=ordered)# umount /dev/vdb1# mount | grep "/dev/vdb"
[*]使用fdisk工具删除旧分区。
说明 删除旧分区会一同删除分区内的数据。如有重要数据请备份,避免因删除旧分区而造成数据丢失。
[*]运行fdisk -u /dev/vdb:分区数据盘。
[*]输入p:打印分区表。
[*]输入d:删除分区。
[*]输入p:确认分区已删除。
[*]输入w:保存修改并退出。
# fdisk -u /dev/vdbWelcome 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/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47bDevice Boot Start End Blocks Id System/dev/vdb1 2048 41943039 20970496 83 LinuxCommand (m for help): dSelected partition 1Partition 1 is deletedCommand (m for help): pDisk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47bDevice Boot Start End Blocks Id SystemCommand (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.
[*]使用fdisk命令新建分区。
[*]运行fdisk -u /dev/vdb:分区数据盘。
[*]输入p:打印分区表。
[*]输入n:新建分区。
[*]输入p:选择分区类型为主分区。
[*]输入<分区号>:选择分区号。本示例选取了1。
警告 新分区的起始位置必须和旧分区的起始位置相同,结束位置必须大于旧分区的结束位置,否则会导致扩容失败。
[*]输入w:保存修改并退出。
本示例中,将/dev/vdb1由20GiB扩容到40GiB。
# fdisk -u /dev/vdbWelcome 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/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47bDevice 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): 1First sector (2048-83886079, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):Partition 1 of type Linux and of size 30 GiB is setCommand (m for help): pDisk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47bDevice Boot Start End Blocks Id System/dev/vdb1 2048 62916607 31457280 83 LinuxCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
[*]运行lsblk /dev/vdb确保分区表已经增加。
[*]运行e2fsck -n /dev/vdb1再次检查文件系统,确认扩容分区后的文件系统状态为clean。
[*]通知内核更新分区表。运行partprobe <数据盘设备名>或者partx -u <数据盘设备名>,以通知内核数据盘的分区表已经修改,需要同步更新。
[*]扩容文件系统。
[*]ext*文件系统(例如ext3和ext4):依次运行以下命令调整ext*文件系统大小并重新挂载分区。
[root@ecshost ~]# resize2fs /dev/vdb1resize2fs 1.42.9 (28-Dec-2013)Resizing the filesystem on /dev/vdb1 to 7864320 (4k) blocks.The filesystem on /dev/vdb1 is now 7864320 blocks long.[root@ecshost ~]# mount /dev/vdb1 /mnt
[*]xfs文件系统:依次运行以下命令先重新挂载分区,再调整xfs文件系统大小。
# mount /dev/vdb1 /mnt/# xfs_growfs /dev/vdb1meta-data=/dev/vdb1 isize=512 agcount=4, agsize=1310720 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=5242880, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 5242880 to 7864320
https://help.aliyun.com/document_detail/25452.html#title-j9l-ytz-fgi 注意事项:这里操作的时候如果出现报错,先关闭swap分区跟卸载主机监控以及宝塔相关服务(关闭命令参考:宝塔Linux面板命令及各软件安装路径大全)
具体命令为:
(1)关闭swap分区:
swapoff -a
(2)卸载主机监控:
sudo bash -c "/usr/local/cloudmonitor/wrapper/bin/cloudmonitor.sh remove && rm -rf /usr/local/cloudmonitor"
http://blog.sina.com.cn/s/blog_a97c61460102xg7x.html 本帖最后由 HainaTec 于 2020-2-1 20:32 编辑
解决类似umount target is busy挂载盘卸载不掉问题杀进程操作:https://www.cnblogs.com/ding2016/p/9605526.html
页:
[1]