背景:
由于曆史遺留問題,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