Creating a mirror from your zroot

I planned to create a zroot mirror when I installed FreeBSD on the R720 but the supplier shipped only one of the two purchased SSDs.

Today the second drive arrived.

Let’s create a zroot mirror.

In this post:

Posts I looked at:

Partitioning

In this section, the partition table for the second drive is copied from the first drive.

This is the existing boot drive. Let’s see what backup gives us:

[root@r720-01 ~]# /sbin/gpart backup ada0 
GPT 152
1   freebsd-boot        40      1024 gptboot0 
2   freebsd-swap      2048   4194304 swap0 
3    freebsd-zfs   4196352 152104960 zfs0 

This command copies it to the other drive, ada1:

[root@r720-01 ~]# /sbin/gpart backup ada0 | /sbin/gpart restore -F ada1

Let’s compare results:

[root@r720-01 ~]# gpart show ada1 ada0
=>       40  156301408  ada1  GPT  (75G)
         40       1024     1  freebsd-boot  (512K)
       1064        984        - free -  (492K)
       2048    4194304     2  freebsd-swap  (2.0G)
    4196352  152104960     3  freebsd-zfs  (73G)
  156301312        136        - free -  (68K)

=>       40  156301408  ada0  GPT  (75G)
         40       1024     1  freebsd-boot  (512K)
       1064        984        - free -  (492K)
       2048    4194304     2  freebsd-swap  (2.0G)
    4196352  152104960     3  freebsd-zfs  (73G)
  156301312        136        - free -  (68K)

[root@r720-01 ~]# 

Labels! I forgot labels

Labels are not required. I do them.

I use the labels when I add the drive to the pool

I remembered how by reading Adding a zroot pool to an existing system.

Look at the labels on the existing drive:

[root@r720-01 ~]# gpart show -l ada0
=>       40  156301408  ada0  GPT  (75G)
         40       1024     1  gptboot0  (512K)
       1064        984        - free -  (492K)
       2048    4194304     2  swap0  (2.0G)
    4196352  152104960     3  zfs0  (73G)
  156301312        136        - free -  (68K)

Let’s duplicate that.

[root@r720-01 ~]# gpart modify -i 1 -l gptboot1 ada1
ada1p1 modified
[root@r720-01 ~]# gpart modify -i 2 -l swap1 ada1
ada1p2 modified
[root@r720-01 ~]# gpart modify -i 3 -l zfs1 ada1
ada1p3 modified
[root@r720-01 ~]# gpart show -l ada1
=>       40  156301408  ada1  GPT  (75G)
         40       1024     1  gptboot1  (512K)
       1064        984        - free -  (492K)
       2048    4194304     2  swap1  (2.0G)
    4196352  152104960     3  zfs1  (73G)
  156301312        136        - free -  (68K)

Before

This is zroot before:

[dan@r720-01 ~]$ zpool status zroot
  pool: zroot
 state: ONLINE
  scan: scrub repaired 0 in 0 days 00:00:03 with 0 errors on Thu Oct 10 21:37:16 2019
config:

	NAME        STATE     READ WRITE CKSUM
	zroot       ONLINE       0     0     0
	  ada0p3    ONLINE       0     0     0

errors: No known data errors

Why am I not root? I because root because I had touble with that gpart copy command sequence. I should have gone back to my regular user earlier.

Add the second drive

The following uses an entry in /dev/gpt, which exist only because I added labels, using gpart. See a previous section.

[dan@r720-01 ~]$ sudo zpool attach zroot /dev/ada0p3 /dev/gpt/zfs1 
Make sure to wait until resilver is done before rebooting.

If you boot from pool 'zroot', you may need to update
boot code on newly attached disk '/dev/gpt/zfs1'.

Assuming you use GPT partitioning and 'da0' is your new boot disk
you may use the following command:

	gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0

[dan@r720-01 ~]$ 

Let’s see that status!

[dan@r720-01 ~]$ zpool status zroot
  pool: zroot
 state: ONLINE
  scan: resilvered 818M in 0 days 00:00:09 with 0 errors on Tue Oct 15 21:32:12 2019
config:

	NAME          STATE     READ WRITE CKSUM
	zroot         ONLINE       0     0     0
	  mirror-0    ONLINE       0     0     0
	    ada0p3    ONLINE       0     0     0
	    gpt/zfs1  ONLINE       0     0     0

errors: No known data errors
[dan@r720-01 ~]$ 

That didn’t take long at all!

Add that boot code

Now, remember to add that boot code. If you don’t, and you need to boot from that new drive, it won’t.

[dan@r720-01 ~]$ sudo gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
partcode written to ada1p1
bootcode written to ada1
[dan@r720-01 ~]$ 

Swap is next!

In my original FreeBSD install, I selected mirrored swap. Despite being a single drive, it did the right thing.

By that I mean:

geom_mirror.ko is loaded:

[dan@r720-01 ~]$ kldstat
Id Refs Address                Size Name
 1   24 0xffffffff80200000  243d228 kernel
 2    1 0xffffffff8263e000    27f48 geom_mirror.ko
 3    1 0xffffffff82666000   3a9a10 zfs.ko
 4    2 0xffffffff82a10000     a4f0 opensolaris.ko
 5    1 0xffffffff82c22000     cc40 geom_eli.ko
 6    1 0xffffffff82c2f000     1800 uhid.ko
 7    1 0xffffffff82c31000     23a8 ums.ko
 8    1 0xffffffff82c34000      acf mac_ntpd.ko

via this directive:

[dan@r720-01 ~]$ grep -r mirror /boot/loader.conf
geom_mirror_load="YES"

Swap is active:

[dan@r720-01 ~]$ swapinfo 
Device          1K-blocks     Used    Avail Capacity
/dev/mirror/swap.eli   2097148        0  2097148     0%

Everything looks good in the mirror:

[dan@r720-01 ~]$ gmirror status
       Name    Status  Components
mirror/swap  COMPLETE  ada0p2 (ACTIVE)

Let’s add the new parition to this gmirror.

First, deactivate swap:

[dan@r720-01 ~]$ sudo swapoff /dev/mirror/swap.eli

Remember to turn that back on later.

Looking back to Creating a gmirror swap, I found:

[dan@r720-01 ~]$ sudo gmirror insert swap /dev/gpt/swap1 
[dan@r720-01 ~]$ gmirror status
       Name    Status  Components
mirror/swap  DEGRADED  ada0p2 (ACTIVE)
                       ada1p2 (SYNCHRONIZING, 25%)
[dan@r720-01 ~]$ 

By the time I was finished typing this, it was active:

[dan@r720-01 ~]$ gmirror status
       Name    Status  Components
mirror/swap  COMPLETE  ada0p2 (ACTIVE)
                       ada1p2 (ACTIVE)
[dan@r720-01 ~]$ 

Turn swap back on

Now we turn the swap back on:

[dan@r720-01 ~]$ sudo swapon  -a
swapon: adding /dev/mirror/swap.eli as swap device

[dan@r720-01 ~]$ swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/mirror/swap.eli   2097148        0  2097148     0%
[dan@r720-01 ~]$ 

As is usual, that swap is defined via this entry:

[dan@r720-01 ~]$ cat /etc/fstab 
# Device		Mountpoint	FStype	Options		Dump	Pass#
/dev/mirror/swap.eli		none	swap	sw		0	0
[dan@r720-01 ~]$ 

Hope this helps.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top