概述
云平台客户的服务器可能会随着业务量的不断增长造成磁盘空间不足的情况,比如:共享文件服务器硬盘空间不足,在这个时候就需要增加磁盘空间,来满足线上的业务;又或者我们在使用linux的过程中, 有时会因为安装系统时分区不当导致有的分区空间不足,而有的分区空间过剩的情况,都可以是使用fdisk分区工具来动态调整分区的大小;
步骤
1.备份
就算是无损的扩容,但难免会出什么意外,备份是必不可少的,一般云平台都有备份功能,可直接对磁盘做一次全量备份。
2.用fdisk重新分区
默认的分区如下
root@i-abnawjwo:/# dfFilesystem 1K-blocks Used Available Use% Mounted onudev 497752 4 497748 1% /devtmpfs 101700 440 101260 1% /run/dev/sda1 20509308 1337636 18106816 7% /none 4 0 4 0% /sys/fs/cgroupnone 5120 0 5120 0% /run/locknone 508488 0 508488 0% /run/shmnone 102400 0 102400 0% /run/user/dev/sdc1 10190136 23032 9626432 1% /dataroot@i-abnawjwo:/data# cat hellotest1
卸载当前的分区 umount /dev/sdc1
若是卸载不掉,有可能是有进程再用,可以用fuser或者lsof查看
fuser -m -v /datafuser -m -v -i -k /datalsof /data
卸载掉后fdisk删除原来的分区,重新分区, 注意开始的磁柱号要和原来的一致(这是保证数据不丢失的关键步骤)
root@i-abnawjwo:/# umount /dataroot@i-abnawjwo:/# fdisk /dev/sdcCommand (m for help): dSelected partition 1Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p):Using default response pPartition number (1-4, default 1):Using default value 1First sector (2048-104857599, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):Using default value 104857599Command (m for help): pDisk /dev/sdc: 53.7 GB, 53687091200 bytes64 heads, 32 sectors/track, 51200 cylinders, total 104857600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x305cddae Device Boot Start End Blocks Id System/dev/sdc1 2048 104857599 52427776 83 LinuxCommand (m for help): wqThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
重启系统
3.检测分区,扩展分区大小
root@i-abnawjwo:~# e2fsck -f /dev/sdb1e2fsck 1.42.9 (4-Feb-2014)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/sdb1: 12/655360 files (0.0% non-contiguous), 79664/2621440 blocksroot@i-abnawjwo:~# resize2fs -p /dev/sdb1resize2fs 1.42.9 (4-Feb-2014)Resizing the filesystem on /dev/sdb1 to 13106944 (4k) blocks.The filesystem on /dev/sdb1 is now 13106944 blocks long.
4.重新挂载,查看分区大小,检查数据
新闻热点
疑难解答