ZFS FreeBSD, ZFS on root, change disk. How to reformat drive?

Hi.
Have:
Code:
root@backup:~ # gpart show
=>        40  3907029088  ada0  GPT  (1.8T)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048     4194304     2  freebsd-swap  (2.0G)
     4196352  3902832640     3  freebsd-zfs  (1.8T)
  3907028992         136        - free -  (68K)

=>        40  3907029088  ada1  GPT  (1.8T)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048     4194304     2  freebsd-swap  (2.0G)
     4196352  3902832640     3  freebsd-zfs  (1.8T)
  3907028992         136        - free -  (68K)

=>        40  3907029088  ada2  GPT  (1.8T)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048     4194304     2  freebsd-swap  (2.0G)
     4196352  3902832640     3  freebsd-zfs  (1.8T)
  3907028992         136        - free -  (68K)

=>        34  7814037101  ada3  GPT  (3.6T)
          34          30        - free -  (15K)
          64     8388608     1  linux-raid  (4.0G)
     8388672     1048576     2  linux-raid  (512M)
     9437248  7804595825     3  linux-raid  (3.6T)
  7814033073        4062        - free -  (2.0M)

I have changed HDD ada3 with new disk from NAS (so we can see Linux partitions).
I used zpool replace procedure. Bге I didn't format new drive before.
How to reformat drive now and make it similar with others?
I want to change ada2 drive too.
 
This is my procedure. Make sure you get your device names AND partition numbers right, or you could wreck your working system!
This is for a mirror. If you have RAIDZ or a stripe, attach it as you please.
Code:
############################################
# Replacing failed encrypted root disk:
############################################
- put new disk
- use gpart to create the same partition layout. Use same offsets and sizes!
- add boot partition to bootpool
- geli init with /boot/encryption.key and same password.
- geli attach encrypted partition
- add encrypted partition to zroot
- binary copy with dd of freebsd-boot partition (512k)
- copy UEFI partition contents
- wait for resilver before rebooting


# plug disk in
dmesg | tail
# get device name

gpart show -l ada3
gpart show ada3

# !!! WARNING: DRAGONS BE HERE !!!
# ada3 is the new disk! ADAPT this to your case!!!
#gpart destroy -F ada3

# Add the partitions with the SAME offsets and sizes like the other mirror members.
gpart add -t freebsd-boot -l gptboot3 -b 40 -s 1024 ada3
gpart add -t freebsd-swap -l swap3 -b 2048 -s 4194304 ada3
gpart add -t freebsd-zfs -l zfs3 -b 4196352 -s 3902832640 ada3

# write the boot code to the right partition!
# MAKE SURE THE INDEX IS CORRECT! It points to the freebsd-boot partition!
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada3

# Format swap, add to fstab etc. This is how I do mirrored encrypted swap in fstab:
# 1. Add the new partition to a mirror named hddswap.
nano /etc/fstab:
#------------------
/dev/mirror/hddswap.eli none swap sw,ealgo=AES-XTS,keylen=128,sectorsize=4096 0 0
#------------------

# OPTIONAL: I use encryption, so I format the ZFS partition with GELI.
geli dump ada0p3
# I use the same GELI parameters asa ada0. -b and -g is a MUST if you want to boot from this encrypted partition.
geli init -g -b -e AES-XTS -l 256 -s 4096 ada3p3
# make sure to backup the key files if applicable.
geli attach ada3p3

# Attach to zpool's mirror
zpool attach zroot ada0p3.eli ada3p3.eli
 
Great thanks!
I corrected procedure for me...
#zpool offline zroot ada3p3
#vi /etc/fstab

# Device Mountpoint FStype Options Dump Pass#
/dev/ada0p2 none swap sw 0 0
/dev/ada1p2 none swap sw 0 0
/dev/ada2p2 none swap sw 0 0
# /dev/ada3p2 none swap sw 0 0

#gpart delete -i 1 ada3
#gpart delete -i 2 ada3
#gpart delete -i 3 ada3

#gpart create -s GPT ada3

ada3 created
#gpart add -t freebsd-boot -l gptboot3 -b 40 -s 1024 ada3
ada3p1 added
#gpart add -t freebsd-swap -l swap3 -b 2048 -s 4194304 ada3
ada3p2 added
#gpart add -t freebsd-zfs -l zfs3 -b 4196352 -s 3902832640 ada3
ada3p3 added
#gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada3
partcode written to ada3p1
bootcode written to ada3

#swapon /dev/ada3p2

#vi /etc/fstab

# Device Mountpoint FStype Options Dump Pass#
/dev/ada0p2 none swap sw 0 0
/dev/ada1p2 none swap sw 0 0
/dev/ada2p2 none swap sw 0 0
/dev/ada3p2 none swap sw 0 0

#zpool replace zroot ada3p3
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 'ada3p3'.
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

# zpool status
pool: zroot
state: DEGRADED
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Mon Apr 8 13:12:29 2019
44.6G scanned out of 5.33T at 289M/s, 5h19m to go
10.7G resilvered, 0.82% done
config:

NAME STATE READ WRITE CKSUM
zroot DEGRADED 0 0 0
raidz1-0 DEGRADED 0 0 0
ada0p3 ONLINE 0 0 0
ada1p3 ONLINE 0 0 0
ada2p3 ONLINE 0 0 0
replacing-3 OFFLINE 0 0 0
9335136065648740732 OFFLINE 0 0 0 was /dev/ada3p3/old
ada3p3 ONLINE 0 0 0

errors: No known data errors

Now I wait... :)
 
That's great. It's advisable to put the code in CODE tags (use the icons on the toolbar above the message field), which will format it properly for others to read easier. You could edit your message and put the code in a CODE tag.
 
Back
Top