Experiment 2: MBR sector fault simulation and repair
1. Add a hard disk to store backup
2. Partition formatting
1>fdisk /dev/sdb--->n-->p-->1--> Enter several times to jump out -->w
2>mkfs.ext3 /dev/sdb1
3.mkdir /wang to create a mount point
4. Mount /dev/sdb1 /wang to mount the partition so that the hard disk can store backups.
5.dd if=/dev/sda of=/wang/sda.mbr.bak ( optional name ) bs=512count=1
Backup MBR , 512 bytes
6.dd if=/dev/zero of=/dev/sda bs=512count=1 After simulating the failure, restart the system
7. The system cannot be entered normally, after booting (make sure the system disk is placed in the CD-ROM), enter the menu,
Select Rescueinstalled system to enter rescue mode
8. Enter the text interface after a series of settings
mkdir /tmpdir
mount /dev/sdb1 /tmpdir
ddif=/tmpdir/sda.mbr.bak of=/dev/sda bs=512 count=1
After exit select the restart option
Experimental steps:
[root@a ~]# fdisk –l // View disk devices
[root@a ~]# fdisk /dev/sdb // Partition the newly added hard disk
[root@a ~]# cat /proc/partitions // Check whether the kernel recognizes the partitioned hard disk, if not, refresh
major minor #blocksname
8 0 20971520 sda
8 1 524288 sda1
8 2 18349056 sda2
8 3 2097152 sda3
81610485760 sdb
8 17 5242880 sdb1 // to identify
1108491008 sr0
[root@a ~]# mke2fs -t ext4 /dev/sdb1 // Format the partition and write it to the file system.
[root@a ~]# mkdir /wang // Create a directory under the root as a mount point
[root@a ~]# mount /dev/sdb1 /wang // Mount the hard disk to the created wang directory
[root@a ~]# df –h // Check whether the mount is successful,
[root@a ~]# dd if=/dev/sdaof=/wang/sda.mbr.bak bs=512 count=1 // Backup to, new hard disk
1+0 reads are recorded
Recorded the write out of 1+0
512 bytes (512 B) copied, 0.000556432 sec, 920 kB/ sec
[root@a ~]# ls /wang/
lost+found/ sda.mbr.bak // View , it has been backed up
[root@a ~]# dd if=/dev/zero of=/dev/sdabs=512 count=1 // Destroy the entire MBR
1+0 reads are recorded
Recorded the write out of 1+0
512 bytes (512 B) copied, 0.000589937 sec, 868 kB/ sec
Restart, can't enter the system
Enter rescue mode and copy the backup back.
mkdir /tmpdir // create mount point
mount /dev/sdb1 /tmpdir // mount
ddif=/tmpdir/sda.mbr.bak of=/dev/sda bs=512 count=1 // copy back
After exit select the restart option