Skip to main content
Topic: Deleted /usr directory entirely. How to salvage system? (Read 667 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

Deleted /usr directory entirely. How to salvage system?

Hello. I am not only new to Artix Linux forum, but also new to Arch-based systems as I have been working with the past few days. So I have been trying to install dependencies for a mail server today and extracted a "usr" file from the gmime tar file downloaded from the AUR into my Downloads folder. Then I wanted to delete the file because I didn't find the PKGBUILD I was looking for, and then told the terminal "sudo rm -rf /usr" thinking that I'm in the same directory where this other "usr" file was in. Suddenly after running this command, my computer went blank and had just realized, "Shit, I deleted the /usr directory on the system." I rebooted the computer, and it now leads me to a screen where it says that /dev/sda1is clean. Know what else it says? This:

ERROR: Root device mounted successfully, but /sbin/init does not exist
Bailing out, you are on your own. Good Luck

sh: can't access tty; job control turned off


I'll admit that this is a newbie mistake, but I can't fathom throwing away what I essentially put about 20 hours into building the system ideal for me. I can make a live USB with Artix on it if that's the case to recover /usr. What are my options at this point?


Re: Deleted /usr directory entirely. How to salvage system?

Reply #2
I can make a live USB with Artix on it if that's the case to recover /usr. What are my options at this point?
Not that bad, I've done worse. Boot your live USB and mount the root partition to, say, /mnt.
Then reinstall all packages to your damaged filesystem, by instructing pacman to look into /mnt/var/lib/pacman/db:
Code: [Select]
# pacman -Sy -b /mnt/var/lib/pacman
# pacman -S $(pacman -Qqe -b /mnt/var/lib/pacman) -b /mnt/var/lib/pacman -r /mnt --cachedir /mnt/var/cache/pacman/pkg
# pacman -S --asdeps $(pacman -Qqd -b /mnt/var/lib/pacman) -b /mnt/var/lib/pacman -r /mnt --cachedir /mnt/var/cache/pacman/pkg
This will preserve the installation cause of your packages, i.e. first fix explicitly installed and second dependency packages. You may want to add --noconfirm and/or --overwrite='*' to the commands. The latter is untested, better run it without, it'll just take a little longer waiting for your confirmation.

Re: Deleted /usr directory entirely. How to salvage system?

Reply #3
Not that bad, I've done worse. Boot your live USB and mount the root partition to, say, /mnt.
Then reinstall all packages to your damaged filesystem, by instructing pacman to look into /mnt/var/lib/pacman/db:
Code: [Select]
# pacman -Sy -b /mnt/var/lib/pacman
# pacman -S -b /mnt/var/lib/pacman pacman -S $(pacman -Qqe -b /mnt/var/lib/pacman) -r /mnt --cachedir /mnt/var/cache/pacman/pkg
# pacman -S --asdeps $(pacman -Qqd -b /mnt/var/lib/pacman) -r /mnt --cachedir /mnt/var/cache/pacman/pkg
This will preserve the installation cause of your packages, i.e. first fix explicitly installed and second dependency packages. You may want to add --noconfirm and/or --overwrite='*' to the commands. The latter is untested, better run it without, it'll just take a little longer waiting for your confirmation.

Okay, I entered pacman -S -b /mnt/var/lib/pacman pacman -S $(pacman -Qqe -b /mnt/var/lib/pacman) -r /mnt --cachedir /mnt/var/cache/pacman/pkg and got the message:
error: only one operation may be used at a time

Can you shorten the command for me? I managed to mount /dev/sda1 to /mnt like you said and ran pacman -Sy -b /mnt/var/lib/pacman without any issues.

Re: Deleted /usr directory entirely. How to salvage system?

Reply #4
Okay, I entered pacman -S -b /mnt/var/lib/pacman pacman -S $(pacman -Qqe -b /mnt/var/lib/pacman) -r /mnt --cachedir /mnt/var/cache/pacman/pkg and got the message:
error: only one operation may be used at a time

Can you shorten the command for me? I managed to mount /dev/sda1 to /mnt like you said and ran pacman -Sy -b /mnt/var/lib/pacman without any issues.
Duh, wrong copy/paste, fixed original message too.
Code: [Select]
# pacman -S $(pacman -Qqe -b /mnt/var/lib/pacman) -b /mnt/var/lib/pacman -r /mnt --cachedir /mnt/var/cache/pacman/pkg
# pacman -S --asdeps $(pacman -Qqd -b /mnt/var/lib/pacman) -b /mnt/var/lib/pacman -r /mnt --cachedir /mnt/var/cache/pacman/pkg