How to restore the master boot record (MBR) in Linux

The Master Boot Record (MBR) is an essential part of your disk that contains information necessary to boot your operating system. It stores the bootloader, like GRUB, which allows your system to start up. If the MBR becomes corrupted or is overwritten, your system might fail to boot. Knowing how to restore the MBR from a backup is critical to ensuring the system can function again.

Tools like dd in Linux can help restore the MBR, provided you have a valid backup. Restoring the MBR requires using a Live USB or installation media, such as an Ubuntu disk, to access the unbootable system. Identifying the correct disk and verifying the backup are important steps to avoid further damage.

Once the MBR is successfully restored, the bootloader will resume its function, allowing the system to boot normally. Using the correct procedure minimizes the risk of data loss and ensures the system returns to a bootable state.

Related: How to back up Master Boot Record (MBR) in Linux
Related: How to recover GRUB bootloader in Linux

Steps to restore MBR from a backup in Linux:

  1. Boot from a Live CD or USB to access your unbootable Linux system.

  2. Open the terminal.

  3. Verify the correctness of your MBR backup file.
    $ file mbr.bak 
    mbr.bak: DOS executable (COM)
    $ cat mbr.bak 
    �c������t��pt���y|1��؎м ��d|<�t��R��t��}��|�A��U�ZRr=��U�u7��t21��D@�D��D�f�\|f�f�`|f�\
    Z������}�f�ƈd�@f�D�������@�����f�f�`|f	�uNf�\|f1�f�4��1�f�t;}7����0�����Z�ƻp��1۸�r��`���1�������a�&Z|��}���}�4��}�.���GRUB GeomHard DiskRead Error
    ����<u��
  4. Identify the disk with the damaged MBR from disk listing.
    $ lsblk
    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    loop0    7:0    0  55.4M  1 loop /snap/core18/1932
    loop1    7:1    0  55.4M  1 loop /snap/core18/1944
    loop2    7:2    0 217.9M  1 loop /snap/gnome-3-34-1804/60
    loop3    7:3    0   219M  1 loop /snap/gnome-3-34-1804/66
    loop4    7:4    0    51M  1 loop /snap/snap-store/498
    loop5    7:5    0  62.1M  1 loop /snap/gtk-common-themes/1506
    loop6    7:6    0    51M  1 loop /snap/snap-store/518
    loop7    7:7    0  64.8M  1 loop /snap/gtk-common-themes/1514
    loop8    7:8    0  31.1M  1 loop /snap/snapd/10492
    loop9    7:9    0  31.1M  1 loop /snap/snapd/10707
    sda      8:0    0    20G  0 disk 
    ├─sda1   8:1    0     1M  0 part 
    ├─sda2   8:2    0   513M  0 part /boot/efi
    └─sda3   8:3    0  19.5G  0 part /
    sr0     11:0    1  1024M  0 rom
  5. Restore the MBR using dd to write from the backup file.
    $ sudo dd if=mbr.bak of=/dev/sda
    [sudo] password for user: 
    0+1 records in
    0+1 records out
    446 bytes copied, 0.00284831 s, 157 kB/s
  6. Verify that the MBR was restored successfully.
    $ sudo head -c 446 /dev/sda
    �c������t��pt���y|1��؎м ��d|<�t��R��t��}��|�A��U�ZRr=��U�u7��t21��D@�D��D�f�\|f�f�`|f�\
    Z������}�f�ƈd�@f�D�������@�����f�f�`|f	�uNf�\|f1�f�4��1�f�t;}7����0�����Z�ƻp��1۸�r��`���1�������a�&Z|��}���}�4��}�.���GRUB GeomHard DiskRead Error
    ����<u��
  7. Restart the system to check if it boots correctly.

Keep regular backups of your MBR to avoid boot failures in the future.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值