Re: Howto migrate a FreeBSD cloud instance to another one without native FreeBSD support?

From: Michael Grimm <trashcan_at_ellael.org>
Date: Thu, 28 Dec 2023 09:28:22 UTC
Alexander Leidinger <Alexander@leidinger.net> wrote
> Am 2023-12-26 19:41, schrieb Michael Grimm:
>> Miroslav Lachman <000.fbsd@quip.cz> wrote;
>>> On 26/12/2023 15:22, Michael Grimm wrote:

>> Sorry, if I haven't been clear enough:
>> #) I do want to migrate an existing ZFS pool (from one instance to another (zfs send | zfs receive).
>>   This I have done numerous times before.
>> #) New to me is the preparation of the target disk out of an Ubuntu/Linux rescue system.
>>   Namely, how to partition with Linux functionality (gdisk, cfdisk, …) lacking gpart?
>>   Namely, which kind of booting to use (legacy versus EFI)?

>>> And the second is: you can prepare small minimalistic FreeBSD image in Bhyve / VirtualBox etc. make a copy of it with dd and then write it by dd to your new instance's disk with the help of Linux rescue system. Then you can reboot to a minimalistic FreeBSD system, enlarge partition(s), use growfs or zpool / zfs enlargement and then finally move data from the old instance to this new instance by rsync, or zfs send, or whatever tool you prefer.

>> Thanks for this info, very much appreciated.
> 
> This is more or less what I did for such a case (local provider, not OVH): I used an existing FreeBSD system, created a file of a few GB, dd-ed /dev/zero to it completeley (for a compressed transfer), created a md(4) out of the file, partitioned it, created a root pool, installed FreeBSD into it, created a suitable rc.conf and such to boot from it, and wrote it to the linux rescue system on the target host "ssh -C me@target dd of=/dev/sda <imagefile" or "zstd <imagefile | ssh me@target unzstd \| dd of=/dev/sda" (it helps to create a authorized_keys entry on the target system). After rebooting into the system, a gpart recover and a gpart resize, followed by setting autoexpand=on on the pool.

I finally succeeded in migrating to a new cloud instance by following my initial plan:

1) Using Linux functionality in rescue 

	a) Repartition the target disk using gdisk:
		Partition 1: EF00  EFI system partition
		Partition 2: A504 FreeBSD ZFS

	b) mkds.fat Partition 2

	c) copy loader.efi from old server to /EFI/BOOT/BOOTX64.efi in Partition 2

	d) Creation of target zpool

2) Migration of old zfs filesystem to target ZFS filesystems (in rescue)

	zfs send from target | zfs receive

3) Modification of rc.conf et al.

As proof on concept I did follow https://community.hetzner.com/tutorials/freebsd-openzfs-via-linux-rescue first

Thanks and regards,
Michael