When you reach a point where you no longer have enough free space on your server and simply adding a new drive and symlinking to it will not really suffice, it’s time to grow the filesystem. When I first skimmed over websites explaining how to do this, it seemed overly complicated. Alll you really need to do is a couple of calculations and then use those numbers as the new parameters.
Modifying the filesystem can be dangerous, so make sure you have a backup of any data you do not want to lose. Luckily, I was working on a virtual server, so I just had to clone it, which takes a little time, but less painful than rebuilding the server and restoring from backup.
The first step is to see the partition table as it currently is:
root@web01:~ > fdisk -s
/dev/da0: 3394 cyl 255 hd 63 sec
Part Start Size Type Flags
1: 63 54524547 0xa5 0×80
root@web01:~ > fdisk
******* Working on device /dev/da0 *******
parameters extracted from in-core disklabel are:
cylinders=3394 heads=255 sectors/track=63 (16065 blks/cyl)
Figures below won’t work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=3394 heads=255 sectors/track=63 (16065 blks/cyl)
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 63, size 54524547 (26623 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>
The current partitions are:
root@web01:~ > df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/da0s1a 248M 166M 62M 73% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/da0s1d 989M 8.3M 902M 1% /tmp
/dev/da0s1f 22G 18G 2.3G 88% /usr
/dev/da0s1e 1.9G 302M 1.5G 17% /var
procfs 4.0K 4.0K 0B 100% /proc
root@web01:~ > disklabel /dev/da0s1
# /dev/da0s1:
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 524288 0 4.2BSD 2048 16384 32776
b: 1048576 524288 swap
c: 54524547 0 unused 0 0 # “raw” part, don’t edit
d: 2097152 1572864 4.2BSD 2048 16384 28552
e: 4194304 3670016 4.2BSD 2048 16384 28552
f: 46660227 7864320 4.2BSD 2048 16384 28552
Here we see that /usr is 46660227 sectors, or ~22G. The size can be checked with the formula:
(46660227/2)/1024 = 22783M
I am adding another 20G of space, reverse the above formula to figure out the size:
42*1024*1024*2 = 88080384 sectors
We can use the final number of sectors to now determine the final size of the entire filesystem:
(88080384-46660227)+54524547 = 95944704 sectors
We also need to figure out how many cylinders will be used, (16065 sectors/cylinder):
95944704/16065 = 5972
The summary of changes to be made (and adjustments I had to make to account for inaccuracies in the formulas translating to the actual disk structure):
cylinders: 3394 -> 5972 (6004 this change was made automatically by the system)
c: 54524547 -> 95944704 (95940117 this was adjusted by fdisk)
d: 46660227 -> 88080384 (88075797 this was figured by subtracting the same number of sectors that fdisk dropped to properly align the cylinder boundary)
I had to make those adjustments to avoid getting error messages after running fdisk.
**At this point you will need to log into single user mode and then mount /tmp
# mount /tmp
# fdisk -u
******* Working on device /dev/da0 *******
parameters extracted from in-core disklabel are:
cylinders=6004 heads=255 sectors/track=63 (16065 blks/cyl)
Figures below won’t work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=6004 heads=255 sectors/track=63 (16065 blks/cyl)
Do you want to change our idea of what BIOS thinks? [n]
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 63, size 54524547 (26623 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 1023/ head 254/ sector 63
Do you want to change it? [n] y
Supply a decimal value for “sysid (165=FreeBSD)” [165]
Supply a decimal value for “start” [63]
Supply a decimal value for “size” [54524547] 184025088
fdisk: WARNING: partition does not end on a cylinder boundary
fdisk: WARNING: this may confuse the BIOS or some operating systems
Correct this automatically? [n] y
fdisk: WARNING: adjusting size of partition to 184024512
Explicitly specify beg/end address ? [n] y
Supply a decimal value for “beginning cylinder” [0]
Supply a decimal value for “beginning head” [1]
Supply a decimal value for “beginning sector” [1]
Supply a decimal value for “ending cylinder” [1023] 5972
Supply a decimal value for “ending head” [254]
Supply a decimal value for “ending sector” [63]
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 63, size 95940117 (46845 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 852/ head 254/ sector 63
Are we happy with this entry? [n] y
The data for partition 2 is:
<UNUSED>
Do you want to change it? [n]
The data for partition 3 is:
<UNUSED>
Do you want to change it? [n]
The data for partition 4 is:
<UNUSED>
Do you want to change it? [n]
Partition 1 is marked active
Do you want to change the active partition? [n]
We haven’t changed the partition table yet. This is your last chance.
parameters extracted from in-core disklabel are:
cylinders=3394 heads=255 sectors/track=63 (16065 blks/cyl)
Figures below won’t work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=3394 heads=255 sectors/track=63 (16065 blks/cyl)
Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
start 63, size 95940117 (46845 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 852/ head 254/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
Should we write new partition table? [n] y
Then I rebooted and choose single user mode again:
# fdisk -s
/dev/da0: 6004 cyl 255 hd 63 sec
Part Start Size Type Flags
1: 63 95940117 0×06 0×00
#mount /tmp
#mount /usr
#disklabel -e -r /dev/da0s1
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 524288 0 4.2BSD 2048 16384 32776
b: 1048576 524288 swap
c: 54524547 0 unused 0 0 # “raw” part, don’t edit
d: 2097152 1572864 4.2BSD 2048 16384 28552
e: 4194304 3670016 4.2BSD 2048 16384 28552
f: 46660227 7864320 4.2BSD 2048 16384 28552
#
Here we change:
c: 5452547 -> 95940117
f: 46660227 -> 88075797
Next we unmount /usr and will use growfs to grow it.
#umount /usr
#growfs -s 88075797 /dev/da0s1f
Once growfs is finished, mount /usr again and check your partitions with df -h:
# mount /usr
# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/da0s1a 248M 166M 62M 73% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/da0s1d 989M 8.3M 902M 1% /tmp
/dev/da0s1e 1.9G 302M 1.5G 17% /var
/dev/da0s1f 41G 18G 20G 47% /usr
#
Then we can run fsck to make sure the drive is ok. Once you are done, reboot in regular mode and you are done.