OpenBSD : p2v

Here is a small hack to transfer an OpenBSD physical server to a virtual machine (VMware in my case, but it should work with all).

Unless a bad command, there is no risk for the server because it does not modify anything on it.
Step 1: install the VM

Here, nothing special. Retrieve an OpenBSD ISO and install in a virtual machine. Configure the network to have SSH access.
Step 2: list the bulk on the physical server

If I list that contains my server, this is what I get:

$ ls /.
altroot boot dev home obsd sbin usr sys
bin bsd bsd.rd etc mnt root tmp var stand

My server runs OpenSMTPD with the config located in/etc and messages in/home. Next comes dovecot installed from ports, its files are located in/usr (and the config in/etc). And finally, prosody coming also ports and operates a database in/var. The list of directories to be transferred is therefore:

/ etc
/ Home
/ usr
/ var

Step 3: backup directories

Using a good old tar (you can use compression by adding the argument z):

# tar – pcvf etc.tar/etc /
# tar – pcvf home.tar/home
# tar – pcvf usr.tar usr
# tar – pcvf var.tar /var/

Attention do not work in the/home directory when you do the second order! Otherwise this will never end (it will check in the file to archive newly created, etc).
Step 4: transfer of archives on the VM

The easiest way is to use the sftp Protocol (active from the moment that sshd is active on your system). This can be done from Filezilla on a third machine (with the root accounts).
Step 5: Restoration of users

For security reasons, the file containing the system users and their passwords is read-only, even for root (see this page). You must use the vipw(8) tool to import them.

Open vipw on the host computer, copy all lines after the line “nobody”, and paste it to the suite in the VM vipw (you can do this from a third computer and SSH connections).
Step 6: installation on the VM

The procedure is classic, except that we must think to save the fstab file because the partitioning may differ:

# tar – pxvf var.tar c.
# tar – pxvf usr.tar UI.
# tar – pxvf home.tar UI.
# cp/etc/fstab /root/
# tar – pxvf etc.tar c.
# cp/root / / etc / fstab
# reboot

Be sure to review the rc.conf configuration, including the host name and the network which may differ.