5.4 KiB
Expanding a FreeBSD FileSystem on a VM
If a VM is getting a bit tight for disk space, you can expand the size of a drive. This example is the more difficult one of expanding the primary drive. The example uses the instance name work0psg.com, which should be replaced by your own, of course.
Tell Ganeti to Grow the Disk
First you need to make the Ganeti disk allocation larger.
gnt-instance grow-disk work0.psg.com 0 100G
grows the priimary drive by 100G.
This allocates more disk in Ganeti and creates a larger partition. But it does not tell FreeBSD that the disk is bigger.
Also, like many gnt-instance modify commands, it will not take effect until the next Ganeti start, not reboot within the VM, but a real Ganeti instance reboot or shutdown/start.
It is Best to do this in Single User
Boot into single user
Enter full pathname of shell or RETURN for /bin/sh:
Set-Up
Confirm the disk is allocated as expected. Note that the new allocation will not show yet.
:/# gpart show vtbd0
=> 34 209715133 vtbd0 GPT (200G) [CORRUPT]
34 128 1 freebsd-boot (64K)
162 201326464 2 freebsd-ufs (96G)
201326626 8388540 3 freebsd-swap (4.0G)
209715166 1 - free - (512B)
Everything says to turn swap off, but I think it is normall off in single user
:/# swapoff /dev/vtbd0p3
swapoff: /dev/vtbd0p3: Invalid argument
Get FreeBSD to See the New Space
Tell gpart to find the new space
:/# gpart recover vtbd0
vtbd0 recovered
Now we can see the new space
:/# gpart show vtbd0
=> 34 419430333 vtbd0 GPT (200G)
34 128 1 freebsd-boot (64K)
162 201326464 2 freebsd-ufs (96G)
201326626 8388540 3 freebsd-swap (4.0G)
209715166 209715201 - free - (100G)
Get Swap Out of the Way and Expand the Partition
Get the swap partition out of the way
:/# gpart delete -i 3 vtbd0
vtbd0p3 deleted
:/# gpart show vtbd0
=> 34 419430333 vtbd0 GPT (200G)
34 128 1 freebsd-boot (64K)
162 201326464 2 freebsd-ufs (96G)
201326626 218103741 - free - (104G)
Grow the data partition, being sure to leave room for the swap partition
:/# gpart resize -i 2 -a 4k -s 196G vtbd0
vtbd0p2 resized
See that it grew.
:/# gpart show vtbd0
=> 34 419430333 vtbd0 GPT (200G)
34 128 1 freebsd-boot (64K)
162 411041790 2 freebsd-ufs (196G)
411041952 8388415 - free - (4.0G)
Make a Swap Partition
Recreate a swap partiton
:/# gpart add -t freebsd-swap -a 4k vtbd0
vtbd0p3 added
See that it is as expected
:/# gpart show vtbd0
=> 34 419430333 vtbd0 GPT (200G)
34 128 1 freebsd-boot (64K)
162 411041790 2 freebsd-ufs (196G)
411041952 8388408 3 freebsd-swap (4.0G)
419430360 7 - free - (3.5K)
Turn swap on, but probably not needed in single user
:/# swapon /dev/vtbd0p3
Tell FreeBSD to Expand the FileSystem to Fill Partition
The last move is to tell FreeBSD to detect the larger space and grow the file system to fill it
:/# growfs /dev/vtbd0p2
It's strongly recommended to make a backup before growing the file system.
OK to grow filesystem on /dev/vtbd0p2, mounted on /, from 96GB to 196GB? [Yes/No] Yes
super-block backups (for fsck_ffs -b #) at:
201352064, 202634560, 203917056, 205199552, 206482048, 207764544, 209047040,
210329536, 211612032, 212894528, 214177024, 215459520, 216742016, 218024512,
219307008, 220589504, 221872000, 223154496, 224436992, 225719488, 227001984,
228284480, 229566976, 230849472, 232131968, 233414464, 234696960, 235979456,
237261952, 238544448, 239826944, 241109440, 242391936, 243674432, 244956928,
246239424, 247521920, 248804416, 250086912, 251369408, 252651904, 253934400,
255216896, 256499392, 257781888, 259064384, 260346880, 261629376, 262911872,
264194368, 265476864, 266759360, 268041856, 269324352, 270606848, 271889344,
273171840, 274454336, 275736832, 277019328, 278301824, 279584320, 280866816,
282149312, 283431808, 284714304, 285996800, 287279296, 288561792, 289844288,
291126784, 292409280, 293691776, 294974272, 296256768, 297539264, 298821760,
300104256, 301386752, 302669248, 303951744, 305234240, 306516736, 307799232,
309081728, 310364224, 311646720, 312929216, 314211712, 315494208, 316776704,
318059200, 319341696, 320624192, 321906688, 323189184, 324471680, 325754176,
327036672, 328319168, 329601664, 330884160, 332166656, 333449152, 334731648,
336014144, 337296640, 338579136, 339861632, 341144128, 342426624, 343709120,
344991616, 346274112, 347556608, 348839104, 350121600, 351404096, 352686592,
353969088, 355251584, 356534080, 357816576, 359099072, 360381568, 361664064,
362946560, 364229056, 365511552, 366794048, 368076544, 369359040, 370641536,
371924032, 373206528, 374489024, 375771520, 377054016, 378336512, 379619008,
380901504, 382184000, 383466496, 384748992, 386031488, 387313984, 388596480,
389878976, 391161472, 392443968, 393726464, 395008960, 396291456, 397573952,
398856448, 400138944, 401421440, 402703936, 403986432, 405268928, 406551424,
407833920, 409116416, 410398912
And Bob's your uncle!
:/# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/vtbd0p2 190G 86G 89G 49% /
devfs 1.0K 1.0K 0B 100% /dev