Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Convert freebsd ZFS MBR to GPT

edited May 2011 in News
We here at ish use Freebsd for all of our unix technical needs, and with Freebsd comes ZFS. Recently after upgrading to 8.2-RELEASE and then running zpool upgrade on our systems they would no longer boot (getting stuck at the boot loader with the spinning star). While a fix for this has been committed into stable that does not help us getting our systems running again.

I do not recall the reasons why we are using MBR with our machines. Now days you should only be using MBR if you are dual booting with windows. This decision was made years ago when we were installing freebsd 7.0-RELEASE and my only assumption is that for some reason it was not a good idea or we had some difficulties with it. The fact that we were originally creating UFS partitions in the 7.0-RELEASE days probably has something to do with it (Link).

Here is the process I have completed to get our servers running again by converting our mirrors from MBR to GPT.

Firstly download from the Freebsd website the 8.2-RELEASE livefs CD, and boot from it. Once you are in the menu drop to the livefs.

Create a directory so the zpool.cache file is created once you import your ZFS pool
#mkdir -p /boot/zfs
Load ZFS kernel modules
#kldload /mnt2/boot/kernel/opensolaris.ko
#kldload /mnt2/boot/kernel/zfs.ko
Import your ZFS pool, in our case it is called 'tank'
zpool import -f tank
Pick one of the disks in your mirror pool. eg. We have ad6s1a and ad8s1a and then detach the one you choose.
zpool detach tank ad6s1a
Remove MBR partitioning
#gpart destroy -F ad6
Add GPT partitioning
#gpart create -s gpt ad6
#gpart add -b 34 -s 64k -t freebsd-boot ad6
#gpart add -s 4G -t freebsd-swap -l swap0 ad6
#gpart add -t freebsd-zfs -l disk0 ad6 (this will use the rest of the disk)
Install the GPT bootcode
#gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 ad6
Attach our new formatted drive to the tank pool
#zpool attach tank ad8s1a gpt/disk0
Wait for it to resilver! Check it with a #zpool status

Mount your legacy root file system, our root file system is tank/root
#mkdir /tankroot
#mount -t zfs tank/root /tankroot
Copy ZFS cache file over to your live file system.
#cp /boot/zfs/zpool.cache /tankroot/boot/zfs/zpool.cache
Now you can reboot into your live system and we can complete the other disk.

Firstly, you will need to take care of your swap. Right now, you will only have one of the drives swap in use.
#swapinfo
swapinfo
Device 1K-blocks Used Avail Capacity
/dev/ad8s1b 8388608 0 8388608 0%
So firstly, we need to turn on the new swap!
#swapon /dev/gpt/swap0
Turn off the swap for the drive we need to repartition
#swapoff /dev/ad8s1b
You should also have something like the following in your /etc/fstab
/dev/ad8s1b none swap sw 0 0
/dev/ad6s1b none swap sw 0 0
Lets change that to
/dev/gpt/swap0 none swap sw 0 0
/dev/gpt/swap1 none swap sw 0 0
And that will be the end of our swap issues, now can remove the other drive from the mirror and repartition it
#zpool detach tank ad8s1a
Remov the MBR partitioning.
#gpart destroy -F ad8
Add gpt partitioning
#gpart create -s gpt ad8
#gpart add -b 34 -s 64k -t freebsd-boot ad8
#gpart add -s 4G -t freebsd-swap -l swap1 ad8
#gpart add -t freebsd-zfs -l disk1 ad8 (this will use the rest of the disk)
Install the gpt bootcode
#gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ad8
Attach our new formatted drive to the tank pool
#zpool attach tank gpt/disk0 gpt/disk1
And lastly, add the new swap in!
#swapon /dev/gpt/swap1
And there you have it! A converted system with no reinstall!
Sign In or Register to comment.