This is a really terrible way of cloning one box to another.
I don’t recommend it. Its very gross. There is manual work needed and no guarantee that it won’t really mess up parts of a system.
Don’t do this
If you need to clone something, a much better option would be to use ZFS
snapshots, send the snapshot to the remote host, and then boot from something
like mfsbsd, clone the snapshot (need it writable), and then set the mountpoint
of the clone to /
.
Clone a box with Rsync
On the target host:
- enable root ssh in sshd_config
- set a root password
- stop services / remove from pools
- sudo umount -t nfs -a
- Remove schange flag from files that need it
- start by finding all the ones that have it set on target system:
- sudo find / -flags +schange
- sudo chflags -R noschg /usr/bin /usr/lib /usr/lib32 /bin /lib /sbin /libexec
- Make sure to undo this after the copy – restore the ones from your find.
1cd /
2rsync -av --exclude /boot/loader.conf --exclude /etc/fstab --exclude /etc/rc.conf --exclude /etc/ssh --exclude /tmp/ --exclude /var/tmp/ --exclude /var/log/ --exclude /etc/pf.conf --exclude /etc/hosts --exclude \*.core --exclude /boot/zfs --delete / $HOSTNAME:/
better yet boot the target machine into mfsbsd
1zpool import -o altroot=/tank tank
2chflags -R noschg /tank
3cd /
4rsync -avHX --exclude /etc/rc.conf --exclude /tmp --exclude /var/tmp/ --exclude /var/log/ --exclude *.core --exclude /boot/zfs --exclude /usr/src --exclude /usr/obj --exclude /usr/ports --exclude /dev/ --exclude /mnt/ --delete . $machine_running_mfsbsd:/tank
Then fixup stuff and reboot…
- -H or –hard-links - preserve hard links, keeps rsyncing the rescue busybox-type thing from blowing out the root filesystem
- -X or –xattrs - preserve extended attributes
Things that may need attention afterwards
- /etc/rc.conf
- /etc/fstab - nfs mounts, maybe other stuff
If doing nfs, put your nfs stuff in /etc/fstab and rc.conf AND pf.conf,
1sysrc touch /etc/exports
- Create your mount directories
1sysrc nfs_client_enable="YES"
2sysrc nfs_client_flags="-n 16"
3sysrc rpcbind_enable="YES"
And don’t forget
1sysrc dumpdev="AUTO"
Comments