Skip to content

Instantly share code, notes, and snippets.

@Nithanim
Created April 28, 2019 12:26
Show Gist options
  • Save Nithanim/b08a8c131b87a4a05c0999e75b92a0e3 to your computer and use it in GitHub Desktop.
Save Nithanim/b08a8c131b87a4a05c0999e75b92a0e3 to your computer and use it in GitHub Desktop.
Freenas zfs recovery to nfs share (with geli)
Start the booting process of freenas.
Press any buttons to pause boot sequence.
If you land in menu with boot hit enter
In menu "Welcome to FreeNAS" (shark ascii art) find "escape to loader prompt".
(https://www.ixsystems.com/community/threads/zfs-has-failed-you.11951/)
type "set vfs.zfs.recover=1"
and "set vfs.zfs.debug=1"
then "boot -s"
Wait for "Enter full path name of shell or RETRUN for sh" and then hit enter.
You can change to bash by typing "bash".
Execute "sh /etc/rc.initdiskless" to make filesystem writeable. (The bash history might now be writeable but probably requires that you re-enter bash. Useful if kernel panicks all the time when copyin from froken zfs!)
For easier handling, prepare some commands as shell files on an external drive.
To list device you can use "gpart show". If the output is too long, you can use the scroll lock key and arrow keys to scroll through the output.
Note that only some file systems are supported. I was able to mount ext4 with the ext2 driver as readonly with
"mkdir /mnt/ext && mount -t ext2fs -o ro /dev/da1p1"
You can then call the prepared files from the drive.
I you used geli to encrrypt your zfs, we need to setup the decrypted devices.
Use "export KEY=/data/geli/*" to save the path to the file in the "KEY" variable.
Execute "bash /mnt/ext/setup_geli.sh".
Note: if this does not work, verify that there is only one file in the geli directory. Also the path does not want to copy, you can copy the shell file to the mnt direcctory and then append the path with "echo" and ">>" and the cut and uncut the path to the KEY varaible in "nano".
After all drives are available, you can let zfs search for available pools to import with "zpool import".
Hopefolly oyur pool shows up!
You can then import the pool by name with "zpool import -o readonly=on -f -R /mnt MyPool".
This mounts the pool named "MyPool" as subfolder with the same name in /mnt
If you have porblems importing you can try "-F" and "-m" as additional parameters.
Note that we mount the pool read only to not damage anything further.
You can then "ls /mnt/MyPool" to list your folders on the zfs pool"
To copy out files we we can enable networking by
"bash /mnt/ext/setup_networking.sh"
Or you mount some other disks but I would not recommend that if you system is untrusted or crashes a lot (like mine).
Sadly I could not get the NFS server to work, which would be a hell of a lot better because we could comfortably copy the most important files by sript ort gui.
What I tried was writing the share to "/etc/exports" and then "service nfsd onestart" but would not work.
The alternative is establishing a connection to an nfs server by "bash /mnt/ext/setup_share.sh".
You can then copy your stuff with cp from /mnt/MyPool to /mnt/nfs.
I recommend that you use the "-v" option (to see on which file it crashed if it crashes) and also be VERY selective at first an copy the most important files because it is a pain in the **** to set everything up AGAIN from scrath every time the system crashes.
Copy the most important files first!
GOOD LUCK!
# This decryptes the first four drives. Adapt to your needs.
# Everyhin is mounted read only to not damage anything further
geli attach -r -p -k "$key" /dev/ada0p2
geli attach -r -p -k "$key" /dev/ada1p2
geli attach -r -p -k "$key" /dev/ada2p2
geli attach -r -p -k "$key" /dev/ada3p2
# Adapt to some free address in your network
ifconfig re0 192.168.0.50
# Adapt with the path on your pc
mkdir /mnt/nfs
mount -t nfs -o soft 192.168.0.40:/mount/external/drive/on/your/main/pc /mnt/nfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment