It was a late night, and I did a full system update. Either it failed during update or whatever … as I said it is late and I am tired… The system won’t boot into Linux the next morning
The reason was …
As I suspected, the kernal is corrupted.
rollback the kernal from cache:
1 2 |
pacman -U /var/cache/pacman/pkg/linux*4.10.13* #3 file including header |
I could’ve updated the grub config and fix the loader, but I panic; and I did not know. so, I took the hard way.
Restore the system
Back up the partition
- Boot from a live media.
- Make sure no partitions are mounted from the source hard drive.
- Mount the external HD
- Backup the drive.
1 2 |
# dd if=/dev/sdX conv=sync,noerror <status=progress> bs=64K | gzip -c > /path/to/backup.img.gz |
Reinstall the arch with steps here.
Rsync and restore the system
-
decrypt and read img file with info here.
123456789101112gunzip -k image.img.gz # unzip and keep originalecho "Mounting image file...";sudo losetup -D;sudo losetup /dev/loop0 $FILENAME;echo "Decrypting image file...";sudo cryptsetup luksOpen /dev/loop0 encrypted;echo "Mounting encrypted volume...";sudo mount /dev/mapper/encrypted /mnt/encrypted;vim -i NONE -c 'set noswapfile' -c 'set nobackup' -c 'set noundofile' --cmd 'set undodir=/dev/null' /mnt/encrypted/; -
Restore files
12# rsync -aAXv --exclude={"/boot/*","/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /from/encrypted/source /Note: Rename these files and folder in backup image: /etc/fstab , /grub/grub.cfg , /etc/mkinitcpio.d mkinitcpio.conf
-
Unmount and clean up
123456789echo "Unmounting encrypted volume...";sudo umount /mnt/encrypted;echo "Closing encrypted volume...";sudo cryptsetup luksClose /dev/mapper/encrypted;echo "Unmounting image file...";sudo losetup -D; - If needed, fix after boot and then chroot into live media.
Access the image file from Arch Linux System
1 2 3 4 5 6 |
sudo losetup -D; sudo losetup /dev/loop0 /run/media/tan/My\ Passport/arch-backup.img tan@sagittarius ~$ sudo cryptsetup open /dev/loop0 encrypted Enter passphrase for /dev/loop0: tan@sagittarius ~$ sudo mount /dev/mapper/encrypted ./encrypted |
Note: (from here.) Note: If it gives you the error /dev/loop0: No such file or directory, you need to first load the kernel module with modprobe loop. These days (Kernel 3.2) loop devices are created on demand. Ask for a new loop device with # losetup -f.
Reinstall Grub after motherboard replacement (or hdd upgrade)
Prepare Arch Linux Live Disc
- Make a bootable installation media for Arch Linux
-
This laptop doesn’t have any CD/DVD drive so the first thing is to make a bootable USB drive.
Boot into Windows 10. In Windows, download archlinux iso from the following website
https://www.archlinux.org/download/
Use the mirror which is closest to you and download the Arch iso. archlinux-2015.12.01-dual.iso
Download Rufus from the following location https://rufus.akeo.ie/
Plugin any usb drive/pendrive in your usb port. Make sure that you backup data from this usb drive
- Attach it to your computer
Turn off Windows fast boot and secure boot, if not already [NOT needed to HDD upgrade]
- Shutdown Windows after disabling fast start following instruction here or here. And use the command shutdown -s -t 0 to do so.
-
Restart windows by clicking on Power -> Restart. Make sure that when hitting restart, you are press down Shift key Windows will give you options for Troubleshoot/Adanced Options/UEFI Firmware/
-
Once you restart your machine you should be able to see the BIOS settings.
Under Configuration you should disable Intel Fast boot, disable SecureBoot (more here). Make sure you change the settings for Graphics from Switchable to Internal. This is needed only to install, you can then modify it later. Save the changes and exit.
-
-
Once the machine restarts press and hold F12 key.
This will give you option to boot from various available devices and your USB drive would be one of them
- Select your USB drive to boot
-
Select the UEFI boot mode when you see the ArchLinux boot screen.
Once the usb has booted you will see the root prompt.
Connect to the internet (Wi-Fi), if you need to update or install some packages in chroot session
1 2 3 4 5 |
rfkill unblock wifi # I need to do this for Lenovo Ideapad $ iw dev # Get the interface name $ wifi-menu <wifi_interface_name> ping google.com # check internet |
Decrypt the root partition with LUKS Link
1 2 3 |
# cryptsetup open /dev/sdaX cryptroot # mount /dev/mapper/cryptroot /mnt |
where /dev/sdX is the disk (not a partition) where GRUB is to be installed. For example /dev/sda or /dev/nvme0n1, or /dev/mmcblk0
1 2 |
# mount /dev/sdaY /mnt/boot |
Find and mount the efi partition to /mnt/boot/efi
1 2 |
mount /dev/sda1 /mnt/boot/efi |
Arch and Grub Installation after chroot in.
-
chroot into the arch installation (from live CD).
12arch-chroot /mnt [/bin/bash] -
Install the bootloader – grub.
Note: This step should NOT be necessary.
Install the packages grub and efibootmgr. GRUB is the bootloader, efibootmgr creates bootable .efi stub entries used by the GRUB installation script.
12pacman -S grub
Generate the main configuration file
-
Make sure all partitions are mounted, i.e. / /boot /boot/efi
1234567891011121314151617mount -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 /
123456789101112131415nvme0n1 259:0 0 953.9G 0 disk├─nvme0n1p1 259:1 0 260M 0 part /boot/efi├─nvme0n1p2 259:2 0 16M 0 part├─nvme0n1p3 259:3 0 234.2G 0 part├─nvme0n1p4 259:4 0 25G 0 part├─nvme0n1p5 259:5 0 1000M 0 part├─nvme0n1p6 259:6 0 20.2G 0 part├─nvme0n1p7 259:7 0 1000M 0 part├─nvme0n1p8 259:8 0 200M 0 part /boot├─nvme0n1p9 259:9 0 8G 0 part [SWAP]├─nvme0n1p10 259:10 0 187.1G 0 part│ └─cryptroot 254:0 0 187.1G 0 crypt /└─nvme0n1p11 259:11 0 477G 0 part└─home-crypt 254:1 0 476.9G 0 crypt /home -
Intial Ramdisk Environment
12mkinitcpio -p linuxNote: Step 2-4 can be omitted, it does not hurt though. You can jump to step 5 configure grub.
Add the encrypt hook to mkinitcpio.conf: link here.
123etc/mkinitcpio.confHOOKS="... encrypt ... filesystems ..." -
update /etc/default/grub
1234GRUB_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):
12# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grubThe section assumes you are installing GRUB for x86_64 systems. For IA32 (32-bit) UEFI systems (not to be confused with 32-bit CPUs), replace x86_64-efi with i386-efi where appropriate.
The –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.
12grub-mkconfig -o /boot/grub/grub.cfg #Generate initial grub config.Now, let’s add Windows to the GRUB menu. Edit /boot/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.
1234567891011if [ "${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:
$hints_string with the output of $ grub-probe --target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi. $fs_uuid with the output of $ grub-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi.
- Unmount and Reboot
1 2 3 4 |
exit umount -R /mnt reboot |
- Reboot into Arch Linux
-
Install os-prober. Regenerate grub configuration. Reboot.
123456pacman -Syu os-probersudo os-prober#/dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi:Windows Boot Manager:Windows:efigrub-mkconfig -o /boot/grub/grub.cfg #OR following is bettergrub-customizerDone! Now you can choose between Windows and Arch Linux at the start. Yay!
Recovery bootloader for a dual boot system of Windows 7 and Arch Linux
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 (also works for Windows 10)
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:
12bootrec /rebuildbcd -
Press Enter Type the next command:
12bootrec /fixmbr -
Press Enter Type the next command:
12bootrec /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 |
# cryptsetup open /dev/sdaX cryptroot # mount /dev/mapper/cryptroot /mnt |
1 2 |
# 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 |
mount /dev/sda3 /mnt/boot/ |
Arch and Grub Installation after chroot in.
-
chroot into the arch installation (from live CD).
12arch-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.
12pacman -S grub
Generate the main configuration file
-
Make sure all partitions are mounted, i.e. / /boot /boot/efi
1234567891011121314151617mount -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
12mkinitcpio -p linuxAdd the encrypt hook to mkinitcpio.conf: link here
123etc/mkinitcpio.confHOOKS="... encrypt ... filesystems ..." -
retrieve the UUID, it is the crypto_LUK one.
123456lsblk -fblkid #or─sda10 crypto_LUK 1de833a9-36b8-4bab-91d6-65360080e71c└─cryptrootext4 Arch Linux 63fbc4cb-fffd-488e-84fc-9b8ea8bf47f8 / -
update /etc/default/grub
1234GRUB_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):
12# 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.
12grub-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.
1234567891011if [ "${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
1234exitumount -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.
MAY
About the Author:
Beyond 8 hours - Computer, Sports, Family...