ZFS Need help recreating partitions

I had backed up my FreeBSD instance from my laptop's internal disk using a Linux bootable (sadly), but instead of dd'ing the whole disk I dd'd the partitions separately - so as to make the ZFS partition available separately.


I now have the following:
sda1 512Kb (boot maybe) sda2 2GB (perhaps SWAP) sda3 463GB (/ zfs)

I now have a similar sized internal disk on a separate laptop - same brand.
How do I clone this back?
I need to know how can I create similar sized partition so that this all fits back as it was.


I thought of fresh installing FreeBSD with a similar partition structure and then overwriting everything with the original clones but there has to be an easier way.

Any gpart or other commands? Any ideas?
 
I need to know how can I create similar sized partition so that this all fits back as it was.
You dd(1) the individual partitions? I.e. dd if=/dev/sda2 of=backup? Restoring them doesn't need to be the exact same size partition, as long as it's not too small of course. freebsd-boot has be 512K, don't make it any larger (don't have to restore it, use gpart(8) to write a new one). Swap (don't even bother restoring that), just create the space. For ZFS it's not going to matter much, as long as it isn't smaller than the original.
 
For other readers that are interrested in manually create ZFS, I share a couple blogposts I wrote. Not near as concise and precise like 'SirDice' creates post, yet I believe you can learn information from them.
https://ghostbsd-arm64.blogspot.com/2023/07/learning-zfs-on-root-setup-for.html Learning ZFS on root setup for the Raspberry Pi 4B
https://ghostbsd-arm64.blogspot.com/2023/10/honey-i-broke-my-zfs-usb-sata-ssd-1-tb.html Honey I borked my ZFS USB SATA SSD, now what to do?

Example of creating partitions using a shell script file. ESP EFI FAT32 partition #1 for boot files 0xA501, partition #2 for swap files 0xA502, partition #3 for UFS files
cat freebsd-partition.sh
#!/bin/sh

# Prompt user for disk selection
echo "Enter the disk to use (e.g., da0, ada0):"
read disk

# Destroy existing partitions on the selected disk
gpart destroy -F $disk

# Create GPT partition table on the selected disk
gpart create -s GPT $disk

# Add partitions as specified
gpart add -i 1 -a 1M -s 260M -t fat32 $disk
gpart add -i 2 -a 1M -s 1024M -t freebsd-swap $disk
gpart add -i 3 -a 1M -s 12G -t freebsd-ufs $disk

# Set the size for the last partition (you can customize this range)
gpart modify -s 10G -i 3 $disk

# Create file systems on the specified partitions
newfs -t msdos /dev/${disk}p1
newfs /dev/${disk}p3


To use ZFS , create a blank partition with type freebsd-zfs A503
gpart add -i 3 -a 1M -s 12G -t freebsd-zfs $disk

rcsys enable_ZFS="YES" # edit in this one line into file, /etc/rc.conf file for selecting ZFS partition
# zfs_enable="YES" # for ZFS Zetabyte File System formatted boot parition, use this line
zfs_enable="NO" # for UFS Unix File System formatted boot partition, use this line

# edit the following 5 lines into file, /boot/loader.conf
kern.geom.label.disk_ident.enable=0
kern.geom.label.gptid.enable=0

zfs_load="YES"
vfs.zfs.debug=0
# vfs.root.mountfrom="zfs:zroot/ROOT/default"
# vfs.root.mountfrom="zfs:arm64pool/ROOT/default"
vfs.root.mountfrom="zfs:arm64pool/ROOT/default" #tell which filesystem to mount
# vfs.root.mountfrom="ufs:/dev/da0p3" or "ufs:/dev/gpt/rootfs" # Whatever label you gave the Root File System (ie rootfs )

https://ghostbsd-arm64.blogspot.com/2023/12/zfs-boot-on-root-setup-for-usb-ssd.html#more

You used 'dd' command to copy the partitions. Seems like a good idea.
I used tar cvzf my_tar_zroot.tar.gz /
mount /dev/gpt/esp /mnt/esp
cd /mnt/esp ; tar cvzf my_esp_boot.tar.gz .

SirDice does this work when copying files into a new clean partition? This method has worked for me. Is there some catch that I missed?
Should work fine with msdos partition. The ZFS partition tar should create a fine tar.gz file. Then the extraction of that same tar.gz file into a mounted ZFS partiton, that is blank should recreate all the hidden information in behind the scenes that ZFS uses internally for the zettabyte file system, yet the files themselves should have the same byte for byte contents. Correct? I probably missed some item. Use at your own risk. Fred
ps. Now that I know a little more than I did a few months ago. I should edit, clean up, and add to these blogposts I listed above..
 
Back
Top