Linux File Recovery Study

来源:http://www.cnblogs.com/00100011F/archive/2016/06/23/5611370.html
-Advertisement-
Play Games

Background Today I did stupid things that I went into the ~/Downloads/ and pressed [Alt] + [A] then [Shift] + [Delete]. Wtf... I didn't want to delete ...


Background


Today I did stupid things that I went into the ~/Downloads/ and pressed [Alt] + [A] then [Shift] + [Delete]. Wtf... I didn't want to delete this folder but another sub-folder...... So no zuo no die : )


Theory


  • Generally, Linux filesystem mainly contains inode and blocks. inode is the index of file or directory; blocks stores the actual data.

  • Usually, our rm or [Shift] + [Delete] in GUI just modify the inode but do not rewrite the blocks in which your data has ever be (If you use some special professional softwares to delete file, good luck : ) ).

  • So if our file is just there as it was before if we take measures in time. We can't use filename or inode to fetch it, but there are other probably ways to make it.

  • EMPTY. I want to add more filesystem knowledge here later. Remind me of it, OK ?

P.S. The filesystem is very interesting. You can regard it as local Domain Name System to some extent. And the filename is something like the domain name, while inode is something like IP address.


Recovery


Environment: Linux (I tried on Ubuntu 14.04 & CentOS 6.0)
Filesystem: Ext4 [1]
Of course, you'd better be root and everything will be easier.

0x0 Forbid other users and processes to Modify the filesystem

~If no speical prompts, you'd better follow this part to protect your data.
~Now we test on /dev/sda8 mounting at /tmp. sth in /tmp may be erased after mounting or unmounting, but sth in /tmp/lost+found may not.
~I use cat /proc/meminfo > /tmp/lost+found/tet to create a test file and delete it.
~fs means filesystem.
~sth means something.

For the test, I md5sum /tmp/lost+found/tet before deleting it

Before unmounting, use ls -id /tmp and take down the inode number

  1. use df or fdisk -l to determine the fs to be unmounted
  2. unmount it: umount /dev/sda8

  3. mount the fs with read-only state: mount -r -n /dev/sda8 And you can have a try to write sth and find failed.

P.S.
~When I man umount I found umount /dev/sda8 is not recommended and it's better to use umount /tmp (directory name). And after I mount -r -n /dev/sda8, I failed to use umount /dev/sda8 to unmount it.
~If the fs is busy and you can't unmount it. You can use fuser -v -m /dev/sda8 to find the processes using it and kill them. What's more, you can use fuser -k -v -m /dev/sda8 to kill them automatically.


Here I will give some methods I have tried(the title is the main tool to be used).

0x1 extundelete

  • yum install e2fsprogs e2fsprogs-libs e2fsprogs-devel
  • wget http://tenet.dl.sourceforge.net/project/extundelete/extundelete/0.2.4/extundelete-0.2.4.tar.bz2
    If you didn't install g++ like me, yum install gcc-c++
  • ./configure
  • make && make install
  • extundelete /dev/sda8 --inode 2 to check

  • extundelete /dev/sda8 --restore-directory lost+found
    here I use --restore-directory, you can also use --restore-file RELATIVE-PATH-OF-FILE
  • md5sum ./RECOVERD_FILES/lost+found/tet

Bingo~

P.S.
You can also use extundelete /dev/sda8 --restore-all simply.

0x02 debugfs & dd

...

0x03 testdisk

...


Finally


Some advice:

  • Backup is very very important
  • Disk should be parted into filesystems (/,/home,/boot,/var,/usr,swap,...)
  • alias rm="rm -i"

Quotations


I learnt knowledge from articles below. Thanks for the authors' sharing.


Appendix


[1] How to determine your filesystem?

  1. fdisk -l # to get the name of disk. E.g. /dev/sda5
    You can also use df and this tool can show the relationship between fs and your directories. However, this tool can only deal with fs being mounted.
  2. file -s /dev/sda5


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 本文的本本win7 64bit 6G android studio2.1 在運行程式的時候Gradle Build Running 特別慢,一個helloworld都快2min了 1、開啟gradle單獨的守護進程 在下麵的目錄下麵創建gradle.properties文件: /home/<user ...
  • ZIP壓縮包文件中允許存在“../”的字元串,攻擊者可通過精心構造ZIP文件,利用多個“../”從而改變ZIP包中某個文件的存放位置,覆蓋替換掉應用原有的文件。 ...
  • 8.Vsync 8.1概論 VSYNC(Vertical Synchronization)是一個相當古老的概念,對於游戲玩家,它有一個更加大名鼎鼎的中文名字—-垂直同步。 “垂直同步(vsync)”指的是顯卡的輸出幀數和屏幕的垂直刷新率相同,這完全是一個CRT顯示器上的概念。其實無論是VSYNC還是 ...
  • 打開Android Studio,依次【File】-【Settings】 在打開的settings界面里找到plugins設置項,點擊右側的“Browser。。”按鈕 在搜索欄里輸入genymotion關鍵字,可以看到右側已經搜索到插件,點擊install安裝。 開始下載,速度很快。安裝後重新啟動A ...
  • 大家好,本人是高三剛畢業,即將踏入校園的程式猿~我寫這篇文章呢,主要是想鞏固一下之前對於電腦的基礎知識理論,也希望能幫助沒有電腦基礎的同學能維護一下自己的電腦,要是能幫助女生修電腦那就是更好啦~~哈哈哈,話不多說,直接進入主題~!!(本教程出現的鏈接大家可以複製到網頁地址欄進入) 本教程總共分為: ...
  • WOL(從網卡喚醒)諸多限制,內網都不穩定,外網更不用說,放棄 斷電恢覆上次狀態,必須的 通電即開機,必須的 WIFI智能開關一個 受管理的伺服器 Esxi 6 2台,windows 2012 2台 統一使用WIFI開關,esxi6設置SSH自啟動,設置VM隨主機開關機,HYPERV設置VM自啟動 ... ...
  • ld --verbose | grep SEARCH ...
  • 如何保護你的linux操作系統 如何保護你的linux操作系統 導讀 在現在這個世道中,Linux操作系統的安全是十分重要的。但是,你得知道怎麼乾。一個簡單反惡意程式軟體是遠遠不夠的,你需要採取其它措施來協同工作。那麼試試下麵這些手段吧。 使用SELinux SELinux是用來對Linux進行安全 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...