Ubuntu – Problem accessing old data on btrfs /home in ubuntu 14.04

btrfsdata-recoveryfilesystempartitioning

I recently did a fresh installation of ubuntu 14.04 64 bit on my pc. Previously I was dual booting ubuntu 14.04 with windows(both 32 bit). My hdd is 500 GB. The previous structure of the hard disk was as follows:

  • partition 1:type-primary, size:100GB, file system:NTFS(windows)
  • partition 2:type-primary, size:100GB, file system:NTFS(data)
  • partition 3:type-primary, size:100GB, file system:NTFS(data)
  • partition 4:type-extended, size:(remaining), contents:following:-
    • sub-partition 1: size:100GB, file system:NTFS(data)
    • sub-partition 2: size:1GB, file system:ext4(/boot)
    • sub-partition 3: size:50GB, file system:ext4(/)
    • sub-partition 4: size:16GB, file system:ext4(/home)
    • sub-partition 5: size:2GB, file system:swap

Now first I copied data from partition 2 into partition 3. then after creating ubuntu 14.04 live usb on a 8GB pen drive, I deleted partition 1, 2 using Gparted in live session and created a new partition of size 106 GB. Then I copied partition 3 data (both backup of part. 2 and data of part. 3) into new 105GB partition (let's call it root_new) of type:primary and file-system:btrfs. then I copied sub-partition 1 data into root_new and old /home data in root_new. I put all these in separate directory to identify them later. Then I archived old /etc in root_new. After this total backup size was 48GB approx.

Then I deleted partitions 3, 4 and created a new partition on remaining free space of type:primary and file-system:btrfs. let's call it home. Its size is approx. 370GB. Then I copied root_new backup data in home. Then I deleted root_new and created new partitions as follows:

  • partition 1:type-primary, size:1GB, file-system:btrfs(/boot)
  • partition 2:type-primary, size:100GB, file-system:btrfs(/)
  • partition 3:type-swap, size:remaining.

Then I installed ubuntu in the partitions with configurations shown in new part.1, 2, 3 (with formatting) and using home as /home without formatting so that I could access backups on home after installation.

Ubuntu installed successfully. I choose not to encrypt my home directory. But after login I did not find my backup data on /home. There was only my home directory.

Here is output of df command:

$ df -lh
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       100G  3.2G   96G   4% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            986M  8.0K  986M   1% /dev
tmpfs           200M  984K  199M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            996M  156K  996M   1% /run/shm
none            100M   52K  100M   1% /run/user
/dev/sda2       360G   47G  312G  14% /home
/dev/sda1       1.0G   35M  861M   4% /boot

As you can see /home is 14% used.

Here is output of ls -la /home:

$ ls -la /home
total 0
drwxr-xr-x 1 root root   8 May  2  2015 .
drwxr-xr-x 1 root root 176 May  2  2015 ..
drwxr-xr-x 1 kutu kutu 480 May  2 18:00 username

And I'm sure I put backups right under /home in directory which are not showing.

Here is another command.

$ sudo btrfs filesystem df /home 
Data, single: total=47.01GiB, used=46.48GiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00
Metadata, DUP: total=1.00GiB, used=65.45MiB
Metadata, single: total=8.00MiB, used=0.00

Please help me to recover these backup data.

Best Answer

  • I solved the problem!

    First i noticed in /etc/fstab that / was mounted with subvol-@ but /home as subvol=@home. So I googled and found the solution.

    Here are the steps (assuming /home is on /dev/sda2) I did:

    1. Create a directory to mount the total partition.

      sudo mkdir /mnt/old_home
      
    2. Mount the partition.

      mount -t btrfs /dev/sda2 /mnt/btrfs
      
    3. Copy contents from the backup directory to suitable location.

    And that's it.