Friday, August 03, 2007

Cloning a disk in OpenBSD

If you want to upgrade your disk or clone it for whatever reason (move to another machine, etc), you can do this easily with dump(8). Let's assume the old disk is wd0 and the new disk is wd1.

Cloning a disks is little more then doing a full system backup and restoring it to another disk.

Remember, you need to boot single user mode with "boot -s", fsck -p / && mount -uw / (repeat for /usr, etc) to make sure there are no problems with the level 0 dump (as OpenBSD dump does NOT support snapshots). If you have issues, just make sure everything is mounted properly (check with the "mount" command).

  1. Add the new disk, and check "dmesg".
  2. Initialize the MBR for the new disk:
    # fdisk -i wd1
  3. Create a disklabel for the new disk:
    # disklabel -e wd1
  4. Format the new disk:
    # newfs /dev/wd1a
  5. Mount the disk:
    # mount /dev/wda1 /mnt
  6. Change to the /mnt directory:
    # cd /mnt
  7. Do a full system dump and restore to the /mnt mountpoint. If you have more filesystems, restore them to their respective mountpoints (/var goes to /mnt/var, etc).
    # dump -0f - / | restore -rf -
  8. Change to the root directory:
    # cd /
  9. Install bootblocks to make the second disk bootable:
    # /usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd1
  10. Umount the new disk:
    # umount /mnt
  11. Reboot
    # reboot

You can now remove the disk.

This dump can also be done over the network using ssh. Just replace the dump | restore commands with:

# /sbin/dump -0f- / | gzip -2 | ssh -c blowfish user@server dd of=/backup/disk.gz
You can now restore this image over the network at your own leisure. This will also serve as a full disk backup.

On a side note, be sure to read the manpage for newfs(8). Look at the -i option to chose the inode density. Depending on the server's role, you may run out of inodes before you run out of disk space. There's 2 ways to avoid this: larger disks / partitions = more inodes or chaning the inode density. This is especially important since you can't change it in the installer. So one way to avoid such problems is to create the data partition (for your web stuff or whatever) after you've installed the system. That, or dump / newfs -i 2048 / restore.

4 comments:

Anonymous said...

Step 5. should obviously be:
# mount /dev/wd1a /mnt

leo said...

Thank you for informations.Unfortunatelly my O.S. is installed in a flash card. I would like to clone it on usb flash card unit. Using dmesg openbsd recognized:
usb1 at ohci0: USB revision 1.0 and I don't know which unit to use with fdisk,newfs,dump commands. Can you help me? Thank you very much for kindness :-(

cmihai said...

Are you sure that's your device? Normally it would be something like "sd" something (ex: /dev/sd0, /dev/sd1, etc). Try looking at your dmesg again (or try another disk :P).

Take a look at:
http://openbsd.org/faq/faq14.html#flashmem

That's for a fresh install, but the same idea applies for "disk cloning".

Also, without seeing a "dmesg" pastebin or something, I can't help you.

Please keep in mind these instructions are 4 years old :-).

Ariel Merlo said...

I found this guide very useful.
I could change the old disk of my machine sucefully.

Thanks!