# ZFS: rebuild zroot in the mirror



## ogogon (Dec 25, 2018)

Colleagues, tell me, pls, answer my question!

*If I installed FreeBSD on a server with zroot on one disk, can I later rebuild it in the mirror?*

Speaking of rebuild, I mean to add a physical volume and give the command, rather than doing backup and reinstallation.
Of course, all mirror disks must be bootable.
(Perhaps this is in the documentation, but I could not find such an option.)

Thank you in advance for the answer on the essence of my question.

Ogogon.


----------



## Emrion (Dec 25, 2018)

Of course, you can and it's very simple. Your first disk has a GPT scheme?
If it is, you should post the result of `gpart show`


----------



## ogogon (Dec 25, 2018)

Emrion said:


> Of course, you can and it's very simple. Your first disk has a GPT scheme?


I do not discuss the specific case, but the possibility.


----------



## ogogon (Dec 25, 2018)

Here is my nearest server:
`root# gpart show
=>        34  1953525101  ada0  GPT  (932G)
          34           6        - free -  (3.0K)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048   134217728     2  freebsd-swap  (64G)
   134219776  1819303936     3  freebsd-zfs  (868G)
  1953523712        1423        - free -  (712K)
root#`

Suppose I added a disk ada1.


----------



## Emrion (Dec 25, 2018)

Ok.. The possibility... You have to:

Add a physical disk.
Duplicate the scheme of the first disk to the new one.
Install the bootcodes on the second disk.
Use `zpool attach` to mirror the partition of interest.
Then, just wait the resilvering has finished up.

Is it clear?


----------



## ogogon (Dec 25, 2018)

In theory. At the time of mbr and ufs, I did this, but not for gpt and zfs. It will be necessary to understand.


----------



## ogogon (Dec 25, 2018)

Anyway - thank you.

P.S. And I can copy the disc to the same type, using the utility dd?

`dd if=/dev/ada0 of=/dev/ada1 bs=1M`

This should include steps 2 and 3.

Ogogon.


----------



## Emrion (Dec 25, 2018)

It's why I asked you... Details make difference between something that works and disaster. And please do not use `dd` at all.

First, do not suppose, just see the facts. You added a disk but is it ada1?
You have to run `ls /dev`. And if it is like you think, you will see: ada0, ada0p1, ada0p2 and ada0p3 but just ada1.

Then, you'll know what you're doing. The new disk is ada1.

As you have a GPT scheme on your first disk, it's easy to duplicate the thing on you second disk (I assume it's ada1): `gpart backup ada0 | gpart restore -F ada1` (the -F option is only needed if the added disk had a partition scheme before).

I saw that you boot under legacy BIOS. So, to make the new disk bootable, you just have to issue this command:
`gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i1 ada1`

After that, it's time to mirror ada0p3. You have to run: `zpool attach zroot ada0p3 ada1p3`
zroot being the name of your zfs pool.


----------

