So the other day I attempted to upgrade my ZFS zpool on FreeBSD. After the move, it's been quite hecting and I have not had the time to do some TLC housekeeping on my BSD farm. The systems returned a message saying that I have to update my boot code. Unfortunately one of the systems had too small of a boot partition and there was not enough room to write the new bootcode.

$ sudo zpool upgrade tank
This system supports ZFS pool feature flags.

Enabled the following features on 'tank':
  sha512
  skein
  device_removal
  obsolete_counts
  zpool_checkpoint

If you boot from pool 'tank', don't forget to update boot code.
Assuming you use GPT partitioning and da0 is your boot disk
the following command will do it:

        gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0
$ sudo gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
gpart: /dev/ada0p1: not enough space

Well crap #1....We don't have enough space. Let's do some digging around.

$ gpart show
=>       34  250069613  ada0  GPT  (119G)
         34          6        - free -  (3.0K)
         40       1024     1  freebsd-boot  (64K)
       1064    8387712     2  freebsd-swap  (4.0G)
    8388776  241680864     3  freebsd-zfs  (115G)
  250069640          7        - free -  (3.5K)

$ du -sh /boot/gptzfsboot
117K    /boot/gptzfsboot

Our current freebsd-boot partition is only 64K but the /boot/gptzfsboot file is 117K.

What do we do?

What we need to do is remove freebsd-boot and freebsd-swap partitions in order to create a larger freebsd-boot partition with 512K size. Easy Peasy. Let's try that...

Start off with disabling SWAP before we delete its partition:

$ swapoff -a
swapoff: /dev/gptid/dc62e18d-25a7-11e6-9df9-50465d51d4d1: Cannot allocate memory

Well crap #2....

We can't disable swap partition temporarily as there is something in the swap memory already!

Alright alright. Take a deep breath. Moving on... -_-

Create a new ZFS-based swap filesystem.

$ zfs create -V 4G -o org.freebsd:swap=on -o checksum=off -o compression=off -o dedup=off -o sync=disabled -o primarycache=none tank/swap

Four gigs will do. Enable the partition and disable the old swap that we're trying to remove to gain some extra space.

$ swapon /dev/zvol/tank/swap
$ swapoff /dev/gptid/dc62e18d-25a7-11e6-9df9-50465d51d4d1
$ swapctl -l

Delete the old boot and swap partition:

$ gpart delete -i 1 ada0
$ gpart delete -i 2 ada0

Great. That worked.

Add new partitions:

$ gpart add -b 40 -s 512K ada -t freebsd-boot ada0
$ gpart add -t freebsd-swap ada0

Print the partition table:

$ gpart show
=>       34  250069613  ada0  GPT  (119G)
         34          6        - free -  (3.0K)
         40       1024     1  freebsd-boot  (512K)
       1064    8387712     2  freebsd-swap  (4.0G)
    8388776  241680864     3  freebsd-zfs  (115G)
  250069640          7        - free -  (3.5K)

Setup the bootloader on the new partition (you know, the thing we tried to do in the beginning):

$ gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
$ partcode written to ada0p1
$ bootcode written to ada0

Don't forget to disable ZFS-based swap partition and to update /etc/fstab with new swap!

$ swapon -F /etc/fstab /dev/gptid/618812bd-d1b9-11e8-b735-50465d51d4d1
$ swapoff /dev/zvol/tank/swap

Comments

comments powered by Disqus