Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-23-2012, 08:17 PM
kingneutron kingneutron is offline
Member
 
Join Date: May 2005
Posts: 51
Thanks: 6
Thanked 0 Times in 0 Posts
Talking HOWTO: P2V of non-mirrored ZFS root disk (or Bare-metal recovery)
# See for scripts:
http://communities.vmware.com/thread/406560

-Hi there It's been a while, so I wanted to contribute something to the community again. (Hopefully it helps somebody, cuz it took me like 3 hours to write up!!)

I got to thinking it would be a good idea to be prepared in case I ever had to do a bare-metal recovery of my PCBSD 9/Freebsd 9 server, in case the non-mirrored Root disk died, and Vmware was a natural choice. (Plus I wanted to see if my idea worked.)

I've seen some really complicated recovery howtos out there, with custom scripts and ZFS SEND and the whole 9 yards, but they didn't seem to fit my needs, so I just went ahead and did it My Way (TM.)

In short: I have a tar.gz backup of my PCBSD 9 Root ZFS filesystem on another machine, and want to restore it with a minimum of fuss. To accomplish this, you will need the following:

o First, Obtain the PCBSD 9 " Live DVD 64-bit ", which will act as a recovery boot environment:

http://pcbsd.org/index.php?option=co...mid=98&lang=en

o You will need tar and netcat on the PC that has your backup file on it (in my case, Linux Mint.)

o If you want to use my ' nclisten ' script on your Backup PC, you should either install " pv " (Shell pipeline element to meter data passing through) which gives you a progress report, or you can delete the entire " |pv " line in the script, it will still work.

o Both the backup PC and the VM (or your FREEBSD box) need to be connected to the same network, since we'll be transferring data with netcat. (In my case, Gigabit DHCP 192.168.x.x)

-----

This requires a little bit of preparation, so it's always good to run tests like this *BEFORE* the system fails!

** Document the sizes of your partitions on the original machine. I have a backup script that I use (don't forget to chmod +x it. See vmware page for script.) This documents most of what you need to know for a Restore in " /root/df-h.txt ", which I have included as an example. If you're in a bind and need to know how that original box was configured, it can be easily restored from your tar.gz backup file.

For example purposes, in my case I kept the slightly-tweaked defaults for the PCBSD install (I allocated only 2GB of swap space

On an 80-gig root filesystem disk:

zfs tank0 " / " == 54 GB (used: 322MB) # These are important if you're restoring to a smaller disk!
zfs tank0/usr == 69 GB (used: 15GB)
zfs tank0/var == 54GB (used: 371MB)

This is also important during the restore later, because we'll be using Bind mounts for the various ZFS mountpoints.

Also note: In this case, I restored an 80GB ZFS disk to a smaller 20GB disk. You will probably want a slightly bigger vdisk, like 25-30GB or so, if you have a similar setup.

-----

o Boot your new VM (or PC) with either the PCBSD 64-bit install DVD, or the live DVD.

PROTIP: Learn from my mistake and boot your VM with at least 4GB of RAM. I reduced mine from 6GB to 3GB to save on bootup time, and it froze at the end of the restore. (It booted OK tho!)

PROTIP: The live DVD will ask you which desktop environment to start; since we're doing a Restore and want speed and light resources, I would go with LXDE.

Note: If you're using the PCBSD 9 Live DVD, the installer link is broken on the desktop as of this writing. To run it, Click on the Start menu (lower left) \ Accessories \ Terminal, and run
' pc-sysinstaller '.

o Install PCBSD, making sure you replicate the ZFS mount points the same as the original machine ( in this case, " / " , /usr , /var ) with enough space for everything to fit and some leftover free space.

PROTIP: When selecting the disk for system installation, I used GPT, Entire disk, ZFS - and then went into the Advanced tab and selected " Use default layout ", then Edited the Swap and brought the slider down to 2GB; then Edited /usr and used the slider to fill up the rest of the free space. Whatever you do, if you used GPT on the original box then you should use GPT on the VM or Restore-PC.

PROTIP: When installing the Desktop, you don't need to do the full KDE/GNOME thing, or Ports. Most of this temporary install will be Deleted later on to prep for the Restore, so just install ICEWM. (I actually rebooted into the temporary-install environment to test it, but you don't really have to.)

Note: when you get to the "Users" part of the install, if you're not restoring to bare-metal you might want to make sure you change the Hostname here.

Let the install finish, then Shutdown the VM.

-----

OK - after your nice new PCBSD install is finished in your new VM, Reboot into the Live DVD - and we're going to delete most of it for the Restore

o Boot VM with PCBSD live DVD

# Reference - I picked up some tips from: (Thanx!)
http://forums.freebsd.org/showthread.php?t=17560

Start menu \ Accessories \ Terminal
# So you have a command line to work with ;-)

o Issue the following commands:

mkdir /mnt/tank0
zpool import
# This does not actually do any importing yet, it just gives you a list.

zpool import -R /mnt/tank0 tank0
# this grabs the ZFS root and mounts -almost- everything OK (/usr and /var, but not " / ") - which we will be fixing shortly...

df

zfs list
# since /tank0 mountpoint is LEGACY, it needs to be manually mounted somewhere

# Here we are creating a temporary place to mount the VM's ZFS root so we can have a place to Restore to

mkdir /mnt/tank0/root
mount -t zfs tank0 /mnt/tank0/root
# best compromise - but unless we do union mounts, it's gonna make restoring from tar a pain

# this fixes it right - we have to unmount the Imported /usr and /var and remount them under the temporary root
# for all the files from the tarball to go to the right places automagically:

umount tank0/usr
# otherwise we get busy error
mount -o union -t zfs tank0/usr /mnt/tank0/root/usr

umount tank0/var
mount -o union -t zfs tank0/var /mnt/tank0/root/var

# Explanation: If you don't unmount and UNION those mount points, /mnt/tank0/root/usr ( and var ) are BLANK directories!

# As always, repeat for any other ZFS mount points that are under ' zfs list '.

# Okay - at this point, everything should be in place for the restore, you can check with ' df '

# /mnt/tank0/root == " / "
# /mnt/tank0/root/usr == " /usr "
# /mnt/tank0/root/usr == " /var "

# Midnight Commander - thankfully included on the Live DVD FTW!
mc
cd /mnt/tank0/root

# Fix weird immutable files 1st: (for linux folks, this is equivalent to ' chattr ')
# Otherwhise when we try to delete the dirs, mc will complain that certain files can't be deleted
chflags noschg bin/rcp
chflags noschg lib/*
chflags noschg libexec/*
chflags noschg libexec/resolvconf/*
chflags noschg sbin/*
chflags noschg usr/bin/*
chflags noschg usr/lib/*
chflags noschg usr/lib32/*

# Delete the following dirs: (select multiple with Insert, Delete with F8)
/bin
/boot-mount
/etc
/lib
/libexec
/rescue
/root
/sbin

# Enter into your ZFS mountpoint dirs, and delete the CONTENTS of:
# To select: (with Numlock on, hit the numeric keypad "+" key, select "*" and delete with F8)
/usr
/var

# Leaving behind in the root dir:
/compat
/dev
~home # symlink
/media
/mnt
/proc
/tmp
/usr
/var

---

/ Truncated for 10,000 char post limit!
Reply With Quote
 

Tags
p2v zfs root bare metal

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:13 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Copyright 2005-2010, The PC-BSD Project. PC-BSD and the PC-BSD logo are registered trademarks of iXsystems.
All other content is freely available for sharing under the terms of the Creative Commons Attribution License.