Cloning OPNsense to Another Disk on a Live System
As part of an ongoing project to consolidate my infrastructure, I am turning my physical OPNsense router into a virtual machine (I may elaborate on the reasons in another blog post). Before proceeding with the virtualization, it’s essential to create a clone of the existing system disk for backup or migration purposes. In this guide, we’ll walk through the steps to clone the running OPNsense system to another disk.
Pre-requisites
- OPNsense system using ZFS
- A second disk with equal or larger size (will be referred to as
ada1) - Basic understanding of FreeBSD disk utilities
Step 1: Identify the Current Disk and Filesystem
First, identify the current disk used by OPNsense. Typically, the root file system (/) is on ZFS.
Run the following command to view mounted filesystems:
As can be seen, there’s no mounted partitions other than the ZFS datasets, which makes it ideal for live migration.
Step 2: Backup Existing Partition Table
Back up the partition table of your existing disk (ada0 in this example) to a file.
Step 3: Prepare the Destination Disk
Before we clone the partition table to the new disk, make sure it’s empty or you’re willing to erase it.
Warning: This step will destroy all data on ada1.
Step 4: Clone the Partition Table
Use the backed-up partition table to set up identical partitions on the new disk (ada1).
Step 5: Optionally Resize Last Partition
If ada1 is larger than ada0, you can resize the last partition to utilize the extra space.
Step 6: Clone ZFS Pool
You can now add the new ZFS partition to your existing ZFS pool in a mirrored setup. This will initiate the resilvering process.
Use zpool status to monitor the resilvering process.
Here’s an example output during resilvering:
Wait for the resilvering to complete before proceeding.
Step 7: Update Boot Code
Finally, you’ll need to install the boot code to the new disk.
Conclusion
In summary, this guide walked you through the process of cloning your OPNsense system disk on a live system. By now, you’ve not only created a mirror of your existing disk but also gained an understanding of the benefits of ZFS. With this new disk, you’re ready to plug it into another server and continue your operations seamlessly. This method provides you with a robust backup strategy, ensuring minimal downtime in your quest to consolidate your infrastructure.
For further questions or issues, feel free to reach out.