在我们腾讯云升级扩容数据磁盘后,服务器上正在挂载的数据磁盘是没有扩容成功的,需要自行扩容
首先查看腾讯云给我们扩容的磁盘是否加进来了
[root@VM-0-18-centos filebeat]# fdisk -l
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0005fc9a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 104857566 52427759+ 83 Linux
Disk /dev/vdb: 1095.2 GB, 1095216660480 bytes, 2139095040 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: 0x6fdb8954
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 83 Linux
表示当前数据盘“/dev/vdb”总容量为1095.2 GB,数据盘当前只有一个分区“/dev/vdb1 ”,该分区的初始磁柱值为2048,截止块为104856576即是100GB。该分区只分配了一百多个GB,看回显中数据盘“/dev/vdb ”的容量还有1000多个GB未分配,所以我们进行把最后的1000多G分配到/dev/vdb1中。
2. 执行以下命令,卸载磁盘分区。
umount /data
#取消挂载的时候无法取消下来是因为有进程号在运行
umount: /data: device is busy
umount: /data: device is busy
2.1 、提示被占用,使用强制卸载
[root@localhost /]# umount -f /data
umount2: Device or resource busy
umount: /data: device is busy
umount2: Device or resource busy
umount: /data: device is busy
注:使用-f 参数进行强制卸载时一般建议等一会儿再进行下面的操作,一些情况下处理需要1-2分钟的时间。
2.2 、使用umount -f,问题依旧。使用fuser命令,先确认有那些进程在占用该目录
[root@localhost /]# fuser -cu /data
/data: 1757c(某进程)
上面查看发现是pid为1757的某进程用户起的进程在占用该目录。
2.3、确认某进程所起的进程可以kill 后,可以直接使用fuser 的k参数进行kill (也可以手动停掉1757进程再卸载)
[root@localhost /]# fuser -ck /data
/data: 1757c
注:这里k 就是kill的意思,注意没进行确认前要谨慎使用该参数。
另外,umount异常时,也经常会用到 lsof 指定确认文件被什么进程占用
上面就是Linux使用umount命令强制卸载文件系统的方法,即使提示被占用也照样能够通过命令来卸载。
3. 执行以下命令之后,进入fdisk分区工具,并输入“d”,删除原来的分区“/dev/vdb1”。
fdisk /dev/vdb
屏幕回显如下:
[root@ecs-b656 test]# fdisk /dev/vdb
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): d. ---->删除分区不会导致数据盘内数据的丢失 – 不放心可以先使用‘p’ 即是print打印所有选择
Selected partition 1 ----d 看到一个分区已经删除
Partition 1 is deleted
Command (m for help):
- 输入【n】,按【Enter】,开始新建分区。输入【n】表示新增一个分区。
回显类似如下信息:
Command (m for help): n。 创建分区后 一般情况下全部回车默认即可------然后w 写入 即完成
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
5. 此处分区类型需要与原分区保持一致,以原分区类型是主要分区为例,输入【p】,按【Enter】,开始重新创建一个主分区。
回显类似如下信息:
Select (default p): p
Partition number (1-4, default 1):
Partition number表示主分区编号。
6. 此处分区编号需要与原分区保持一致,以原分区编号是【1】为例,输入分区编号【1】,按【Enter】。
回显类似如下信息:
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
7. 此处必须与原分区保持一致,以步骤1中记录的初始磁柱值2048为例,按【Enter】。
回显类似如下信息:
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
8. 此处截止磁柱值应大于等于步骤1中记录截止磁柱值209715199,以选择默认分配截止磁柱值为2139095039为例,按【Enter】。
回显类似如下信息:
Last sector, +sectors or +size{K,M,G} (2048-2139095040, default 2139095040):
Using default value 2139095040
Partition 1 of type Linux and of size 1000 GiB is set
Command (m for help):
表示分区完成。
9. 输入【p】,按【Enter】,查看新建分区的详细信息。
回显类似如下信息:
Command (m for help): p
Disk /dev/vdb: 1095.2 GB, 1095216660480 bytes, 2139095040 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: 0x6fdb8954
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2139095039 1069546496 83 Linux。 ----已发生变化
Command (m for help):
表示新建分区“/dev/vdb1 ”的详细信息。
10. 输入【w】,按【Enter】,将分区结果写入分区表中。
回显类似如下信息:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
表示分区创建完成。
11. 执行以下命令,检查“/dev/vdb1 ”文件系统的正确性。
e2fsck -f /dev/vdb1
回显类似如下信息:
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1 : 11/655360 files (0.0% non-contiguous), 83137/2621184 blocks
12. 执行以下命令,扩展“/dev/vdb1 ”文件系统的大小。
磁盘已经扩容 但显示还是未扩容状态 用这个命令刷新
#resize2fs /dev/vdb1
[root@ecs-b656 test]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 5242624 (4k) blocks.
The filesystem on /dev/vdb1 is now 5242624 blocks long.
也可能会报错
Linux resize2fs: Bad magic number in super-block
需要确认文件系统是xfs: ext一般不会报错 直接挂载即可
[root@backup binlog]# cat /etc/fstab | grep centos-home
/dev/mapper/centos-home /home xfs defaults 0 0
xfs用以下命令来扩磁盘空间:
[root@backup binlog]# xfs_growfs /dev/mapper/centos-home 即可完成再进行df -H 扩容成功
13. 执行以下命令,将新建分区挂载到“/data”目录下。
mount /dev/vdb1 /data
14. 执行以下命令,查看“/dev/vdb1 ”分区挂载结果。
df -H