Latest News:
2019-02-05: XigmaNAS 12.0.0.4.6412 - BETA released!
2019-01-22: XigmaNAS 11.2.0.4.6400 - released!

We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS cost money, please consider a donation to our project so we can continue to offer you the best.
We need your support! eg: PAYPAL

How do I change root on ZFS to a mirror?

Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
texneus
Starter
Starter
Posts: 23
Joined: 12 Oct 2017 05:02
Status: Offline

How do I change root on ZFS to a mirror?

#1

Post by texneus » 14 Feb 2019 07:03

Currently have a full ZigmaNAS install with root on ZFS using a single SDD. Realizing loosing the boot drive would be somewhat painful, I would like to convert this to a mirrored set. Do I just "attach" a second drive as you normally would to convert a single vdev to a mirror? From a BIOS perspective, do I choose either drive as the boot device and FreeBSD re-pairs the drives into a mirror when it boots? Or does BIOS recognize the drives as mirrored from the get go and I need to boot the mirror somehow?

User avatar
JoseMR
Hardware & Software Guru
Hardware & Software Guru
Posts: 950
Joined: 16 Apr 2014 04:15
Location: PR
Contact:
Status: Offline

Re: How do I change root on ZFS to a mirror?

#2

Post by JoseMR » 14 Feb 2019 10:54

Hi, it is not as simple as that, as RootOnZFS like any other install platform requires for disk preparation, hence it is strongly advised to let the installer take care of the zroot and the swap mirror(optional) partitioning scheme.

***Please provide the output for "df -h" command before continue with below suggestions.***


However, there are currently two methods for doing this task as follow:

Easy Method (Uses the bemanager TUI utility for backup/restore Boot Environments, requires for downtime)
1: Download and setup the bemanager TUI utility.
2: Backup the current Boot Environment to a desired permanent data location, i.e your ZFS pool/dataset.
3: Perform a new RootOnZFS Mirror install, download and setup again the bemanager utility, then restore/activate the saved Boot environment and reboot.


Advanced Method (For advanced users only, example taken from a standard/default RootOnZFS install)
Warning: In this example my second drive is "ada1", please edit the commands accordingly.
1: Determine the boot disk device id, then analyze the partition scheme as follow:

Code: Select all

xigmanas: ~# gpart show ada0
=>      40  33554352  ada0  GPT  (16G)
        40      1024     1  freebsd-boot  (512K)
      1064      7128        - free -  (3.5M)
      8192   4194304     2  freebsd-swap  (2.0G)
   4202496  29343744     3  freebsd-zfs  (14G)
  33546240      8152        - free -  (4.0M)

xigmanas: ~#
2: Proceed to create the same partitioning scheme in the new disk as follow:

Code: Select all

xigmanas: ~# gpart create -s gpt ada1
ada1 created
xigmanas: ~# gpart add -a 4k -s 512K -t freebsd-boot -l sysboot1 ada1
ada1p1 added
xigmanas: ~# gpart add -a 4m -s 2g -t freebsd-swap -l swap1 ada1
ada1p2 added
xigmanas: ~# gpart add -a 4m -t freebsd-zfs -l sysdisk1 ada1
ada1p3 added
xigmanas: ~# 
3: Proceed to write the boot code in the new disk as follow:

Code: Select all

xigmanas: ~# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
partcode written to ada1p1
bootcode written to ada1
xigmanas: ~#
4: Visualize and confirm the newly created partitioning scheme that match with the existing OS disk as follow:

Code: Select all

xigmanas: ~# gpart show ada1
=>      40  33554352  ada1  GPT  (16G)
        40      1024     1  freebsd-boot  (512K)
      1064      7128        - free -  (3.5M)
      8192   4194304     2  freebsd-swap  (2.0G)
   4202496  29343744     3  freebsd-zfs  (14G)
  33546240      8152        - free -  (4.0M)

xigmanas: ~#
5: Proceed to attach the newly prepared disk to the existing zroot pool as follow(ignore updating bootcode as already done in steep #3):

Code: Select all

xigmanas: ~# zpool attach zroot /dev/gpt/sysdisk0 /dev/gpt/sysdisk1
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/sysdisk1'.

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

xigmanas: ~#
6: Verify/confirm for the newly attached drive belongs to the zroot pool mirror as follow:

Code: Select all

xigmanas: ~# zpool status
  pool: zroot
 state: ONLINE
  scan: resilvered 568M in 0h0m with 0 errors on Thu Feb 14 09:00:30 2019
config:

	NAME              STATE     READ WRITE CKSUM
	zroot             ONLINE       0     0     0
	  mirror-0        ONLINE       0     0     0
	    gpt/sysdisk0  ONLINE       0     0     0
	    gpt/sysdisk1  ONLINE       0     0     0

errors: No known data errors
xigmanas: ~#
7: Optional, you can add the second swap device to be appended to the system in the fstab as follow(swap mirror conversion also possible):

Code: Select all

xigmanas: ~# echo "/dev/gpt/swap1 none swap sw 0 0" >> /etc/fstab
8: Optional, shutdown the server and disconnect the previous drive, and test if you can boot of the newly added one in degraded mode.

9: Go to "Disks > Management > HDD Management" check "Clear configuration information before importing disks." and re-import drives.

Notes: This does not account for EFI and/or BIOS+UEFI, custom root partition size etc., in such case follow the exact scheme provided by the "gpart show diskid" command.

Hope this may help.
Regards

Disclaimer: I'm not responsible for the data lost or damage provided in this example, proceed at your own risk.
System: FreeBSD 12.0, MB: Supermicro X8SI6-F, Xeon X3450, 16GB DDR3 ECC RDIMMs.
Devel: XigmaNAS Embedded and Full Latest, VirtualBox, 2 x CPU Cores, 4GB vRAM.
Addons Devel GitHub
JoseMRPubServ Resources

texneus
Starter
Starter
Posts: 23
Joined: 12 Oct 2017 05:02
Status: Offline

Re: How do I change root on ZFS to a mirror?

#3

Post by texneus » 17 Feb 2019 00:25

So lesson learned...do it right the first time! Could you also backup up the server settings, re-install XigmaNAS onto a mirror, and restore settings? Presumably you loose any customization that isn't part of XigmaNAS, but that might be easier...

User avatar
JoseMR
Hardware & Software Guru
Hardware & Software Guru
Posts: 950
Joined: 16 Apr 2014 04:15
Location: PR
Contact:
Status: Offline

Re: How do I change root on ZFS to a mirror?

#4

Post by JoseMR » 17 Feb 2019 00:40

texneus wrote:
17 Feb 2019 00:25
So lesson learned...do it right the first time! Could you also backup up the server settings, re-install XigmaNAS onto a mirror, and restore settings? Presumably you loose any customization that isn't part of XigmaNAS, but that might be easier...
Yes, you can save config, install and restore as mirror then re-import/synchronize the drives and done, however any optional packages and manual configurations/customization will be lost if by default.


you can backup whole running Boot Environment to a compressed file to any permanent data location inside the server or even remotely, so after re-install with mirror setup and importing and activating back the saved BE, your system will start right like the last state, i.e up and running with all packages and customization untouched.

Thats why I asked if you can provide output for "df -h" to see if you are running of later RootOnZFS with /var inside the BE's, as it was shared before to save space but later just follow bsdinstall.

Please post here output for the below command and I give you all you need to reinstall as a mirror and import back your last state Boot Environment.

Code: Select all

df -h
Regards
System: FreeBSD 12.0, MB: Supermicro X8SI6-F, Xeon X3450, 16GB DDR3 ECC RDIMMs.
Devel: XigmaNAS Embedded and Full Latest, VirtualBox, 2 x CPU Cores, 4GB vRAM.
Addons Devel GitHub
JoseMRPubServ Resources

texneus
Starter
Starter
Posts: 23
Joined: 12 Oct 2017 05:02
Status: Offline

Re: How do I change root on ZFS to a mirror?

#5

Post by texneus » 17 Feb 2019 01:32

JoseMR wrote:
17 Feb 2019 00:40
Thats why I asked if you can provide output for "df -h" to see if you are running of later RootOnZFS with /var inside the BE's, as it was shared before to save space but later just follow bsdinstall.

Please post here output for the below command and I give you all you need to reinstall as a mirror and import back your last state Boot Environment.
Sorry, I meant to answer this. I appreciate the offer but this is more complicated than I feel like dealing with at this time, so I'm going to leave it alone. After a very long period of trial and error to get everything working reliably, I'm just going to sit back, relax, and enjoy NASing for a while :-).

Post Reply

Return to “ZFS (only!)”