操作系统:CentOS 7.2 ,文件类型:ext3
磁盘扩容前,一定要先做磁盘快照备份。
1.卸载挂载点报错:
umount /dev/vdb1
umount: /u01: target is busy.
(In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
使用fuser -k /dev/vdb1 找不到关联的进程;同时使用lsof |grep /dev/vdb1 也找不到关联的进程。
解决方法:重启服务器后停止了云镜、httpd、nfs等服务后成功卸载数据盘
使用:e2fsck -f /dev/vdb1 > aa.txt & 扫描修复磁盘,300G磁盘执行这条命令需要2个小时。
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: 2892836/19660800 files (14.7% non-contiguous), 72828039/78642944 blocks
执行命令:resize2fs /dev/vdb1 #没有报错,但磁盘也没有扩容。
resize2fs 1.42.9 (28-Dec-2013) The filesystem is already 78642944 blocks long. Nothing to do!
执行:fdisk -l /dev/vdb1 #查看磁盘空间
Disk /dev/vdb1: 322.1 GB, 322121498624 bytes, 629143552 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
更换另一种方式:
wget -O /tmp/devresize.py https://raw.githubusercontent.com/tencentyun/tencentcloud-cbs-tools/master/devresize/devresize.py ssh -o ServerAliveInterval=60000 user@sshserver #避免ssh因长时间没有输入而断开连接
nohup python /tmp/devresize.py /dev/vdb > result.txt & #这里需要使用磁盘/dev/vdb,而不是分区/dev/vdb1。300G磁盘执行这条命令需要3个小时。
a.命令执行时间过长,出现Write failed: Broken pipe ssh连接断开的问题。连接断开后,执行就失败了。
b.在执行命令的过程中,不能断开远程服务器的连接,否则也会执行失败。如使用命令:python /tmp/devresize.py /dev/vdb > result.txt & 。在断开window远程服务器的连接后,xshell窗口中的执行任务,也会自动中断。
后续改进:把文件系统格式从ext3切换到ext4后,会缩减磁盘扩容的时间。
操作系统:CentOS 7.2 ,文件类型:ext3,把格式转换成ext4
ssh -o ServerAliveInterval=30 root@10.0.1.24
fdisk -l /dev/vdb1
service httpd stop
fuser -um -v /dev/vdb1
systemctl stop YDService
systemctl stop nfs
!umo
tune2fs -O extents,uninit_bg,dir_index /dev/vdb1
fsck -pf /dev/vdb1
mount -t ext4 /dev/vdb1 /u01
vim /etc/fstab
/dev/vdb1 /u01 ext4 defaults 0 0
df -T 只可以查看已经挂载的分区和文件系统类型。
fdisk -l 可以显示出所有挂载和未挂载的分区,但不显示文件系统类型。
file -s /dev/vdb1