Ubuntu – How to restore lost files in /etc

data-recoveryrestore

I have accidentally removed /etc/ folder.
Now there is no way to do any administration, because /etc/passwd and /etc/shadow are lost.

Is there any way to restore it in Ubuntu?

Best Answer

Here is how I would proceed.

If you want to try to manually recover, boot the ubuntu live CD and update everything

sudo apt-get update && sudo apt-get -y dist-upgrade

You then mount your ubuntu partition at /mnt

sudo -i
mount /dev/sdxy /mnt

You can the copy /etc to /mnt/etc

cp -Raf /etc /mnt

You will then need to manually edit /mnt/etc/passwd and /mnt/etc/group and /mnt/etc/sudoers

The format should be easy enough to understand from existing entries, but if not ask. Make sure your user is in the admin group.

Add in your user to those files ^^

Then chroot

sudo chroot /mnt

And set your user password

passwd your_user

You also need to update /mnt/etc/fstab , define your root partition and swap. You can use the live CD as a template for most of the entries.

reboot and hope it works.

If not, boot the live CD and back up your data to a flash driver or alternate partition and re-install.

Best of luck

Related Question