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):

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)

The output for the most part will be like this:

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

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 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:

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.

Also you can just use PS to see the PID you can also do this:

or  (if you need a better look at what PID of screen is doing what command – use pstree):

Once you find out the PID of your session , then run screen like this:

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:

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:

or with a while loop

NOTE: The awk ‘/./’ will remove any blank lines

Leave a Reply

Your email address will not be published. Required fields are marked *