# Migrating remote host from slice/label/UFS to GPT/ZFS



## jem (Nov 13, 2009)

I have a dedicated host currently running 7.2-RELEASE with its disks partitioned using the traditional slice+bsdlabel+UFS scheme.  I'd like to non-destructively migrate the system to GPT+ZFS scheme with mirrored disks, doing as much of the work as possible remotely via ssh.

I think I should be able to do all of this without having to call up the hosting company to enable remote console access or have them put a livefs cd in.  I'd like to run my plan past the people here to see if there's anything obvious I've missed or gotten wrong.  I've done manual installs of 8.0-RC2 with GPT and ZFS before so I'm familiar with all the steps in the process.

The machine originally had a single 160GB SATA disk (ad4) and 1GB RAM.  I've just had the hosting company install a second identical disk (ad6) and another gigabyte of RAM.


My plan is:


 Rebuild my world from 7.2-RELEASE to 7.2-STABLE to pull in ZFS v13 and boot support and reboot into the newer version.

 Prepare the new disk (ad6) with GPT and ZFS:
	a) Use gpart to GPT partition the disk similarly to this:

```
=>        34   312499933  ad6  GPT  (149G)
          34         128    1  freebsd-boot  (64K)
         162   312499805    2  freebsd-zfs  (149G)
```
	b) Install pmbr into block 0 and gptzfsboot image into ad6p1
	c) Create zpool from ad6p2
	d) Create seperate ZFS filesystems as needed

 Build a ZFS-aware /boot/loader and install it in the existing UFS root filesystem.

 Copy existing installation from ad4 to ad6.  I'm not sure about the best way to do this.  I've always used dump|restore to move live installations between disks in the past, but that's not an option for UFS->ZFS.  I'm thinking I'll take snapshots of my live UFS filesytems, mount the snapshots, and use tar or rsync to copy their contents to the new ZFS filesystems.

 Configure /boot/loader.conf on ad4 to load the kernel and mount the ZFS filesystems from ad6.

 Cross fingers and reboot.  At this point, hopefully the system will come back up and be fully running from ZFS filesystems on ad6.

 Now I can trash the contents of ad4 and set it up to mirror ad6:
	a) Replicate the GPT partitioning from ad6
	b) Install pmbr into block 0 and gptzfsboot image into ad4p1
	c) zpool attach ad4p2
The zpool mirror is now created and should resilver the data from ad6 to ad4.

Job done.

Can anyone see any glaring flaws in my plan?


----------



## graudeejs (Nov 13, 2009)

Hmmm, I think dump/restore will work.... 
dump is fs specific, I think restore is not, unfortunately I can't test this.


----------



## phoenix (Nov 13, 2009)

jem said:
			
		

> I have a dedicated host currently running 7.2-RELEASE with its disks partitioned using the traditional slice+bsdlabel+UFS scheme.  I'd like to non-destructively migrate the system to GPT+ZFS scheme with mirrored disks, doing as much of the work as possible remotely via ssh.



Make sure you have a full, known-to-work backup before attempting this.  No matter how well you plan, something bad can happen rendering the system unbootable.



> The machine originally had a single 160GB SATA disk (ad4) and 1GB RAM.  I've just had the hosting company install a second identical disk (ad6) and another gigabyte of RAM.
> 
> My plan is:
> 
> ...



Also look into boot.config.  This is a simple text file that can be used to tell the loader which partition to boot from and which partition to use as the root filesystem.



> Copy existing installation from ad4 to ad6.  I'm not sure about the best way to do this.  I've always used dump|restore to move live installations between disks in the past, but that's not an option for UFS->ZFS.  I'm thinking I'll take snapshots of my live UFS filesytems, mount the snapshots, and use tar or rsync to copy their contents to the new ZFS filesystems.



Use rsync, with (at the very least) *--hard-links --archive --numeric-ids* set.  Or look into cpio(8).  Tar might work, as well.

Beyond that, the theory looks good.  Just be sure to have a good backup, just in case.


----------



## jem (Nov 14, 2009)

Seems that killasmurf86 was correct.

Dumping UFS and restoring to ZFS worked fine.


----------



## jem (Nov 17, 2009)

Well I encountered a problem when I tried to carry out my plan.

After I rebuilt /boot/loader to include ZFS support, it didn't work properly.  It's unable to load the kernel and outputs a bunch of "forth not found; definitions not found" errors.  Googling around suggested patching it (something to do with libstand), or using the loader from 8.0.

Also there's also some forced unmounting of ZFS's happening at shutdown.  This all leads me to believe that ZFS isn't quite as smoothly integrated into FreeBSD 7.x as it is in 8.x, so I think I'll just use 8.0 instead.  It's not a mission critical server.


----------

