USE METHODS AT YOUR OWN RISK, IF YOU DECIDE TO USE THIS ARTICLE, HEED ALL OF THE SAFETY MEASURE (IF I MISSED A SAFETY MEASURE, DONT BLAME ME, I SAID USE AT YOUR OWN RISK)
Note this inspired from this forum I left an answer on: http://askubuntu.com/questions/157917/how-do-i-recover-a-btrfs-partition-that-will-not-mount/407766#407766
If you have a btrfs volume thats not mounting, or has transid issues (this might be the first best move for transid issues, first I would try mounting though: btrfs transid article), or after everything it just doesn’t budge. This might be your only option. This looks thru the filesystem and dumps what it can to a USB, it works in situations where mount will not work, so its a good tool for recovery. Currently (1/19/2014) there is little to no info on btrfs on the web, so everything on it is gold.
Just like EXT2 EXT3 and EXT4 has way to dump a corrupt filesystem as a feature: debugfs ext article
We will use btrfs restore command, if its not on your command set for btrfs, try upgrading your btrfs version
Note some of these options might not be available to you and you will need to get the package. The name of the package for all this is the btrfs-tools, apt-get might not have the latest so you might need to look online for the sources and compile them
BTRFSCK
NOTE: I assume your btrfs volume is /dev/sda3
First off run btrfsck /dev/sda3
Thats a readyonly check of the system so it will not hurt your volume any further but you can get an idea of what is going on with it
BTRFS RECOVERY MOUNTS
First off before restoring try some mounts (dont forget to include the options you had on your btrfs volume, try mixing your options with these – I know thats wierd but for now thats all we have to go off):
# mount -t btrfs -o ro /dev/sda3 /mnt/sda3 # mount -t btrfs -o ro,recovery /dev/sda3 /mnt/sda3 # mount -t btrfs -o recovery /dev/sda3 /mnt/sda3 # mount -t btrfs -o rootflags=recovery,nospace_cache /dev/sda3 /mnt/sda3 # mount -t btrfs -o rootflags=recovery,nospace_cache,clear_cache /dev/sda3 /mnt/sda3 # mount -t btrfs -o recovery,nospace_cache,clear_cache /dev/sda3 /mnt/sda3 # mount -t btrfs -o ro,rootflags=recovery,nospace_cache /dev/sda3 /mnt/sda3 # mount -t btrfs -o ro,rootflags=recovery,nospace_cache,clear_cache /dev/sda3 /mnt/sda3 # mount -t btrfs -o ro,recovery,nospace_cache,nospace_cache /dev/sda3 /mnt/sda3
If it mounts successfully, you will be lucky enough not to have to use btrfs restore (its just faster to have a mount and dump, plus you can use better copy tools). After the mounts are successful just use cp,tar,rsync, whatever your favorite method of backup is to get your data to a safe location. After getting your data to a safe location it might be safe to do a btrfsck –repair
BTRFS RESTORE
Here is a quick manual on it: https://btrfs.wiki.kernel.org/index.php/Restore
If the btrfs recovery mounts dont work. Then try this. Again this will attempt to dump the disk to a specified location.
First attach a mount (USB, or network mount) that can hold enough space to contain the entirety of the filesystem (snapshots not included). I will assume that mount point is called /USB (but for you it might be /mnt)
# btrfs restore /dev/sda3 /USB
The output for the most part will be like this:
..skip.. offset is 5087232 offset is 5095424 offset is 5103616 offset is 5111808 offset is 5120000 offset is 5128192
This process might take forever. And keep an eye on it. It comes up with prompts (about some recursive situation that it might of got in and you have to answer yes to continue) you have to answer either “y” or “Y” to (I might be wrong and it might be just one upper/lower casing of the letter so just “y” answers or just “Y” answers). So type in what it wants “y” or “Y” without the quotes and hit ENTER.
I know what your thinking, “I wish there was a force yes” (to that prompt I only answer yes. That is all I ever answer to it, and maybe that’s the wrong way to go about it, but where is the documentation telling us that’s the wrong way? This is all we got folks, for now at least)
SINCE ITS A LONG PROCESS I RECOMMEND LAUNCHING IT WITH SCREEN OR DETACH
Here is an example with screen
# screen /bin/bash # btrfs restore /dev/sda5 /USB
To detach (btrfs restore will still continue to run run):
CONTROL-a then type “:detach” without the quotes then press ENTER
Another way to detach: close out of putty or your terminal and it will detach (as mentioned the command btrfs restore will still run).
To check up on it, just reattach screen back to it:
# screen -x
screen -x will attach to sessions, even if detached, and unlike -h, help, says it will attach even if its already attached as well.
If you have several screens, screen -x will tell you need to be more specific to attach to the session by its PID (PID of the screen command), it will list the sessions but you can also list the sessions like so:
# screen -ls OUTPUT AS SUCH MIGHT APPEAR: There are screens on: 30074.pts-3.3C82350F00DF5 (01/19/14 06:17:55) (Attached) 29864.pts-2.3C82350F00DF5 (01/19/14 06:14:37) (Attached) 2239.pts-1.3C82350F00DF5 (01/06/14 19:29:30) (Attached) 3 Sockets in /var/run/screen/S-root.
Remember “ls” for list all sessions, easy to remember that.
Also when there are many sessions screen -x will have that same output, asking you to pick the correct session by PID.
# screen -x OUTPUT AS SUCH MIGHT APPEAR: There are several suitable screens on: 30074.pts-3.3C82350F00DF5 (01/19/14 06:17:55) (Attached) 29864.pts-2.3C82350F00DF5 (01/19/14 06:14:37) (Attached) 2239.pts-1.3C82350F00DF5 (01/06/14 19:29:30) (Attached) Type "screen [-d] -r [pid.]tty.host" to resume one of them.
Also you can just use PS to see the PID you can also do this:
# ps aux | grep screen
or (if you need a better look at what PID of screen is doing what command – use pstree):
# pstree -aP OUTPUT MAYBE LIKE THIS: ..skip.. |-screen,2239 /bin/bash | `-bash,2240 | `-btrfs,2241 restore -i /dev/md127 /mnt/RN516/data/ |-screen,29864 /bin/bash | `-bash,29865 | `-watch,29871 -n10 ./makechart.sh | tac
Once you find out the PID of your session , then run screen like this:
# screen -x PID
Example: if I wanted to attach to 2239.pts-1.3C82350F00DF5 (because from the pstree it looks like the brtfs restore is right there under the 2239 screen PID), I could just write:
# screen -x 2239
That will attach to a specific session. You can have several sessions/puttys attached to the same screen (they will output the same text, you can type commands in one, and they will be mirrored on the other putty)
MONITORING YOUR BTRFS RESTORE
Simplest way is just to watch or do a while loop if you dont have watch:
# watch -n0.1 '(date; ((df -h && df)); echo ----; top -cbn1 | awk '/./' | head -n10;)' # watch -n0.1 '(date; ((df -h && df)|egrep -i "File|/USB"); echo ----; top -cbn1 | awk '/./' | head -n10;)'
or with a while loop
# while true; do date; ((df -h && df)); echo "----"; top -cbn1 | awk '/./' | head -n10; sleep 1; done; # while true; do date; ((df -h && df)|egrep -i "File|/USB"); echo "----"; top -cbn1 | awk '/./' | head -n10; sleep 1; done;
NOTE: The awk ‘/./’ will remove any blank lines