You are not logged in.

#1 2023-04-16 13:19:52

Gravel
Member
From: [object Object]
Registered: 2022-06-01
Posts: 34

[SOLVED] Help with reinstallation after accidental rm -r /*

Hello everyone,

as many have before I have also commited the incredibly dumb mistake of sudo rm -r /*'ing instead of using ./* and as such I have wiped most of my root partition with it.
Fortunately however I managed to stop the command before it wiped out my entire drive and as so I've preserved some of it, mostly the home partition and some of the root directories.

However still the most important dirs like /root /etc /boot and /bin are completely gone and as such while I was still able to use my os post-catastrophe i could not do things like use sudo to reinstall packages with pacman or run any programs, although I was still able to execute commands
I've seen some posts regarding the deletion of these directories and it seems like /etc points to a mandatory reinstall so that's what I'm asking help with

lsblk o/p: http://0x0.st/H81r.txt

p1 is boot (empty)
p2 is swap
p3 is root (ls below)
p4 is home (untouched)

ls /mnt (root, or what remains of it) o/p: http://0x0.st/H81s.txt

And yes, I'm already ordering an HDD to keep a backup for next time.
Any help greatly appreciated :)

Last edited by Gravel (2023-07-23 18:00:33)


"A signature is a small piece of text that is attached to your posts. In it, you can enter just about anything you like. Perhaps you would like to enter your favourite quote or your star sign. It's up to you! In your signature you can use BBCode if it is allowed in this particular forum. You can see the features that are allowed/enabled listed below whenever you edit your signature."

Offline

#2 2023-04-16 13:31:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: [SOLVED] Help with reinstallation after accidental rm -r /*

I'm not sure what you are asking.  You've booted into a live iso and mounted your partitions already it would seem.  So just run pacman (with --sysroot=/mnt flag) to reinstall any packages you had.  If the local database under /var is still there, you can even query which packages you had installed in order to know exactly what to reinstall.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2023-04-16 13:50:03

Gravel
Member
From: [object Object]
Registered: 2022-06-01
Posts: 34

Re: [SOLVED] Help with reinstallation after accidental rm -r /*

Wait really? That easy? I can restore my bootloader and /etc files with pacman and get my system back? Won't anything overwrite my home partition?
Please pardon my ignorance but I'm scared I'll cause further damage to the system by not knowing what I'm doing so if you could give a brief explanation on how to restore /boot /etc and query packages from /var it would mean the absolute world to me (or how to find leads on how to do that for the matter)


"A signature is a small piece of text that is attached to your posts. In it, you can enter just about anything you like. Perhaps you would like to enter your favourite quote or your star sign. It's up to you! In your signature you can use BBCode if it is allowed in this particular forum. You can see the features that are allowed/enabled listed below whenever you edit your signature."

Offline

#4 2023-04-16 14:04:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,531
Website

Re: [SOLVED] Help with reinstallation after accidental rm -r /*

For querying packages from /var, you'd use pacman, e.g.,

pacman --sysroot /mnt -Qq | pacman --sysroot /mnt -S -

You'd have to reconfigure anything just as you did in the intial install.  Just follow part 3 of the installation guide after installing the packages.

The only thing that would "touch" your home partition is you.  Other than for generating the fstab (with genfstab), you wouldn't even need to have the home partition mounted.

You'd also need to redo any post-install configuration you may have done.  E.g., you'll need to recreate your user account (but should specify the existing user directory), reconfigure sudo (via visudo) if you want to use that, redo any network configuration(s) for known networks.

EDIT: Actually I'm not sure if that pacman command will work as is - it's worth a shot.  But if there is no /mnt/etc/pacman.conf it may fail.  In that case you'd need to use pacstrap.  But still you'd be able to extract a list of packages from /var (assuming that is still there):

sed -n '/%NAME%/{n;p;}' /mnt/var/lib/pacman/local/*/desc > pkglist

Note that you can also just go through the whole installation process, just leave the home partition alone.  This actually might be the cleanest approach as my suggestions above aren't really salvaging anything else anyways.  With a clean install you could just follow the installation guide and associated docs with no revisions (just don't reformat your home partition).  But grabbing the pkglist above might be useful (note that this includes explicit and as-deps packages, so do just blindly install all of them on the new system).

In otherwords:

1. get the pkglist
2. reformat (mkfs) p1, p2, and p3 (not p4).  Mount the partitions
3. copy pkglist to /mnt/home/<yourusername>/ for later use
4. pick up with part two of the installation guide and go from there
5. once fully installed, reboot into the new system, and review pkglist to figure out what packages to install.

Last edited by Trilby (2023-04-16 14:19:31)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2023-04-16 15:12:46

Gravel
Member
From: [object Object]
Registered: 2022-06-01
Posts: 34

Re: [SOLVED] Help with reinstallation after accidental rm -r /*

Tried using pacman but it returns "error: config file /etc/pacman.conf could not be read: No such file or directory". Should I just copy the pacman.conf from the live os to /mint/etc?

P.D. pacstrap doesn't work either since no config file either

Also about reinstalling completely, I'm wishing to get as much similarity to my pre nuke OS as I can, that is, will I end up with an install different than what I could do with my current salvage?
(I know that beggars can't be choosers so I'm only asking if there's that possibility)


Update:

I got my system back without any data loss. I reinstalled all my packages thanks to the list you suggested me to make and got everything running back again after a day or so.
Thank you!

Last edited by Gravel (2023-07-23 17:59:22)


"A signature is a small piece of text that is attached to your posts. In it, you can enter just about anything you like. Perhaps you would like to enter your favourite quote or your star sign. It's up to you! In your signature you can use BBCode if it is allowed in this particular forum. You can see the features that are allowed/enabled listed below whenever you edit your signature."

Offline

Board footer

Powered by FluxBB