backup partition table
The partition table is very important, it is recommended to backup the partition table in the production environment
Let's take a look at the partition table we want to backup first hexdump -C /dev/sda -n 512
We only backup the first 512 bytes
Backup the partition table dd if=/dev/sda of=/data/mbr_bak bs=1 count=512 Back up the partition table of sda to mbr_bak of /data/
The backup file cannot be saved in the local machine, because the partition table is damaged and the machine cannot get up, and the backup file cannot be restored in the local machine.
So the partition table backup file should exist in a relatively safe place, where we copy the backup file to centos7
Simulate the destruction of the partition table
Use the dd command to overwrite the data in the partition table with 0 devices
At this point the partition table has been destroyed by us
restore partition table
1. The machine did not restart
Use fdisk -l and lsblk commands to view partition information
At this time, we can see that there is a partition table in the memory (we destroy the partition table on the hard disk). If the partition table is found to be damaged in time, the machine does not restart; we can directly restore it with the files we backed up.
Use the dd command to overwrite the first 512 bytes of the data we backed up
Check that the partition table has been restored
2. The machine has been restarted
After the partition table is damaged, the machine cannot be restarted, and the recovery is performed below
In the BIOS, set the first boot item to CD-ROM
The boot item is set to CD-ROM boot, select item 3, enter rescue mode
Enable network optionYes
This option Skip
Enter rescue mode, first check the IP address, and ping to see if it can connect to the remote host where the partition table backup file is stored
Use the scp command to copy the partition table backup file on the remote host to the local
Use the dd command to restore
reboot after recovery
Set the first startup item as the hard disk
The system is started, and then check the partition table information
Partition table restored
If there is no network on the server where the backup files are stored, remove the hard disk with the lost data and install it on the machine where the backup partition table is restored.
Note: If the size is the same and the partition strategy is the same, you can use the same partition table to restore
Partition table clone
fdisk -l can check that sda is more than 200 GB; sdb is more than 60 GB
Write sda data to sdb
The end position of sdb4 is wrong, the total capacity is not that big
sdb4 is not displayed because the partition start record of sdb4 is wrong
Note: Two hard disks can achieve partition table cloning, the premise: the second hard disk is larger than the first hard disk or has the same capacity
Only primary partitions can be cloned, but logical partitions cannot be cloned. Because the information of the logical partition is placed in the EBR, and the EBR is in the extended partition, it is not placed in the first MBR
delete flag
Take sdb hard disk as an example
Check first if there is an identifier
clear flag
Check the partition table, the flag is 0
lsblk checks and finds that there are no partitions; we can also use this method to delete hard disk partitions
There are gaps in the partition space