Monday, 9 May 2016

(Live Environment) Resize Root Filesystem -BSD

I was running out of space on my FreeBSD machine and I decided to expand the root partition (and the fileystem on it).Before any changes, here is what I had:

thenabx@mst:~$gpart show da0

=>      34  31457213  da0  GPT  (15G)
        34       128    1  freebsd-boot  (64K)
       162  29360000    2  freebsd-ufs  (14G)
  29360162   1572864    3  freebsd-swap  (768M)

  30933026    524221       - free -  (256M)

Then I powered down the system and increased the space on the FreeBSD VM. After that I powered it on and saw the new free space:

thenabx@mst:~$gpart show da0
=>      34  52428733  da0  GPT  (25G)
        34       128    1  freebsd-boot  (64K)
       162  29360000    2  freebsd-ufs  (14G)
  29360162   1572864    3  freebsd-swap  (768M)

  30933026  21495741       - free -  (10G)

Since I will be doing this on a mounted system I had to disable the GEOM safety features:

thenabx@mst:~$sudo sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16

NOTE: after a reboot, this will be reset to the default setting.
Since the swap partition is in the middle of our partitions, we have to disable it. I had it as the 3rd partition:

thenabx@mst:~$swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/da0p3         786432        0   786432     0%
Then I ran the following to disable it:

thenabx@mst~$sudo swapoff /dev/da0p3

thenabx@mst:~$swapinfo
Device          1K-blocks     Used    Avail Capacity
Then to delete the partition:

thenabx@mst:~$sudo gpart delete -i 3 da0

da0p3 deleted
thenabx@mst:~$gpart show da0
=>      34  52428733  da0  GPT  (25G)
        34       128    1  freebsd-boot  (64K)
       162  29360000    2  freebsd-ufs  (14G)
  29360162  23068605       - free -  (11G)

Now let’s resize the second partition, which is the root partition:

thenabx@mst:~$df -Ph
Filesystem    Size    Used   Avail Capacity  Mounted on
/dev/da0p2     14G     12G    565M    96%    /
devfs         1.0K    1.0K      0B   100%    /dev

thenabx@mst:~$sudo gpart resize -i 2 -a 4k -s 24G da0
da0p2 resized
thenabx@mst:~$gpart show da0
=>      34  52428733  da0  GPT  (25G)
        34       128    1  freebsd-boot  (64K)
       162  50331646    2  freebsd-ufs  (24G)
  50331808   2096959       - free -  (1.0G)

Now let’s re-create the swap partition:

thenabx@mst:~$sudo gpart add -t freebsd-swap -a 4k -s 768M da0
da0p3 added
thenabx@mst:~$gpart show da0
=>      34  52428733  da0  GPT  (25G)
        34       128    1  freebsd-boot  (64K)
       162  50331646    2  freebsd-ufs  (24G)
  50331808   1572864    3  freebsd-swap  (768M)

  51904672    524095       - free -  (256M)

And If you're on FreeBSD 10.X you can also proceed with "growfs"

thenabx@MST:~$sudo growfs /dev/da0p2
Device is mounted read-write; resizing will result in temporary write suspension for /.
It's strongly recommended to make a backup before growing the file system.
OK to grow filesystem on /dev/da0p2, mounted on /, from 14GB to 24GB? [Yes/No] yes
super-block backups (for fsck -b #) at:
 29491712, 30773952, 32056192, 33338432, 34620672, 35902912, 37185152,
 38467392, 39749632, 41031872, 42314112, 43596352, 44878592, 46160832,

 47443072, 48725312, 50007552

It looked good (and it was really quick so I wasn’t worried about any writes getting delayed):

thenabx@MST:~$df -Ph

Filesystem    Size    Used   Avail Capacity  Mounted on
/dev/da0p2     23G     12G    9.5G    56%    /
devfs         1.0K    1.0K      0B   100%    /dev


I then rebooted the system one more time to make sure all is well and it was.

That's All Please leave your comments below.

No comments:

Post a Comment