[INFO] Crypted broken system, restored with chroot and timeshift

A place to share tips, guides, application configurations and scripts about all elements of ArcoLinux, all of your personal configurations to make ArcoLinux awesome
Post Reply
Mithrandir
Crewman
Posts: 6
Joined: Sun Sep 03, 2023 4:53 pm

Hi, during a kernel update my battery unexpectedly dropped out and the update didn't complete. Because of this, I was unable to reboot the system.
The startup error was as follows:

Code: Select all

Loading Linux linux-lts ...
error: file '/boot/vmlinuz-linux-lts' not found.
Loading initial ramdisk ...
error: you need to load the kernel first

Press any key to continue
Even though I have never used chroot, I followed the Arcolinux guides to use arch-chroot, and then to issue the command:

Code: Select all

$ pacman -S linux-lts
Unfortunately this command said that everything was already installed and gave an error, and it didn't reconfigure the system.
Furthermore, the # mkinitcpio -P command, sometimes suggested to reconfigure the system, said that it did not find the /boot/vmlinuz-linux-lts image.

I have a system encrypted with LUKS, dual booted with Windows. I didn't want to reinstall and absolutely had to fix the problem. I solved it as follows, using a live image of ArcolinuxL and timeshift.

Once you have started a live USB of Arcolinux, open the terminal and set your keyboard:

Code: Select all

$ setxkbmap it
instead of 'it' everyone can put the identification code of their keyboard.
Then you list the existing disks and partitions:

Code: Select all

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0         7:0    0   2.4G  1 loop /run/archiso/airootfs
sda           8:0    1   3.8G  0 disk 
├─sda1        8:1    1   2.5G  0 part /run/archiso/bootmnt
└─sda2        8:2    1    15M  0 part 
sdb           8:16   1     0B  0 disk 
nvme0n1     259:0    0 476.9G  0 disk 
├─nvme0n1p1 259:1    0   100M  0 part 
├─nvme0n1p2 259:2    0    16M  0 part 
├─nvme0n1p3 259:3    0 183.3G  0 part 
└─nvme0n1p4 259:4    0 293.5G  0 part 
and identify the encrypted partition:

Code: Select all

$ lsblk -lf | grep LUKS
nvme0n1p4 crypto_LUKS 1                                     db33046b-75b2-4c2f-94e6-1d9b4c1bf252  
The different types of partition are identified as follow:

Code: Select all

$ sudo fdisk -l
Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: WDC PC SN720 SDAQNTW-512G-1001          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 5E9B4EC5-42C5-4AF5-914F-84BB48536F81

Device             Start        End   Sectors   Size Type
/dev/nvme0n1p1      2048     206847    204800   100M EFI System
/dev/nvme0n1p2    206848     239615     32768    16M Microsoft reserved
/dev/nvme0n1p3    239616  384718230 384478615 183.3G Microsoft basic data
/dev/nvme0n1p4 384718231 1000215182 615496952 293.5G Linux filesystem


Disk /dev/sda: 3.77 GiB, 4048551936 bytes, 7907328 sectors
Disk model: Transcend 4GB   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5e5ace90

Device     Boot   Start     End Sectors  Size Id Type
/dev/sda1  *         64 5255039 5254976  2.5G  0 Empty
/dev/sda2       5255040 5285759   30720   15M ef EFI (FAT-12/16/32)


Disk /dev/loop0: 2.38 GiB, 2550525952 bytes, 4981496 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
So the EFI partition is in:

Code: Select all

/dev/nvme0n1p1      2048     206847    204800   100M EFI System
and the encrypted linux partition is in:

Code: Select all

/dev/nvme0n1p4 384718231 1000215182 615496952 293.5G Linux filesystem
Decrypt the Linux partition:

Code: Select all

$ sudo cryptsetup luksOpen /dev/nvme0n1p4 arcolinuxrestore
Enter passphrase for /dev/nvme0n1p4:
Mount the Linux system partition:

Code: Select all

$ sudo su -
# mount /dev/mapper/arcolinuxrestore /mnt
Mount EFI partition:

Code: Select all

# mount /dev/nvme0n1p1 /mnt/boot/efi
Unfortunately, the arch-chroot command, although very convenient, does not mount all the elements necessary for timeshift to work, so it is necessary to manually mount everything needed as indicated in the Archlinux guides:

Code: Select all

# cd /mnt
# mount -t proc /proc proc/
# mount -t sysfs /sys sys/
# mount --rbind /dev dev/
# mount --rbind /run run/
# mount --rbind /sys/firmware/efi/efivars sys/firmware/efi/efivars/
It's possible now change root:

Code: Select all

# chroot /mnt /bin/bash
[root@ArcolinuxL /#
Now let's restore one of the timeshift images of our system:

Code: Select all

[root@ArcoLinuxL /]# timeshift --restore
Mounted '/dev/dm-0 (nvme0n1p4)' at '/run/timeshift/8585/backup'

Select snapshot:

Num     Name                 Tags  Description  
------------------------------------------------------------------------------
0    >  2023-10-02_00-00-01  M                  
1    >  2023-10-16_13-00-01  W                  
2    >  2023-10-19_16-00-01  D                  
3    >  2023-10-20_16-00-02  D                  

Enter snapshot number (a=Abort, p=Previous, n=Next): 
We select now number 3 snapshot:

Code: Select all

Enter snapshot number (a=Abort, p=Previous, n=Next): 3



******************************************************************************
To restore with default options, press the ENTER key for all prompts!
******************************************************************************

Press ENTER to continue...
And now the system ask for reinstalling grub

Code: Select all

Re-install GRUB2 bootloader? (recommended) (y/n): 
Type 'y' and write the path to the EFI partition --> /dev/nvme0n1p1

Code: Select all

Re-install GRUB2 bootloader? (recommended) (y/n): y

Select GRUB device:

Num     Device     Description                            
------------------------------------------------------------------------------
0    >  sda        JetFlash Transcend 4GB [MBR]           
1    >  sdb        Generic- SD/MMC [MBR]                  
2    >  nvme0n1     WDC PC SN720 SDAQNTW-512G-1001 [MBR]  
3    >  nvme0n1p4   luks, 315.1 GB GB                     

[ENTER = Default (/dev/nvme0n1), a = Abort]

Enter device name or number (a=Abort): /dev/nvme0n1p1
So the system show the disclaimer:

Code: Select all

******************************************************************************
GRUB Device: /dev/nvme0n1p1
******************************************************************************

======================================================================
WARNING
======================================================================
Data will be modified on following devices:

Device                 Mount    
---------------------  ---------
/dev/dm-0 (nvme0n1p4)  /        
/dev/nvme0n1p1         /boot/efi


Please save your work and close all applications.
System will reboot after files are restored.

======================================================================
DISCLAIMER
======================================================================
This software comes without absolutely NO warranty and the author takes no responsibility for any damage arising from the use of this program. If these terms are not acceptable to you, please do not proceed beyond this point!

Continue with restore? (y/n): 
Type 'y', wait for the process to finish, reboot and enjoy your restored system.

Cheers :D
User avatar
erikdubois
Captain
Posts: 5950
Joined: Tue Nov 07, 2017 3:45 pm
Location: Belgium
Contact:

This seems more to be a [INFO] post

Am I right?
Learn, have fun and enjoy.
But first use the power of the Arch Wiki
use the tutorials on https://www.youtube.com/erikdubois
then use the power of google
then use the power of our moderators.
Mithrandir
Crewman
Posts: 6
Joined: Sun Sep 03, 2023 4:53 pm

The idea was to make a guide, to share the result of my efforts, because I had to redo all the steps at least 3-4 times before I managed to do everything correctly. But if you think it's more information, you can move the post to another section
Last edited by Mithrandir on Mon Oct 23, 2023 8:08 am, edited 1 time in total.
User avatar
erikdubois
Captain
Posts: 5950
Joined: Tue Nov 07, 2017 3:45 pm
Location: Belgium
Contact:

It is fine here

Let me change it into [INFO]
Learn, have fun and enjoy.
But first use the power of the Arch Wiki
use the tutorials on https://www.youtube.com/erikdubois
then use the power of google
then use the power of our moderators.
Post Reply

Return to “Configs, Scripts”