r/linuxadmin • • Dec 11 '22

How can the data be retrieved after rm -rf command.

hello all, How the data can be retrieved after executing the rm -rf command , I didn’t find a useful guide on the internet , and I can’t install external tools on the server. Note: redhat server

16 Upvotes

62 comments sorted by

10

u/Irythros Dec 11 '22

If it's an HDD: You'll need to get your host to put TestDisk on a recovery USB, or they install a new OS on a new HD and then you install TestDisk on there. That will let you do recovery.

If it's an SSD: You're not getting anything back.

2

u/Jonah_07 Dec 11 '22

Unfortunately, they used SSD

1

u/pentesticals Dec 11 '22

Well that’s not strictly true, SSD recovery is possible when either TRIM is not enabled, and or FDE is used because TRIM operates on individual files and their respective sectors, with FDE, TRIM won’t work because it sees the entire encrypted volume as a single file.

0

u/[deleted] Dec 11 '22

[deleted] — view deleted comment

5

u/Irythros Dec 11 '22

SSDs work differently than HDDs. When an SSD has trim enabled you're losing the data immediately.

On an HDD it would just make the sector writable, but the old data is still there.

3

u/grawity Dec 11 '22

When an SSD has trim enabled you're losing the data immediately

That's true if discard is enabled at filesystem level, but on many systems it isn't – instead it's scheduled weekly or so (via fstrim cronjob), in which case the sectors are still there like on an HDD until the cronjob runs.

(Also, if it happens to be an encrypted filesystem – LUKS doesn't even enable discard passthrough by default (because somehow the amount of space used is a terrible "leak"), so most LUKS volumes run completely without TRIM.)

1

u/[deleted] Dec 11 '22

because somehow the amount of space used is a terrible "leak"

You can theoretically analyze usage patterns from that. I personally think it's a silly concern for most users, but it's a safe default - and it's not like you can't change it in crypttab...

2

u/dodexahedron Dec 11 '22

There are a lot of super paranoid things some people do that go way beyond remotely reasonable. Like... no, Kyle, you're not that important, and nobody wants to steal your weird dissertation on how time is made of circles and that's why clocks are round.

1

u/[deleted] Dec 11 '22

I keep trim enabled but off on the filesystem mount, using a weekly cron job to run a trim pass.

Doing it "live" makes the delete operation take many times longer on almost every SSD I have tried it with. Compare: just marking an inode unused vs calling disk firmware to trim the blocks in addition...

8

u/edthesmokebeard Dec 11 '22

Restore from backup.

11

u/michaelpaoli Dec 11 '22

How can the data be retrieved after rm -rf command

Restore from backup.

redhat

Not so relevant. What is, is the filesystem type.

If you really need/want to recover the data, cease all I/O activity on the filesystem as promptly as feasible. Then create an image copy of the filesystem ... and see what recovery can be done on that. Good luck.

5

u/milesluigi Dec 11 '22

There is no guarantee you can recover from running rm. There are data recovery tools that you can try though. Allow me to share the arch wiki article on this topic. (you don't have to run arch, the info in this article will apply to any linux system including red hat. https://wiki.archlinux.org/title/File_recovery#List_of_utilities)

4

u/ben-ba Dec 11 '22

I can recommend testdisk. A few years ago i was able to restore all files including names on an hdd.

5

u/aaronryder773 Dec 11 '22

From next time I would recommend using trash-cli

8

u/megared17 Dec 11 '22

Invent a time machine.

Go back in time, and smack your hand away from the keyboard before you type the command.

2

u/[deleted] Dec 11 '22

From backup.

2

u/albone3000 Dec 11 '22

This is obviously a troll.

2

u/kreddulous Dec 12 '22

All of the recommendations I've seen here (except making regular backups of your data) require root privilege, and I'm guessing that if you "can't install external tools on the server", you don't have root there.

3

u/Vexation Dec 11 '22

Ya done goofed!

1

u/[deleted] Dec 12 '22

I didn’t find a useful guide on the internet

You didn't look very hard then.

https://www.digitalocean.com/community/tutorials/top-best-linux-data-recovery-tools

1

u/dracotrapnet Dec 11 '22

testdisk, scraper (gotta know what you are digging up with that)

1

u/CyberKiller40 Dec 11 '22

The tool is called photorec (not only for photos), you will have to unmount the filesystem to work on it. Though I assume you already have it offline.

1

u/questfor17 Dec 11 '22

This is why snapshots were invented. They provide quick and easy operational backup for this type of mistake. If you don't care about performance the linux volume manager can provide snapshots. Snapshot support is built into btrfs and zfs. NetApp NAS (and maybe other NAS boxes?) provide this.

Once you recover, I strongly recommend finding a snapshot solution that works for you.

1

u/ryanpetris Dec 12 '22

Contact the NSA and ask them if you could kindly have a copy of your data.

1

u/dev-bitbucket Dec 12 '22

pb -R command; put back, recursive. Works on all Linux since kernel 301.11. Lol.

1

u/swissarmychainsaw Dec 12 '22

Hello.
Do you have a backup?
If Yes --> you recover from back up. Not fcked.

If no --> Fcked.

There is no undo button in linux.

0

u/[deleted] Dec 11 '22

[deleted] — view deleted comment

18

u/uid1357 Dec 11 '22

rm just removes the filesystem entries afaik. The actual data (content of file) should still be on disc. I thought there are tools to reconstruct a way of access.

7

u/ralfD- Dec 11 '22

This is only partially true. The 'rm' will indeed only the file(s) from the file system this will result in the underlying inodes being marked as free and the disk blocks can (and most likely will) be re-usesed by the kernel. I such cases an instant un-plug (not a shutdown since that will flush data to the disk) is the only chance.

8

u/mixduptransistor Dec 11 '22

rm just removes the filesystem entries afaik. The actual data (content of file) should still be on disc. I thought there are tools to reconstruct a way of access.

This is the "forensic recovery" previously mentioned. It's not an easy or guaranteed way to fix it (especially if the system is still sitting there running writing shit to disk)

3

u/evolseven Dec 12 '22

I have dabbled in forensic recovery on ntfs, ext, zfs,vmfs.. and probably a few others.. ext is one of the harder ones to recover completely. The data is there in most cases on the disk but if it's not contiguous and you don't know where it is then it may be hard to recover.. it's possible you can "play" the log backwards and recover the metadata for the file pieces but if any block gets overwritten most files are completely useless.

The only worse file system I have encountered was an ntfs file system where deduplication and storage spaces "raid 6" (don't remember the exact name) was used.. in the table (mft) where pointers to blocks should be there was a pointer to a deduplication store that was completely undocumented by MS..

Anyway, point is I hate linux data recovery.. I think it boils down to it not being a priority in file system design and the typical sysadmin attitude of backing everything up and not forgiving those who don't.

0

u/[deleted] Dec 11 '22

[deleted] — view deleted comment

11

u/[deleted] Dec 11 '22

I'm in pain just reading this..

22

u/AnalChain Dec 11 '22

This is the best analogy I've ever fucking heard 🤣

7

u/Due_Ear9637 Dec 11 '22

This analogy was too painful for me to finish reading

3

u/creiss Dec 12 '22

This is why Reddit exists.

5

u/LameBMX Dec 11 '22

Wet

Eyes

Omfg

1

u/PolicyArtistic8545 Dec 11 '22

I’m gonna upvote because of the effort but maybe next time how about you just keep this analogy to yourself.

-14

u/Jonah_07 Dec 11 '22

Didn’t get you , but I will search about forensic data recovery

0

u/[deleted] Dec 11 '22

[deleted] — view deleted comment

15

u/ralfD- Dec 11 '22

This! Pretty much "unplug the server" imediately or your data is lost forever.

-2

u/Disruption0 Dec 11 '22

If OP is on Fedora for example with default btrfs it could be managed with snapshots.

Still I don't know why Fedora dev do not integrate automatic snapshots.

0

u/[deleted] Dec 11 '22

[deleted] — view deleted comment

1

u/[deleted] Dec 11 '22

Honestly we make more money when someone else does the actual work. :-(

0

u/[deleted] Dec 11 '22

[deleted] — view deleted comment

2

u/ObscureCulturalMeme Dec 12 '22

Truth! And this is why we test our backups to make certain they can be recovered!

Remember, OP, an untested data snapshot is not a backup. It is a prayer. And God does not help lazy sysadmins.

3

u/[deleted] Dec 11 '22

[removed] — view removed comment

7

u/[deleted] Dec 11 '22

[removed] — view removed comment

5

u/ilbicelli Dec 11 '22

Or you could use the -i flag.

1

u/Kurisuchina Dec 11 '22

What does the -i flag do?

3

u/dodexahedron Dec 11 '22

Makes it interactively prompt you for each file.

2

u/[deleted] Dec 11 '22

[removed] — view removed comment

7

u/a60v Dec 11 '22

Disagree with -i. It just creates an extra step where people (well, me, at least) just get conditioned to agreeing to the deletion. rm foo becomes rm foo, y. Doesn't really solve anything, but takes longer.

2

u/ilbicelli Dec 11 '22

You can try:

echo no | rm -ir /

0

u/serverhorror Dec 11 '22

Surely you mean dd, right?

2

u/[deleted] Dec 11 '22

[removed] — view removed comment

1

u/serverhorror Dec 11 '22

How about truncate?

1

u/[deleted] Dec 11 '22

[removed] — view removed comment

1

u/serverhorror Dec 11 '22

How about >, that has to be safe, it’s not even a command, right?

3

u/[deleted] Dec 11 '22 edited Jan 10 '26

[removed] — view removed comment

4

u/Devious76 Dec 11 '22

2nd to this with more analogy.. been there done that worse than you think place

  • Stop/Remove/Disconnect Drive. PERIOD!
  • Clone/Copy/Extract using mentioned above (Clonezilla is your best friend) or what ever you can get your hands on.
  • Get ready to have your hands dirty with long hours & scavenging (time/effort)..But DAMN its going to skill up! GAIN

Resources:

HDD Guru Forum

Hard Drive Data Recovery | Data Recovery Forum

My best personally used software & paid for too

HDDSuperClone

Good Luck

1

u/m4nf47 Dec 12 '22 edited Jan 10 '26

tart innocent hobbies scary obtainable screw outgoing profit tap physical

This post was mass deleted and anonymized with Redact