Solved zfsroot without mirror - how to replace disk (migrate to bigger)

Hello!

I've just bought new hard disk and I want to replace zfsroot in my FreeBSD router. There's no mirror on zfsroot. What I want to do is:

1. attach new drive
2. mirror zfsroot to new, bigger disk
3. unmirror from old smaller disk
4. remove old drive

I am completely uncertain as how this should be done. Will:

Code:
zpool attach zroot <old drive> <new drive>
<wait>
zpool detach zroot <old drive>
do?

Or do I need to create gpt partitions, install bootcode etc?
 
If you want to boot off it then you will need to partition it and add bootcode.
Make sure you use the correct partition when adding it to the pool. (I've been known to partition a disk, then mess up and add the whole disk to the pool rather than the partition in the past...)

Edit: But yes, you should be able to use attach to create a mirror, then detach the old disk.
 
Thanks usdmatt, so the procedure should look like (given disk is ada1):

Current configuration:

Code:
# zpool status zroot
  pool: zroot
 state: ONLINE
status: Some supported features are not enabled on the pool. The pool can
   still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
   the pool may no longer be accessible by software that does not support
   the features. See zpool-features(7) for details.
  scan: none requested
config:

   NAME                                          STATE     READ WRITE CKSUM
   zroot                                         ONLINE       0     0     0
     gptid/1fca3b2d-df99-11e3-9f92-00270e0db2f7  ONLINE       0     0     0

errors: No known data errors

Now I need to identify partition:
Code:
# glabel status|grep 1fca3b2d-df99-11e3-9f92-00270e0db2f7
gptid/1fca3b2d-df99-11e3-9f92-00270e0db2f7     N/A  ada0p3

Then create partitions:
Code:
gpart create -s gpt ada1
gpart add -b 34 -s 94 -t freebsd-boot ada1
gpart add -t freebsd-zfs -l disk0 ada1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1

And add it to zroot:
Code:
zpool attach zroot ada0p3 ada1p3

Once attached - I need to wait for resilver to complete (can be checked issuing zpool status zroot) and then detach old drive:

Code:
zpool detach zroot ada0p3

Am I missing something?
 
You don't really need to identify the original partition, although that output is showing that the pool is using the 3rd partition on the disk.
It may be worth having a look at gpart show ada0 to see what partitions are on the original disk. There may be a swap partition as well. You don't technically need that but may as well add it if the original disk had one.

In your example above you only add two partitions to the new disk (freebsd-boot and freebsd-zfs), so the ZFS partition would be adaXp2. (Where adaX is the new disk; It will probably be ada1 but may be ada0 if you plug the new drive into a lower port number than the original disk)

Also you add a label to the ZFS partition, calling it disk0. There's not much point to that unless you intend to use it -
Code:
zpool attach zroot ada0p3 gpt/disk0
 
Oh, that's clear with the label now. Thank you again.

Regarding current gpart config - here's the gpart show output:

Code:
# gpart show ada0
=>       34  234441581  ada0  GPT  (112G)
         34       1024     1  freebsd-boot  (512K)
       1058    8388608     2  freebsd-swap  (4.0G)
    8389666  226051949     3  freebsd-zfs  (108G)

Regarding swap itself - I do have two options:
1. Do it as it is done on ada0 - separate partition for swap (although I've extended ram to 8GB and I'd like to use bigger swap as well)
2. Create swap on zfs level.

Now - I'm not sure which way is better - partition or filesystem swap. I do believe keeping it on zfs level gives me possibility to adjust it in the future. Any benefits of keeping it on separate partition on same physical disk?

What you mean by:
You don't really need to identify the original partition, although that output is showing that the pool is using the 3rd partition on the disk.
?

Is it regarding zpool attach? Meaning - I can do it like this:
Code:
zpool attach <new_disk>
?
 
I didn't realise till after you were getting the partition so you could use it in the replace command. Usually you just use whatever's in the zpool output, so in your case -
Code:
zpool replace zroot gptid/1fca3b2d-df99-11e3-9f92-00270e0db2f7 newdisk
 
Here's how I did it:

0. I've added new disk

1. Then I booted up the machine and checked current configuration:
Code:
# zpool status zroot
  pool: zroot
state: ONLINE
status: Some supported features are not enabled on the pool. The pool can
   still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
   the pool may no longer be accessible by software that does not support
   the features. See zpool-features(7) for details.
  scan: none requested
config:

   NAME                                          STATE     READ WRITE CKSUM
   zroot                                         ONLINE       0     0     0
     gptid/1fca3b2d-df99-11e3-9f92-00270e0db2f7  ONLINE       0     0     0

errors: No known data errors

Code:
# gpart show ada0
=>       34  234441581  ada0  GPT  (112G)
        34       1024     1  freebsd-boot  (512K)
       1058    8388608     2  freebsd-swap  (4.0G)
    8389666  226051949     3  freebsd-zfs  (108G)

2. I've initialized disk and created partitions - very important thing is to create freebsd-boot partition with enough space for the bootcode:

Code:
gpart create -s gpt ada1
gpart add -b 34 -s 512K -t freebsd-boot ada1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
gpart add -t freebsd-swap -s 16G ada1
gpart add -t freebsd-zfs -l disk0 ada1

Comments for the code above:
- the -b 34 determines where partition should start, 512K determines size (same as on source drive).
- I've written bootcode directly after I've created the freebsd-boot partition.
- Since I've extended my RAM I've created swap accordingly.

3. Then I just replaced old partition with new:
Code:
zpool replace zroot ada0p3 ada1p3
and I had to wait for resilvering to finish.

4. Once finished I powered off the system, detached old drive.

That's it.
 
Aaaand here's another, much simpler - I do believe - procedure. Basically what needs to be done is (after physical drive is attached):

Code:
gpart create -s gpt ada1
gpart add -b 34 -s 512K -t freebsd-boot ada1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
gpart add -t freebsd-swap -s 16G ada1
gpart add -t freebsd-zfs -l disk0 ada1
Then once disk is initialized, create mirror on it:
Code:
zpool attach zroot ada0p3 ada1p3
Wait for resilver to finish.

Then shut down, detach old drive, boot it up and you'll have missing disk in mirror - then you just need to remove it and it will work without any problem.

Advantage of this procedure is that in case of problems you can still boot from your old drive.
 
Back
Top