Programmers may lose data due to misoperations. if they are busy with projects for a week, they will be overwhelmed. The boss's criticism and the manager's reprimand were followed. The next step is not having to take a break, work overtime, or even leave the damn computer in the early hours of the morning. do you have a sense of wanting to die? For those that do not like tags: Data Recovery
Programmers may lose data due to misoperations. if they are busy with projects for a week, they will be overwhelmed. The boss's criticism and the manager's reprimand were followed. The next step is not having to take a break, work overtime, or even leave the damn computer in the early hours of the morning. do you have a sense of wanting to die?
We are here to talk about data recovery to those who do not like data backup. here we will teach you how to use simple tools to restore deleted data.
Tools: hexedit and fdisk
The following operations are completed in the root environment.
Hexedit:
In linux, hexedit is often used to modify the hexadecimal code of a program. Fdisk is not described here.
Now let's go into the disk world and see what the disk has done to the data.
First, use the root permission on the terminal to run the following command:
Command: fdisk-l
/Dev/sdb1 is the main character of today. we can clearly see some related data from the image, such as the disk size, sector, and I/O size.
The disk format is ext4, not the vfat32 and NTFS formats on MS, and the FAT32 image is pasted at the end of the article.
Step 1:
Run fdisk to back up the Partition table in expert mode.
The partition table of ext4 is very simple. Generally, the backup partition table is ext4.img. Backup is used to prevent data from being damaged.
Step 2:
First, run the cut command on target sdb1 to move the files on sdb1 to the hard disk of the computer. Then, use hexedit to open sdb1.
Cut File name: usb.png
Command: hexedit-s/dev/sdb1
In the image, we can see the file name and the sector where it is located. have you found that the image device is sdc1? Because the automatic attaching of a disk changes dev, the data does not change with the dev of the disk. The file name is found here. Next, you need to find the file header.
How to find the file header? You can use hexedit to perform hex search. if you want ASCII, you can press TAB to switch to the ASCII area.
The file size determines the number of sector S occupied by the file on the disk. 1 sector = 512 bytes. In the figure, the file header offset and sector are displayed.
Extract the hex value and write it to the file.
Restored image:
It looks very simple, it is just a single file cut operation and data recovery. Here, we would like to remind you that the data stored in the disk can be restored without deletion, and the data that has been cut out can be recovered.
Next, let's take a look at how to operate the data deleted from the disk?
Run the deletecommand on the "images" page to delete a file named 1.gif. the operations are as follows:
The image shows the changes from the file header to the end sector. The header sector: 264056, end sector: 264057, the file size is 1 K, and the image is very small.
Create a new file and then perform the delete operation to check disk data changes.
File header sector: 264056, end sector: 264061, the first file header sector: 264056, end sector: 264057 to be deleted. This shows that the data deleted for the first time is overwritten, the second deleted data is retained.
The operation here is to recover the data of a single disk file and demonstrate the data changes on the disk. Next, let's take a look at the operations on dual files.
Two different types of files exist in the disk.
File name: partition.zip
File name: cab. ico
Header secotor of the first file: 264056, end sector: 264058
The second file header sector: 264064, end sector: 264076. The end sector of the first file differs from the header sector of the second file by multiple sector. what is the difference between the end sector and the header sector of the second file?
We can see that all the difference values in the middle are filled with 00. Here we will summarize the practical operations on linux:
Ext4 file system
Execute the clipboard
File name: usb.png sector 67120
File header: sector 264064 file end: sector 264076
Delete
File name: 1.gif sector 67112 (overwrite)
File header: start: sector 264056 end: sector 264057 (overwrite)
File name: 56.jpg sector 67112
File header: start: sector 264056 end: sector 264061
When a single file is deleted, the last deleted data is overwritten.
Store files
(1) file name: partition.zip sector 67112
File header: start sector 264056 end sector 264058
(2) file name: cab. ico sector 67112
File header: start sector 264064 end sector: 264068
Cut Area: sector 264064
Delete area: sector 264056
Storage Zone: coexistence with the deletion zone
Storage Area: when a single file is stored, the stored file overwrites the data in the deleted area.
Data recovery: when multiple files are deleted, the delete partition retains the data hex. if the data of the new file is created, the deleted data hex is overwritten.
Figure:
FAT32 disk format: