背景:
由于历史遗留问题,Freebsd 系统盘出厂大小是 20G,即使购买的系统盘大小大于 20G,系统内分配的也是 20G 大小,那么云上的 Freebsd 如何扩容系统盘呢?
怂一下先:
请对生产环境,保持敬畏之心,务必做好快照备份!
请对生产环境,保持敬畏之心,务必做好快照备份!
请对生产环境,保持敬畏之心,务必做好快照备份!
1,查看磁盘信息,不同于 CentOS/Ubuntu系统使用fdisk,
Freebsd 使用gpart 查看磁盘分区信息
# gpart show
=> 63 83886017 vtbd0 MBR (40G)
63 1 - free - (512B)
64 41942975 1 freebsd [active] (20G)(在用的)
41943039 41943041 - free - (20G) (空闲的)
注:根据官方资料介绍,可以到 /var/run/dmesg.boot 看设备信息,但尴尬的是云上IO优化实例使用KVM的虚拟化技术后,该文件记录似乎不准了(文件记录的是ufs的挂载),因此使用gpart show直接查看
Determine the device name of the disk to be resized by inspecting /var/run/dmesg.boot. In this example, there is only one SATA disk in the system, so the drive will appear as ada0.
2,恢复磁盘的空闲大小(新购系统的扩容理论上可以忽略这一步)
# gpart recover vtbd0
vtbd0 recovering is not needed
3,扩容分区
# gpart resize -i 1 -a 4k -s 39G vtbd0
vtbd0s1 resized
# gpart show
=> 63 83886017 vtbd0 MBR (40G)
63 1 - free - (512B)
64 81788928 1 freebsd [active] (39G)
81788992 2097088 - free - (1.0G)
注:
-i 1 类似于扩容的分区是/dev/vda1
-a 4k 4k对齐
-s 39G 扩容后大小
由于有启动分区的占用,因此不能写满 40G,写满的话会报错
# gpart resize -i 1 -a 4k -s 40G vtbd0
gpart: size '83886080': Invalid argument
4,文件系统扩容
# service growfs onestart
Growing root partition to fill device
vtbd0s1 resized
super-block backups (for fsck_ffs -b #) at:
42314112, 43596352, 44878592, 46160832, 47443072, 48725312, 50007552, 51289792, 52572032, 53854272, 55136512, 56418752, 57700992, 58983232, 60265472, 61547712,
62829952, 64112192, 65394432, 66676672, 67958912, 69241152, 70523392, 71805632, 73087872, 74370112, 75652352, 76934592, 78216832, 79499072, 80781312, 82063552,
83345792
# gpart show
=> 63 83886017 vtbd0 MBR (40G)
63 1 - free - (512B)
64 83886016 1 freebsd [active] (40G)
# df -lh
Filesystem Size Used Avail Capacity Mounted on
/dev/ufsid/59a7effe7885633c 39G 3.9G 32G 11% /
devfs 1.0K 1.0K 0B 100% /dev
扩容成功~
参考资料:
https://www.freebsd.org/doc/handbook/disks-growing.html