After rendering one of my old laptops into OS-less state by restoring the Arch Linux OS from another System without exclude the boot, following is what I did to recover the dual-boot system. I have to fix the MBR and Boot for windows first and then reinstall the grub boot loader with linux live CD.
Fix Windows 7 MBR and Boot
Adapted from here.
-
Boot from the Windows 7 installation DVD. Note: The DVD with the same windows OS is needed. At the “Press any key to boot from CD or DVD…”, press any key to boot from the DVD Select a language Select a keyboard layout Click Next Select the operating system and click Next. The “Use recovery tools that can help fix problems starting Windows” must be checked when you select the operating system. At the System Recovery Options screen, click on Command Prompt
-
Command Prompt successfully loads, type this command:
123bootrec /rebuildbcd -
Press Enter Type the next command:
123bootrec /fixmbr -
Press Enter Type the next command:
123bootrec /fixboot - Press Enter Remove the installation DVD from the disk tray and restart your computer
Reinstall grub with Arch Linux Live Disc
Decrypt the root partition with LUKS Link
1 2 3 4 |
# cryptsetup open /dev/sdaX cryptroot # mount /dev/mapper/cryptroot /mnt |
1 2 3 |
# mount /dev/sdaY /mnt/boot |
Find and mount the boot partition. Note: it is a fat partition before, linux; NOT the MBR sda1.
1 2 3 |
mount /dev/sda3 /mnt/boot/ |
Arch and Grub Installation after chroot in.
-
chroot into the arch installation (from live CD).
123arch-chroot /mnt [/bin/bash] -
Install the bootloader – grub.
Install the packages grub and efibootmgr. GRUB is the bootloader, efibootmgr creates bootable .efi stub entries used by the GRUB installation script.
123pacman -S grub
Generate the main configuration file
-
Make sure all partitions are mounted, i.e. / /boot /boot/efi
123456789101112131415161718mount -alsblk----------------------------------------------------NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 477G 0 disk├─sda1 8:1 0 260M 0 part /boot/efi├─sda2 8:2 0 16M 0 part├─sda3 8:3 0 234.2G 0 part├─sda4 8:4 0 25G 0 part├─sda5 8:5 0 1000M 0 part├─sda6 8:6 0 20.2G 0 part├─sda7 8:7 0 1000M 0 part├─sda8 8:8 0 200M 0 part /boot├─sda9 8:9 0 8G 0 part [SWAP]└─sda10 8:10 0 187.1G 0 part└─cryptroot 254:0 0 187.1G 0 crypt / -
Intial Ramdisk Environment
123mkinitcpio -p linuxAdd the encrypt hook to mkinitcpio.conf: link here
1234etc/mkinitcpio.confHOOKS="... encrypt ... filesystems ..." -
retrieve the UUID, it is the crypto_LUK one.
1234567lsblk -fblkid #or─sda10 crypto_LUK 1de833a9-36b8-4bab-91d6-65360080e71c└─cryptrootext4 Arch Linux 63fbc4cb-fffd-488e-84fc-9b8ea8bf47f8 / -
update /etc/default/grub
12345GRUB_CMDLINE_LINUX_DEFAULT="i915.preliminary_hw_support=1"GRUB_ENABLE_CRYPTODISK=yGRUB_CMDLINE_LINUX="cryptdevice=UUID=1de833a9-36b8-4bab-91d6-65360080e71c:cryptroot root=/dev$ - install os-prober, only detect the correct Windows boot after boot into Linux, not from chroot with live CD.
-
configure grub
The following steps install the GRUB UEFI application to $esp/EFI/grub, install its modules to /boot/grub/x86_64-efi, and place the bootable grubx64.efi stub in $esp/EFI/grub.
First, tell GRUB to use UEFI, set the boot directory and set the bootloader ID. Mount the ESP partition to e.g. /boot or /boot/efi and in the following change $esp to that mount point (usually /boot):
123# grub-install --target=i386-pc --force /dev/sda3The –bootloader-id is what appears in the boot options to identify the GRUB EFI boot option; make sure this is something you will recognize later. The install will create a directory of the same name under $esp/EFI/ where the EFI binary bootloader will be placed.
123grub-mkconfig -o /boot/grub/grub.cfg #Generate initial grub config.Now, let’s add Windows to the GRUB menu. Edit /boot/efi/EFI/grub/grub.cfg and add the following menuentry after the Arch Linux menuentries [Note: grub boot loader does not locate Windows OS, but this is necessary for grub to load Arch Linux in my case. After I boot into arch linux, I ran sudo os-prober and update grub config.] See here for details.
123456789101112if [ "${grub_platform}" == "efi" ]; thenmenuentry "Microsoft Windows Vista/7/8/10 UEFI-GPT" {insmod part_gptinsmod fatinsmod search_fs_uuidinsmod chainsearch --fs-uuid --set=root $hints_string $fs_uuidchainloader /EFI/Microsoft/Boot/bootmgfw.efi}fiand update the string with following output:
$latex hints_string with the output of $ grub-probe –target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi $latex fs_uuid with the output of $ grub-probe –target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi
-
Unmount and Reboot
12345exitumount -R /mntreboot -
Reboot into Arch Linux
Done! Hopefully you can choose between Windows and Arch Linux at the start. If not, just go back in with live CD and tweak more.
DEC
About the Author:
Beyond 8 hours - Computer, Sports, Family...