Understanding harddisks in openbsd
Disk Partitioning Schemes
OpenBSD:
- The "a" slice (= partition) is always the
root (/)
of your machine. - The "b" slice is always the
swap
of your machine. - The "c" slice is always your
entire disk
. You cannot delete, remove or modify the "c" slice!
Differences between Linux and OpenBSD
Things that are different between the OpenBSD and Linux partitioning schemes:
Category | Linux | OpenBSD |
---|---|---|
Disk names | letters (a, b, c, etc...) | numbers (0, 1, 2, etc...) |
Partitions on a disk | numbers | letters |
Counting scheme | starts counting from "1" | starts counting from "0" |
Example | Linux | OpenBSD |
---|---|---|
First disk | /dev/hda | /dev/wd0 |
First partition on second hard disk | /dev/hdb1 | /dev/wd1a |
Counting scheme | /dev/hda1 /dev/hda2 /dev/hda3, etc... | /dev/wd0a /dev/wd0b /dev/wd0c, etc... |
Gain more free space
Abstract
- Expand the underlying volume
- Tell the system to use the entire disk
- Modify the slices
- Create the filesystem according to the slices
Notes
In the following text it is assumed that the underlying volume (A6 - OpenBSD) was already expanded either by reszing the virtual disk or by changing hardware in the box.
It is also assumed that the harddisk is /dev/sd0
.
For simplicity this system has only one big root partition and swap.
Everything is done within OpenBSD's rescue disk kernel
bsd.rd
. Because no one likes to have separate CD-ROM / USB rescue live utilities ;-)
Start
Boot into the system's rescue disk
Boot bsd.rd
by enter this at the kernel boot prompt:
> boot bsd.rd
Then select (S)hell
at the prompt.
Re-initialize the MBR, using the entire disk.
# fdisk -i sd0
Do you wish to write new MBR and partition table? [n] y
Writing MBR at offset 0.
Modify the slices
Now we had free space added to the end of a volume.
We have two options now: either resizing an existing slice or adding a new slice.
Option 1: Resize an OpenBSD Partition
Remembering the notes above, this system has only the root partition and swap. The idea is to remove the swap partition, then extend root, and finally put the swap partition back.
Later we need growfs(8)
which isn't included with the rescue disk,
thats why first we grab it from the existing root partition.
# mount /dev/sd0a /mnt
# cp /mnt/sbin/growfs .
# umount /mnt
Now change the size of the slices:
# disklabel -E sd0
# Inside MBR partition 3: type A6 start 63 size 20964762
Treating sectors 63-20964825 as the OpenBSD portion of the disk.
You can use the 'b' command to change this.
Initial label editor (enter '?' for help at any prompt)
> p
OpenBSD area: 63-20964825; size: 20964762; free: 9446220
# size offset fstype [fsize bsize cpg]
a: 10490382 63 4.2BSD 2048 16384 1
b: 1028160 10490445 swap
c: 20971520 0 unused
> d
partition to delete: [] b
> p
OpenBSD area: 63-20964825; size: 20964762; free: 10474380
# size offset fstype [fsize bsize cpg]
a: 10490382 63 4.2BSD 2048 16384 1
c: 20971520 0 unused
> c
partition to change size: [] a
Partition a is currently 10490382 sectors in size, and can have a maximum
size of 20964762 sectors.
size: [10490382] 9G
Rounding to cylinder: 18876312
> a b
offset: [18876375]
size: [2088450]
FS type: [swap]
> p
OpenBSD area: 63-20964825; size: 20964762; free: 0
# size offset fstype [fsize bsize cpg]
a: 18876312 63 4.2BSD 2048 16384 1
b: 2088450 18876375 swap
c: 20971520 0 unused
> w
> q
No label changes.
Create the filesystem
Grow the filesystem using growfs(8)
:
# growfs /dev/sd0a
We strongly recommend you to make a backup before growing the Filesystem
Did you backup your data (Yes/No) ? Yes
new file systemsize is: 4719078 frags
Warning: 216792 sector(s) cannot be allocated.
growfs: 9111.1MB (18659520 sectors) block size 16384, fragment size 2048
using 45 cylinder groups of 202.47MB, 12958 blks, 25984 inodes.
super-block backups (for fsck -b #) at:
10781088, 11195744, 11610400, 12025056, 12439712, 12854368, 13269024, 13683680, 14098336, 14512992, 14927648, 15342304, 15756960, 16171616, 16586272, 17000928, 17415584, 17830240,
18244896
...and do a last check:
# fsck /dev/sd0a
** /dev/rsd0a
** Last Mounted on /
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cyl groups
100205 files, 418854 used, 4172217 free (97 frags, 521515 blocks, 0.0% fragmentation)
MARK FILE SYSTEM CLEAN? [Fyn?] y
***** FILE SYSTEM WAS MODIFIED *****
Option 2: Add a New Partition to OpenBSD
Remembering the notes above, this system has only the root partition
and swap. Now we create the new slice as the "d" slice and then put
/home
onto it.
Add a new slice for /home
(the "d" slice)
# disklabel -E sd0
Label editor (enter '?' for help at any prompt)
> p
OpenBSD area: 64-251658225; size: 251658161; free: 209728575
# size offset fstype [fsize bsize cpg]
a: 38812976 64 4.2BSD 2048 16384 38128
b: 3116610 38813040 swap
c: 251658240 0 unused
> a
partition: [d]
offset: [41929650]
size: [209728575]
FS type: [4.2BSD]
Rounding offset to bsize (32 sectors): 41929664
Rounding size to bsize (32 sectors): 209728544
> p
OpenBSD area: 64-251658225; size: 251658161; free: 31
# size offset fstype [fsize bsize cpg]
a: 38812976 64 4.2BSD 2048 16384 38128
b: 3116610 38813040 swap
c: 251658240 0 unused
d: 209728544 41929664 4.2BSD 2048 16384 1
> w
> q
No label changes.
Create the filesystem
# newfs /dev/rsd0d
/dev/rsd0d: 102406.5MB in 209728544 sectors of 512 bytes
506 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each
super-block backups (for fsck -b #) at:
32, 414688, 829344, 1244000, 1658656, 2073312, 2487968, 2902624, 3317280,
3731936, 4146592, 4561248, 4975904, 5390560, 5805216, 6219872, 6634528,
7049184, 7463840, 7878496, 8293152, 8707808, 9122464, 9537120, 9951776,
...
[snip]
...
193229728, 193644384, 194059040, 194473696, 194888352, 195303008, 195717664,
196132320, 196546976, 196961632, 197376288, 197790944, 198205600, 198620256,
199034912, 199449568, 199864224, 200278880, 200693536, 201108192, 201522848,
201937504, 202352160, 202766816, 203181472, 203596128, 204010784, 204425440,
204840096, 205254752, 205669408, 206084064, 206498720, 206913376, 207328032,
207742688, 208157344, 208572000, 208986656, 209401312,
Migrate /home
Here, we mount the existing root filesystem (which contains the old
/home
) and also the new filesystem.
Finally migrate the data from old /home
to new space with tar(1)
copying everything from one directory to another, preserving everything
(permissions, etc...).
# mount /dev/sd0a /mnt
# mount /dev/sd0d /mnt2
# (cd /mnt/home; tar cf - .) | (cd /mnt2; tar xpf -)
# rm -rf /mnt/home
# mkdir /mnt/home
Don't forget to add the new /home
to /etc/fstab
and mount it on
boot:
# echo "/dev/sd0d /home ffs rw,softdep 0 1" >> /mnt/etc/fstab
# umount /mnt*
# reboot