Transfer OpenBSD from one disk to another

For some reason, I need to switch my main (and only) disk running OpenBSD. As it is a production machine, I want to do it fast and painless.

The system will go from the internal SSD disk to an external USB FlashVoyagerGT stick. Yeah, quite weird, but this is temporary :) Anyway, here are the directions.

Connect the second disk to the machine, check its name, initialize the MBR, create the partition and the filesystem(s):

# fdisk -i sd1 Do you wish to write new MBR and partition table? [n] y Writing MBR at offset 0. # disklabel -E sd1 Label editor (enter '?' for help at any prompt) > a c (...) > a b (...) > w > q # newfs sd1a /dev/rsd1a: 15287.9MB in 31309568 sectors of 512 bytes (...) # shutdown -h now Shutdown NOW!

Now boot your system in single-user mode and clone the data from the initial disk to the second one:

boot> boot -s (...) Enter pathname of shell or RETURN for sh: /bin/ksh # mount /dev/sd1a /mnt # mount_mfs -s 4096m swap /tmp # cd /mnt # dump -0f - /dev/sd0a | restore -rf -

Another option is to use the `tar` command:

# mount /dev/sd1a /mnt # tar cpzXf - / | tar xpzf - -C /mnt

Note that, in some case, you may get an error such as “tar: Link name too long for ustar usr/local/lib/GNUstep/SOGo/(…)“. AFAIK, this is a limitation of the OpenBSD tar implementation which limits a filename at 100 characters.

We can now check that both disk have the same content and reboot (to install the MBR) properly:

# df -h # shutdown -h now

Reboot the system and, in the OpenBSD loader, force to boot on the secondary disk:

boot> boot hd1a:/bsd -s (...) Enter pathname of shell or RETURN for sh: /bin/ksh # /usr/mdec/installboot -n -v /boot /usr/mdec/biosboot sd0 # shutdown -h now

The primary disk can now be removed and the system will boot on the previously “secondary disk” ; as soon as the bios is configured to ;-)

If everything went well, you now run the system from the new system.

Source: Adding extra disks in OpenBSD

Author: Joel Carnat

@work Technical Architect and SysAdmin ; @home OpenBSD and FOSS, Karate, Kobudō, Jōdō, Bodyweight workout, Photography & Music

3 thoughts on “Transfer OpenBSD from one disk to another”

  1. Hi Joel, I’m having trouble with this procedure. I’m running OpenBSD 5.7 in a VirtualBox VM. The default disks are on the IDE bus, so I’m substituting wd0a for sd0a, wd1a for sd1a, etc. I did the disklabel and newfs stuff on a newly added disk wd1a, and booted up into single user mode; when I try to run the dump | restore command pair I get this error:

    # dump -0f - /dev/wd0a | restore -rf -
    DUMP: Cannot open /dev/wd0a
    Checksum error 0, inode 0 file
    restore: Tape is not a dump tape

    I think that the last two lines are from restore.

    Here is the output of mount(8):

    # mount
    /dev/wd0a on / type ffs (local)
    /dev/wd1a on /mnt type ffs (local)
    mfs:15097 on /tmp type mfs (asynchronous, local, size=8388608 512-blocks)

    I verified that the securelevel is still 0. Any ideas about why this isn’t working? Thank you in advance for your time.


    1. Hi,

      I’ll try the following things:
      – use dump with “/dev/rwd0a” as a source device ;
      – boot on a OpenBSD CD, only mount /dev/wd1a and use the “dump/restore” method ;
      – use the “tar method”.

      Hope it helps.

  2. Hi

    anyone could detail on how to adapt the above process for an encrypted install of OpenBSD ?
    except from dd’ing from disk to disk, and thus retaining slice geometry and disk size, i cant imagine any other option…

    Probably creating an encrypted raid in the target disk, but then the mbr creation and partition geometries wont work im afraid…

    am i wrong here ?

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.