4

I'm using 11.10 (ext4) and somehow I've lost /home/myuserid. /home is there, but appears empty. I can boot to the login prompt and login as Guest, but when attempting to login as myuserid, I get routed back to the login screen. I can also boot into recovery mode via Grub, then to a root prompt. As both Guest and root, /home appears empty:

root@ubuntu:~$ cd /home
root@ubuntu:/home$ ls -al
total 0
drwxr-xr-x  1 root   root    60 2012-01-13 07:42 .
drwxr-xr-x  1 root   root   240 2012-01-13 07:42 ..
root@ubuntu:/home$ 

However, when I boot the computer with my Ubuntu installation USB, run from USB, and open Nautilus, I can see /home/myuserid is there, and all the files in it are intact. I tried recovering it using parted as explained on the Ubuntu Data Recovery page, but the rescue START END command didn't do anything (didn't even give a return code, just a new prompt).

It seems like I've just deleted a pointer in the partition table to the location on disk or something, without deleting the actual partition and files. Anyone know how to restore /home/myuserid?

PS - I've read through many of the threads here on this topic, but they all seem oriented toward restoring lost files, rather than restoring a partition table pointer to a user folder, or fixing a problem with a user folder not mounting correctly, or whatever it is I've done here. My files really aren't lost, I can see and open them just fine when running from the USB drive, and I'm hesitant to try recovery tools like PhotoRec when 1) they don't seem 100% reliable, and 2) I suspect the solution is simpler.

Edit: /home is not mounted now. Booting with the USB drive, which is what I'm doing now, does not automount it. And yes /home is on its own partition (as are /boot, swap, /, and /home, all on separate partitions).

Zanna
  • 72,312
bgibson
  • 5,037

2 Answers2

2

OP's own answer edited out of the question:

Solution: Boot with Ubuntu Live USB, find the missing user directory in /media, back it up, then boot into the Recovery Console Root Prompt, run mount -a to force mount everything in fstab, then reboot and try logging in again. Details:

  1. Backup /home/myuserdir using cp -ax to preserve all links and attributes:

    • Plug in an external hard drive or other backup media via USB.
    • Boot from USB startup disk. [1][1] [2][2]
    • Open a terminal, cd /media
    • Find the unmounted /home partition in /media. It may be named a long GUID string instead of /home. Just cd into it and see if the missing /home/myuserid (or /[GUID]/myuserid) partition is there. Once you've found it, then ...
    • Copy the entire user directory to backup media using [cp -ax to preserve links and attributes][3]:
    • ubuntu@ubuntu:/> cd /media/[GUID]
    • ubuntu@ubuntu:/media/[GUID]> cp -ax * /media/backupdrivename/backupdir
    • This will take a while. About 30-40m for my 117GBs, for reference.
  2. Log out, shutdown, remove the USB startup drive and the backup hard drive. Reboot into the Ubuntu Recovery Console.

    • Hold Shift down while booting to display the GRUB boot menu. Choose the Recovery Console boot option.
  3. In Recovery Console, select the option to drop into a Root Prompt.

  4. At the root prompt, run mount -a to mount everything in /etc/fstab. Now check /home with ls -al /home. With luck /home/myuserdir is now there.

  5. Reboot with sudo reboot. If Ubuntu starts the auto filesystem check during reboot, let it run, don't cancel. At the login screen, login with normal userid.

  6. After this my /home/userdir had been restored and I could log in normally and everything worked.

Zanna
  • 72,312
2

We do not know why or how you lost your $HOME but from what you said it still seems there.

You can easily switch to a shell from your Guest Session by pressing Alt+Ctrl+F1. From there login with your myuserid. You may experience an error saying No directory: logging in with HOME=/. After being logged in run

cd /home/myuserid
ls

If all files are in place and only then you may be able to restore your HOME with the following command

sudo usermod -d /home/myuserid myuserid

Log out from the guest session and login to your account as usual.

If your files are not visible from the guest session then do as comments already suggested. Backup your data or try to mount the partition where /home resides.

Takkat
  • 144,580