Thursday Apr 09, 2009

Broken OpenSolaris? NEVER!

If for some reason your OpenSolaris installation is broken or you want to have an exact system on many computers here is the recipe, which I have successfully tested yesterday!

What you will need?
- SSH access to working OpenSolaris - thanks Bob. ;)
- Some free time (copying took around 1h for me, while I was still able to use my OpenSolaris box!!!)

Let's start
1. On your computer choose some unique zfs filesystem name. To check for the names currently used on your system, type the following command in the terminal:
   $ /usr/sbin/zfs list -rHo name rpool/ROOT
   I will use rpool/ROOT/opensolarisbob as it was not listed

2. Make sure you know the IP address of your box:
   $ /usr/sbin/ifconfig -a
   In our case it's 192.168.0.120

3. Log to Bob computer (192.168.0.100):
   $ ssh -l username 192.168.0.100

4. List all BE's and choose the one which you want to copy:
   bob$ /usr/sbin/beadm list -a
   In our case we will use the one:
   opensolaris
     rpool/ROOT/opensolaris

5. From the rpool/ROOT/opensolaris filesystem create snapshot which we will name mysnapshot:
   bob$ pfexec /usr/sbin/zfs snapshot \
   rpool/ROOT/opensolaris@mysnapshot

6. Send the filesystem to our computer using ssh and login name migi:
   bob$ pfexec /usr/sbin/zfs send \
   rpool/ROOT/opensolaris@mysnapshot | ssh \
   migi@192.168.0.120 \
   "pfexec /usr/sbin/zfs recv rpool/ROOT/opensolarisbob"

7. At this point you should see new be on your computer:
   $ /usr/sbin/beadm list

8. Activate the new BE:
   $ pfexec /usr/sbin/beadm activate opensolarisbob

That's All. At this point the system is the same as on the Bob's computer including users and passwords.
If you want to restore your users and passwords you can mount the new BE and copy over or edit few files.
I did something else by simply "restoring" my user "migi" to the new BE by:
pfexec /usr/sbin/beadm mount opensolarisbob /tmp/opensolarisbob
pfexec grep migi /etc/passwd >> /tmp/opensolarisbob/etc/passwd
pfexec grep migi /etc/group >> /tmp/opensolarisbob/etc/group
pfexec grep migi /etc/shadow >> /tmp/opensolarisbob/etc/shadow
pfexec grep migi /etc/user_attr >> /tmp/opensolarisbob/etc/user_attr

Of course if you can't login to your broken OpenSolaris you could use liveCD, import pool and do the same trick, please let me know if you need such instructions.

By the way it's pretty amazing that copying 3GB of the data took around 1h:


View Larger Map