Tag: Linux boot

UEFI does not see installed Linux (SOLVED)

How to add a new boot option to UEFI

UEFI usually automatically detects operating system loaders on media connected to a computer. But sometimes UEFI does not show all available options. Let's see how to add a new option to the UEFI boot menu.

For example, I plugged a flash drive with two operating systems – Windows 11 and Kali Linux – into my computer USB port, pressed ESC during boot to select boot options. The screenshot shows two options:

  • Linux OS on internal drive
  • Windows OS on a flash drive

If I select the first option, then it will boot from the internal disk, if the second, then Windows will boot. There is no way to boot Kali Linux from a flash drive.

Go to UEFI settings.

To come to the advanced UEFI settings, on my laptop I use the F7 key.

Go to the “Boot” tab.

As you can see, two boot options are selected and I can add additional ones – both from the drop-down list and new ones that are not in the list.

Among the options available in the drop-down list, there is no Kali Linux from a flash drive.

I select “Add New Boot Option”.

In the “Path for boot option” field, I need to specify the path to the /EFI/kali/grubx64.efi file.

I select a USB flash drive (there is a line “USB” in the path).

Select the “EFI” folder.

Select the “kali” folder.

Select the “grubx64.efi” file.

In the “Add boot option” field, I enter a name for this boot option and click the “Create” button.

The new boot option has been successfully created.

I add this option to the boot menu.

I save the settings made and restart the computer.

The option to boot “Kali” from a flash drive is now available.

The Linux bootloader is aware of the existence of Windows 11 installed and adds the ability to boot it into its menu.

When you select the “Windows Boot Manager” item, Windows 11 is booted from a USB flash drive.

When choosing to boot Kali Linux, you are required to enter a password for the encrypted partition on which the /home folder is located.

Further, work from a USB flash drive in Kali Linux continues as usual.

What to do if there are no settings for adding boot options in UEFI (BIOS)

UEFI varies from manufacturer to manufacturer: some have a lot of settings, some don't. It is possible that UEFI does not see the Linux bootloader and does not have the option to add a new item to the boot menu.

In this case, you can use a different approach. The essence of the method is that any UEFI by default tries to load the bootloader with the /EFI/BOOT/BOOTX64.EFI path. This is the so-called fallback path to the bootloader. Therefore, it is enough to rename the existing path to fallback for UEFI to start loading it.

For example, the path to the Kali Linux bootloader is /EFI/kali/grubx64.efi. In this case, you need to rename the “kali” folder to “BOOT” and the “grubx64.efi” file to “BOOTX64.EFI”.

These files are located on a hidden partition with the FAT32 file system.

Renaming files and folders on an EFI partition in Linux

To make these changes on Linux, mount the drive with read/write permissions and rename the directory and file.

Let's see the names of disks and partitions:

sudo fdisk -l

The partition with the EFI System on which we want to make changes is called /dev/sdb1, let’s mount it:

mkdir /tmp/efi
sudo mount /dev/sdb1 /tmp/efi

Now rename the folder and file sequentially.

sudo mv /tmp/efi/EFI/kali/ /tmp/efi/EFI/BOOT/
sudo mv /tmp/efi/EFI/BOOT/grubx64.efi /tmp/efi/EFI/BOOT/BOOTX64.EFI

When finished, unmount the /dev/sdb1 partition:

sudo umount /dev/sdb1

Renaming files and folders on an EFI partition in Windows

Open the Windows Command Prompt with administrator rights. To do this, press Win+x and select “Windows Terminal (Admin)”.

In the command line, run the program and wait for it to open:


At the DISKPART prompt, type:

list disk

We need to find out what number the boot disk has. In my case it is 0.

Now enter the following command, replacing 0 with the number of your boot disk:

sel disk 0

Now the following command will list the volumes:

list vol

This is a very important step! We need to find out what number the partition with EFI has. The EFI partition has a FAT32 file system and does not have a letter.

In my screenshot, the EFI volume is number 2.

Run the following command, replacing 2 with your partition number:

sel vol 2

Now this volume needs to be assigned a letter. It can be any unoccupied letter.

assign letter=V:



Close Command Prompt.

To edit the names of folders and files on the disk, administrator rights are required. To do this, for example, I run Double Commander with administrator rights.

See also: Free analogue of Total Commander

After that, you can edit the EFI partition like regular folders and files.

How to boot into VirtualBox from USB

In this post I will tell you how to connect a USB disk (or USB flash drive) to a virtual machine so that the guest system treats it like a regular hard disk.

This trick will allow you not only to boot from the installation USB – which is rather pointless. If you connect a USB disk or flash drive to the guest system as a regular disk, you can do such interesting things as:

  • boot from physical SATA disk via USB adapter
  • install Windows on a USB disk or flash drive

If you do not have the ability to connect a SATA disk directly to a computer – for example, to a laptop – but you really need to boot into the operating system that is deployed on it, then the trick described here will help you do this: plug the SATA disk to the computer via a USB adapter, and then connect the USB disk to the virtual machine as a regular disk, as shown in this guide.

Regarding the second point – installing Windows on a USB drive – if you want to install Linux on a USB flash drive (not to write a Live image, but to install a full-fledged system), then you do not have to do the trick shown here to install it – since Linux is perfectly installed on a portable media. But in Windows there is a prohibition for installation on USB disks and flash drives.

I will show you how to boot from USB on Windows and Linux. The principle is the same in both of these operating systems, but the commands differ slightly due to the specifics of the OS.

How to Boot into VirtualBox from USB on Windows

Plug a USB flash drive or disk to your computer. Then press Win+r and execute diskmgmt.msc.

Find your USB flash drive and remember the disk number:

For example, in my screenshot, the flash drive has the number 2.

Close all VirtualBox windows if they are open.

Next, we need to open a command prompt as administrator. To do this, press Win+x and select “Windows PowerShell (Admin)”.

Now go to the folder where you have VirtualBox installed. If this program is installed in the default directory, then the command to go:

cd $Env:programfiles\Oracle\VirtualBox

If you chose a different location for VirtualBox, then edit the previous command accordingly.

Now, in the command line, paste the following command, in which replace # with the disk number that we looked at just above, then press Enter:

.\VBoxManage internalcommands createrawvmdk -filename C:\usb.vmdk -rawdisk \\.\PhysicalDrive#

For example, I have this second disk, then the command looks like this:

.\VBoxManage internalcommands createrawvmdk -filename C:\usb.vmdk -rawdisk \\.\PhysicalDrive2

If everything went well, the following message should appear:

RAW host disk access VMDK file C:\usb.vmdk created successfully.

Note that you can replace C:\ usb.vmdk with any file location you want.

This command creates a virtual machine disk file (VMDK) pointing to the physical disk you selected. When you use a VMDK file as a disk in VirtualBox, then VirtualBox will actually have access to the physical disk.

Now open VirtualBox as administrator - this is a must, otherwise it will not work as it should. To do this, click the Start button, type in “VirtualBox” and select “Run as administrator”:

VirtualBox can only access raw disk devices with administrator privileges.

Now in VirtualBox create a new virtual machine, select the appropriate operating system and when it comes to choosing a hard disk, instead of creating a new one, select “Use an existing virtual hard disk file”:

Click “Add”:

Now open the file C:\usb.vmdk (or another one if you saved it in a different location or under a different name):

Choose it:

Press “Create” button:

Boot your virtual machine, now it should see your USB flash drive as an ordinary hard drive. That is, if it is a correctly written boot disk or USB flash drive, then the system will boot from it.

Please note that the USB device must be the first hard drive in your VirtualBox virtual machine, otherwise it will not boot. If you are connecting a new USB disk to an existing machine, then try changing the order of the media in the settings of this machine, or select the appropriate disk at the beginning of the boot.

How to Boot into VirtualBox from USB in Linux

To understand the principle, read the previous section on Windows.

To do without root rights in Linux, you need to add the user (yourself) to the “disk” group:

sudo usermod -a -G disk $USER

Then reboot.

If you do not add yourself to the “disk” group, then you will need to run VirtualBox as root or with sudo, otherwise you will encounter an error:

VD: error VERR_ACCESS_DENIED opening image file '/home/mial/VirtualBox VMs/usb.vmdk' (VERR_ACCESS_DENIED).

On Linux, to find out the name of the USB drive, run the command:

sudo fdisk -l

In my case, the disk name is /dev/sdb.

To create a virtual disk file pointing to a real disk, run a command like this:

VBoxManage internalcommands createrawvmdk -filename '~/VirtualBox VMs/usb.vmdk' -rawdisk /dev/sdX

Where, instead of X, write the letter of the corresponding drive. An example for my conditions:

sudo VBoxManage internalcommands createrawvmdk -filename '~/VirtualBox VMs/usb.vmdk' -rawdisk /dev/sdb

In this command, you can replace '~/VirtualBox VMs/usb.vmdk' with a different location of your choice.

Everything else – creating a virtual machine and choosing an existing virtual disk as a hard disk – just like in Windows.

Note that the usb.vmdk file is a simple text file that you can move to any location and even edit.

Instead of a name like /dev/sdX, you can use a by-id based persistent name, for example:

VBoxManage internalcommands createrawvmdk -filename flash.vmdk -rawdisk '/dev/disk/by-id/usb-Samsung_Flash_Drive_0325121050019952-0:0'

This will allow you to avoid an unavailable disk error if its name changes. See the article “Persistent names for block devices” for details.

How to repair an LVM disk using fsck

How to repair an LVM disk

If, due to errors on the disk, the system cannot boot, then usually in the emergency mode console you need to check the disk partitions, approximately as follows (you need to specify your disk name and partition number):

umount /dev/sda2
fsck -y /dev/sda2

But if we are talking about LVM, or LVM with encryption, then the situation becomes more complicated.

See also:

You can determine that the LVM or LVM technology with encryption is used by the entries /dev/mapper/hostname--vg-root and /dev/mapper/hostname--vg-home, which are indicated instead of the partition names in the command output


1. Checking and repairing an unencrypted LVM disk using fdisk

Use the following steps to repair LVM.

First, we check the partitioning of disks with lsblk:


Output example:

sda                    8:0    0    20G  0 disk  
└─sda1                 8:1    0    20G  0 part  
  └─xubuntu--vg-root 253:0    0    19G  0 lvm   / 
sr0                   11:0    1  1024M  0 rom   

As you can see, LVM is named xubuntu--vg-root, but we cannot run fsck on that name because the command will not find it. We need to get the full name, for this we need to run the lvm lvscan command to get the LV name with which we can run fsck on LVM.

The following command should be run with elevated privileges (with sudo or as root):


Output example:

  inactive          '/dev/xubuntu-vg/root' [<19.04 GiB] inherit
  inactive          '/dev/xubuntu-vg/swap_1' [980.00 MiB] inherit

As you can see, the drive name to check for errors is /dev/xubuntu-vg/root, it should be good enough to run fsck on that name.

If /dev/xubuntu-vg/root root is not ACTIVE, we need to make it active so that we can start checking it.

lvchange -ay /dev/xubuntu-vg/root

It should now look something like this:

sudo lvscan
  ACTIVE            '/dev/xubuntu-vg/root' [<19.04 GiB] inherit
  inactive          '/dev/xubuntu-vg/swap_1' [980.00 MiB] inherit

Now we can run fsck to check the LVM volume:

fsck /dev/xubuntu-vg/root

or run a forced check with automatic error correction:

fsck -fy /dev/xubuntu-vg/root

2. Fix LVM with encryption

It may be that the actions from the previous example are possible only during normal system boot, when all possible utilities are available. Accordingly, in Emergency mode, these operations will fail.

Therefore, let's consider an example of recovering a system from a Live image. The reason for the analyzed problem is that “apt autoremove” command removed the “cryptsetup” package and other utilities important for decryption and normal operation of the partition. This caused the system to stop booting (because the root partition could not be mounted and decrypted using LVM).

If you are not using LVM and full disk encryption, then the probably following is not for you.

In this example, it was possible to fix the system and reinstall cryptsetup and lvm2 in a chroot environment: for this you needed to boot from the Live USB stick, run the following commands in the terminal and reboot

Finding the root partition:

sudo fdisk -l

We decrypt the partition.

sudo cryptsetup open --type luks /dev/nvme0n1p3 nvme0n1p3_crypt


  • replace /dev/nvme0n1p3 with your own drive
  • replace “nvme0n1p3_crypt” with the correct partition name for your computer, you can find it by running the following in the chroot:
cat /etc/crypttab | cut -f1 -d " "

Output example:


Mounting the root partition

sudo vgscan
sudo vgchange -ay
sudo mount /dev/mapper/xubuntu--vg-root /mnt

Preparing the chroot environment:

sudo mount /dev/nvme0n1p2 /mnt/boot/ # replace nvme0n1p2 with your boot partition!
sudo mount -o rbind /dev/ /mnt/dev/
sudo mount -t proc proc /mnt/proc/
sudo mount -t sysfs sys /mnt/sys/

Make DNS service available in chroot:

sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

Enter the chroot:

sudo chroot /mnt /bin/bash

We reinstall the missing packages:

apt install cryptsetup lvm2

Re-generate (this can be done with the “apt” command in the previous step – if it was already done, then skip):

update-initramfs -u -k all

Leaving the chroot environment:


Let’s write the buffer to disk:

sudo sync

Unmount the file systems:

sudo umount /mnt/sys
sudo umount /mnt/proc
sudo umount /mnt/boot

How to determine why Linux boots into Emergency mode

How to determine the exact reason why Systemd falls in emergency mode

A Linux system can go into an emergency mode shell if it encounters problems during boot.

The screen prompts you to execute the command

journalctl -xb

to find the causes of system problems.

It is also proposed to execute

systemctl default



so that the system tries to boot normally.

You can try “systemctl default” – sometimes it really helps, but sometimes first you need to fix the problem that caused the Emergency mode.

The output of “journalctl -xb” is quite extensive, and examining it without filters does not always give a clue why it is booted into an emergency shell. Let's look at ways that can help you find the problem.

1. Finding problems with mounting

There are not so many reasons why the system goes into Emergency mode, usually these are problems with mounting disks and partitions. See what the following commands tell you?

systemctl status local-fs.target
journalctl -xb | grep -i -E 'local-fs.target'

2. Finding errors

What's do “journalctl -xb” tell? Try looking for mount and error related strings – maybe there is an answer.

journalctl -xb | grep -i mount
journalctl -xb | grep -i -E '(error|fail|warn|\(EE\))'

3. Unsuccessful fsck launch

Check fsck related entries:

journalctl -xb | grep -i -E 'fsck'
systemctl status systemd-fsck*

4. Unsuccessful start of any services

The following commands (they are identical) will list the services that failed to start:

systemctl --state=failed
systemctl --failed

5. Log search in Emergency mode and Maintenance mode

You can search for errors in the journald log without using commands – you may find it more convenient for you. Since journalctl uses the “less” command for multi-page browsing, you can use all of the keyboard shortcuts for this utility for your searches.

Output the log:

journalctl -xb

If you are relying on the search (/) function and are looking for something like “error”, “warning”, or “fail”, use -i to make sure the search is case insensitive.

List of commands and keys to search through journalctl (and less generally):

  • -i (case insensitive)
  • g (go to start)
  • /error (find “error”)
  • nnnn (skip nnnn results)
  • g (go to start)
  • /fail (find “fail”)
  • nnnn (skip nnnn results)
  • g (go to start)
  • /warn (find “warn”
  • nnnn (skip nnnn results)

Error “Cannot open access to console, the root account is locked” (SOLVED)

After a sudden power outage, unsuccessful update or adding a new disk to /etc/fstab, you may face the problem that your system does not boot, or rather, boots into the console or into a black screen. Sometimes the problem is compounded by the fact that the system administrator cannot even get into the emergency console. Let's see how to solve the following error:

You are in emergency mode. After logging in, type 'journalctl -xb' to view system logs, 'systemctl reboot'
'systemctl default' or "exit" to boot into default mode.

Cannot open access to console, the root account is locked.

See sulogin(8) man page for more details.

Press Enter to continue.

Reloading system manager configuration

After pressing Enter, everything can be repeated.

This message states that the system booted in emergency mode. In fact, this is not so bad – sometimes a system administrator can deliberately boot into emergency mode to restore the OS.

The real problem is that the root account is locked (this is indicated by the message “Cannot open access to console, the root account is locked”) and you cannot get into the console to start solving problems.

The situation becomes stalemate – the system will not let you go anywhere except in the root console, and it will not let you in the root console either, since this user is locked…

How to unlock the root user in emergency mode

Nevertheless, there is a way out of this situation. Start by booting into single user mode – this is the same mode used to reset the Linux password. Below is a generalized instruction, if something does not work out for you, then separate instructions for different distributions for booting into single-user mode can be found here.

Stop the booting by holding down the SHIFT key while starting the computer, you will see:

Press the “e” key and you will proceed to editing the boot settings:

Find the line starting with “linux”.

Go to the end of this line, insert a space, and add:

single init=/bin/bash

It should look something like this (the kernel number may differ):

When everything is ready, press Ctrl+x or F10 to continue the booting with the set options.

You will see a shell prompt, also note that we are logged in as root i.e. we have elevated privileges, including the use of the passwd command:



will set the password for the root user.

If the passwd command fails:

passwd: Authentication token manipulation error
passwd: password unchanged

the filesystem is most likely mounted read-only. To verify this, enter the command:


The “ro” indicate that the filesystem is mounted read-only and therefore the changes made cannot be saved. Remount the file system:

mount -rw -o remount /

After that, the password change should be successful.

Remove the password lock for the root user:

passwd -u root

If the root user is locked, then this may not be enough. Check which shell is set for root:

less /etc/passwd

If “/usr/sbin/nologin” is specified as the shell for root, run one of the following commands.

  • To assign a Bash shell to the root user:
sudo usermod -s /usr/bin/bash root
  • To assign a ZSH shell to the root user:
sudo usermod -s /usr/bin/zsh root

See also: How to change the login shell in Linux. chsh instruction

To exit, type:

umount /

To turn off your computer run:

poweroff -f

Or restart your computer with the command:

reboot -f

If after the reboot you see “Give root password for maintenance”, then this means that the first stage of recovery was successful – we activated the root user and can now start restoring the system.

How to recover a computer in emergency mode

Now we have the opportunity to restore the system. If you have no idea what exactly caused the error, then run the command

journalctl -xb

and try to find the cause of the problem there.

Checking disks for errors

If you think the error is caused by hard disk problems, then use the following commands to check the partitions:

umount /dev/sda2
fsck -y /dev/sda2

Partition number and disk name may differ from “sda2”, to find out the exact name, use the command

fdisk -l



Failed update

If the system does not boot due to an interrupted update, then try the following commands:

apt install -f -y
dpkg --configure -a

If you think that the problem was caused by an unsuccessful update of a specific package, then use a command like this:

dpkg-reconfigure PACKAGE

This command will reconfigure an already installed package.

For example, the following command will re-configure the Linux kernel:

dpkg-reconfigure linux-image-`uname -r`

System does not boot due to incorrect entry in /etc/fstab

In the event of an unsuccessful mount (this can happen if you made an incorrect entry in the /etc/fstab file, the system will not be able to boot, it will go into emergency mode and the following message will be displayed:

You are in emergency mode. After logging in, type "journalctl -xb" to view system logs, "systemctl reboot" to reboot, "systemctl default" or "exit" to boot into default mode.
Give root password for maintenance
(or press Control-D to continue):

To fix the problem, enter the root password and open the /etc/fstab file for editing:

nano /etc/fstab

Comment out or delete the problematic line. Save the file (Ctrl+o), close it (Ctrl+x) and reboot:


An unplugged disk causes a delay in system boot

The fstab file contains descriptive information about the file systems that the system can mount. In the /etc/fstab file, you can specify the parameters for mounting a disk, which can be either plugged to the system or unplugged from it. An example of such a disk is an external USB drive. In the latter case, you must additionally specify the nofail option.

An example of such an entry:

UUID=26FC3023FC2FEC2D	/mnt/disk_e	ntfs	nofail,rw,utf8	0	0

Thanks to the nofail option, the system boots normally and shows no errors even if the specified disk is missing.

But starting with systemd 249-3, the system began to try to mount this disk even if it was not connected. As a result, when the computer was turned on, it waited for the timeout of this operation to complete, that is, the boot freeze for 90 seconds (the default timeout).

The following messages appeared in the system log:

HackWare systemd[1]: dev-disk-by\x2duuid-26FC3023FC2FEC2D.device: Job dev-disk-by\x2duuid-26FC3023FC2FEC2D.device/start timed out.
HackWare systemd[1]: Timed out waiting for device /dev/disk/by-uuid/26FC3023FC2FEC2D.
HackWare systemd[1]: dev-disk-by\x2duuid-26FC3023FC2FEC2D.device: Job dev-disk-by\x2duuid-26FC3023FC2FEC2D.device/start failed with result 'timeout'.

Most likely, this problem is a temporary bug that will be fixed in future versions of systemd. But now you can use the x-systemd.device-timeout mount option so that the computer does not wait a minute and a half.

In the following example, the timeout value is set to 1 second:


UUID=26FC3023FC2FEC2D	/mnt/disk_e	ntfs	nofail,rw,utf8,x-systemd.device-timeout=1	0	0

As a result, the computer began to turn on almost immediately, without delay.

If the specified disk is connected to the computer after turning on, then the disk will be mounted correctly, taking into account the options from the /etc/fstab file. The minimum timeout time is not an obstacle for mounting after turning on the computer.

If the disk is usually unplugged, then the noauto option is more appropriate:

UUID=26FC3023FC2FEC2D	/mnt/disk_e	ntfs	noauto,nofail,rw,utf8	0	0

This option makes it so that the system will not try to mount the disk when you turn on the computer. However, the next time you connect the disk, it will be mounted according to the options in the /etc/fstab file.

How to change the default operating system in Arch Linux (for UEFI and systemd-boot)

This instruction applies to all boot loaders that implement the Boot Loader Specification and/or Boot Loader Interface, such as systemd-boot.

If you have a modern computer (no older than seven years at the time of writing), then it most likely uses UEFI instead of BIOS and, therefore, uses systemd-boot to boot, which is usually mentioned in the Arch Linux installation instructions (although there may be grub).

The bootctl program can check EFI firmware and bootloader status, list and manage available bootloaders and bootloader entries, and install, update, or remove systemd-boot on the current system.

To check if your system uses systemd-boot, run the command:

bootctl is-installed

The following command will show all available loader entries that implement the Boot Loader Specification, as well as any other entries found or automatically generated by a loader that implements the Boot Loader Interface.

bootctl list

  • title is an entry name. Note that the entry with the string “(default)” is selected as the default loaded
  • id is an identifier, it is needed in the commands described below to change the OS loaded by default
  • source is a path in the OS
  • linux is the Linux kernel
  • initrd is initial RAM filesystem. The purpose of initramfs is to boot the system to the point where it can access the root filesystem.
  • options are boot options

The following command sets the default bootloader entry. It takes one string of the bootloader entry ID as an argument.

sudo bootctl set-default ID

The set-oneshot command will set the default entry for the next boot only, set-default will set it permanently for all future bootings.

sudo bootctl set-oneshot ID

Optionally, the bootloader entry ID can be one of: @default, @oneshot, or @current, which corresponds to the current default bootloader entry for all future downloads, the current default bootloader entry for the next boot, and the currently loaded bootloader entry. These special identifiers are converted to the current values of the EFI variables LoaderEntryDefault, LoaderEntryOneShot, and LoaderEntrySelected. These special identifiers are primarily useful as a quick way to permanently make the currently loaded bootloader entry the default choice, or update the default bootloader entry for the next boot to the default bootloader entry for all future bootings, but they can be used for others operations as well. If an empty string ("") is specified as the identifier, the corresponding EFI variable will not be set.

The boot manager integrates with the systemctl command, so the following commands can be used:

systemctl reboot --boot-loader-entry=ID

This command will reboot the computer to the specified bootloader entry.

By the way, to get a very compact list containing only bootloader entries, run the command:

systemctl reboot --boot-loader-entry=help

The following command will immediately reload you into the EFI boot menu. This menu will have a timeout for the specified number of SECONDS:

systemctl reboot --boot-loader-menu=SECONDS