Resize root (/)

I have read about 10 different sets of instructions on how to resize my root partition. Many of them don't apply because of different file systems, different partition tables, and different versions of FreeBSD. So, here I am asking the question like so many have before, but mine is slightly different :)

I originally installed something like FreeBSD 5 on this machine, and the parition / slice layout has remained the same. In the last few upgrades, I haven't had room for /boot/kernel.old anymore, having to purge it to upgrade the kernel. Now, it is at the point where /boot/kernel barely fits. I could probably disable some kernel modules that I don't need, but I thought I should grow the root partition.

Here is the situation:

Code:
$bsdlabel mfid0s1
# /dev/mfid0s1:
8 partitions:
#          size     offset    fstype   [fsize bsize bps/cpg]
  a:    1048576          0    4.2BSD     2048 16384     8
  b:    8388608    1048576      swap
  c:  974117277          0    unused        0     0     # "raw" part, don't edit
  d:   10452992    9437184    4.2BSD     2048 16384 28528
  e:    1048576   19890176    4.2BSD     2048 16384     8
  f:  953178525   20938752    4.2BSD     2048 16384 28528

Code:
$df
Filesystem    1K-blocks     Used     Avail Capacity  Mounted on
/dev/mfid0s1a    507630   471508     -4488   101%    /
devfs                 1        1         0   100%    /dev
/dev/mfid0s1e    507630     6178    460842     1%    /tmp
/dev/mfid0s1f 461587862 19653692 405007142     5%    /usr
/dev/mfid0s1d   5060654  2026636   2629166    44%    /var
fdescfs               1        1         0   100%    /dev/fd

Code:
$gpart show
=>       63  974127041  mfid0  MBR  (465G)
         63  974117277      1  freebsd  [active]  (464G)
  974117340       9764         - free -  (4.8M)

=>        0  974117277  mfid0s1  BSD  (464G)
          0    1048576        1  freebsd-ufs  (512M)
    1048576    8388608        2  freebsd-swap  (4.0G)
    9437184   10452992        4  freebsd-ufs  (5.0G)
   19890176    1048576        5  freebsd-ufs  (512M)
   20938752  953178525        6  freebsd-ufs  (455G)

Code:
FreeBSD - 10.0-RELEASE-p9 FreeBSD 10.0-RELEASE-p9 #2 r272394M: Thu Oct  2 23:18:05 PDT 2014

My thought was to steal some space from the swap, since it is directly after the root partition. I'm not sure of the correct way to do this. If possible, I would like to do it live, but I can drop it to single user after hours.
 
Re: Resize root (/) slice

Thank you. I will create a swap file as you mentioned, and delete the swap partition.

What is the right way to grow the root partition? Do I just edit the table with bsdlabel?
 
Re: Resize root (/) slice

Hmm, something odd going on. I followed the instructions to get the swap file, but it doesn't seem to be using it:

root@server:/$ls /usr/swap0 -al
-rw------- 1 root wheel 4294967296 Oct 3 15:54 /usr/swap0
root@server:/$grep swap /etc/fstab
#/dev/mfid0s1b none swap sw 0 0
md99 none swap sw,file=/usr/swap0 0 0
root@server:/$swapon -qa
root@server:/$swapinfo
Device 1K-blocks Used Avail Capacity
root@server:/$
 
Re: Resize root (/) slice

Success! Thanks for your help. The sequence of commands, as near as I recall, are below.

Code:
$dd if=/dev/zero of=/usr/swap0 bs=1m count=4096
$chmod 0600 /usr/swap0

added following line to fstab:

Code:
md99    none    swap    sw,file=/usr/swap0      0       0

Code:
$swapoff /dev/mfid0s1b

remove following line from fstab:

Code:
/dev/mfid0s1b          none            swap    sw              0       0

Code:
$swapon -aqL
$gpart delete -i 2 mfid0s1
$gpart resize -i 1 -a 4k mfid0s1
$growfs /dev/mfid0s1a
$df
Filesystem    1K-blocks     Used     Avail Capacity  Mounted on
/dev/mfid0s1a   4569322   471508   3732270    11%    /
devfs                 1        1         0   100%    /dev
/dev/mfid0s1e    507630     6178    460842     1%    /tmp
/dev/mfid0s1f 461587862 23850098 400810736     6%    /usr
/dev/mfid0s1d   5060654  2026642   2629160    44%    /var
fdescfs               1        1         0   100%    /dev/fd
 
Back
Top