Manual operations are always a bit nerve - wracking. Mistakes always accompany us often. So, to avoid losses, we need to back up the hard disk partition table to another disk, or it's better to back it up to a USB flash drive. Backing up to a floppy disk is also possible, but it's not very reliable because the floppy disks I've experienced all have a short lifespan. Some floppy disks can be written to, but when you try to read them, they fail. Or they can be read today but not tomorrow, making you shed tears.
After backing up your partition table, you may be relatively at ease, but not 100% at ease because the dd command itself is very dangerous.
When using the dd command, if you forget to type the "count=" parameter, in some cases, it will destroy the entire hard disk, and of course, you won't be able to recover it because it erases all the data on the entire hard disk, not just the partition table. Especially when the input file specified by the if= parameter is a device, the danger is the greatest. For example, if=/dev/zero or if=/dev/hdc, etc.
So, I oppose using the dd command. Even if you are careful, I oppose it because this command is extremely simple to use, giving people the impression that it's very good, and this is likely to induce those who are not proficient in LINUX to try to use this command. It's happy if used well, but a disaster if used badly.
Well, assume you have backed up your partition table to the USB flash drive; otherwise, you may not be able to sleep at ease. Now it's time to start the risky operation.
-----------------------------------------------------------------------------------------------------------------------------------------------
First, read the "Microsoft's disk signature" and the "hard disk partition table", that is, the last 72 bytes of the first sector of the first hard disk:
dd if=/dev/hda of=my_heart bs=1 count=72 skip=440
bs=1 means calculating in bytes.
count=72 means copying 72 units of length to the destination.
skip=440 means skipping the first 440 units of the source input file.
Therefore, what is to be copied is the 72 bytes from the 441st to the 512th byte.
After the command is completed, use
hexedit my_heart
to see if the file content is correct.
Second, read the first 440 bytes at the beginning of GRLDR:
dd if=grldr of=new_mbr_code bs=1 count=440
Third, read the 2nd to 5th sectors at the beginning of GRLDR:
dd if=grldr of=sector_2_to_5 bs=512 count=4 skip=1
Fourth, concatenate the above three files into one file:
cat new_mbr_code my_heart sector_2_to_5 > my_dangerous_mbr_5_sectors
Use ls -l to list the length of my_dangerous_mbr_5_sectors and see if it is correctly 2560 bytes, and then use hexedit to check and confirm that the file format is correct.
Fifth, all the above are writing to temporary files, and now it's really dangerous! To write to the MBR, the consequences are at your own risk! Don't say you regret it later (especially don't say it's my fault)!
You need to confirm again that /dev/hda is indeed where your MBR is stored! If you mistakenly write to another disk, then you have committed involuntary manslaughter, innocently destroying other disks!
In some machines, the MBR is on /dev/sda or on other devices, so this must be clarified! If there is any ambiguity, then stop here and don't continue!
dd if=my_dangerous_mbr_5_sectors of=/dev/hda bs=512 count=5
Sixth, you don't know yet if you have killed the disk. While the machine is still alive, you need to confirm what you just did:
dd if=/dev/hda of=mbr_just_written bs=512 count=5
You use hexedit to see if mbr_just_written is normal. If there is an error, you still have a chance to make amends.
Seventh, you need to run the fdisk -l /dev/hda command to see if your partitions are still there. If there is an anomaly, you know it's caused by what you did, so this is not a time for you to sleep. You'd better operate more large software to see if there are problems, and then feel at ease.
Eighth, it's not too important, but to avoid the machine crashing at startup, check if the GRLDR file is located in the root directory of a primary partition, and the primary partition should be a Microsoft - formatted partition, not a Linux - formatted partition (because currently there is no support for Linux - formatted partitions).
Ninth, you've done all the bad things, and life or death depends on this! By the way, see if your USB flash drive is still there. Restart the machine and see if the GRLDR boot is normal.
After the above operations, if you suffer from insomnia,多梦 and other diseases in the future, it's all normal.
In addition to the above - mentioned limitations, GRLDR has no other limitations. Even if you write the MBR first and then put GRLDR in the root directory of a primary partition, it's also okay. The MBR doesn't contain the location information of the GRLDR file. It finds GRLDR by searching all four primary partitions, and the search process is dynamic. After the MBR takes control, it starts to search for GRLDR.
因为我们亲手创建,这个世界更加美丽。