How to install Windows 11 and Kali Linux on the same flash drive

Table of contents

1. Flash drive with Windows 11 and Kali Linux

2. Preparing a flash drive for installation

3. Using a flash drive as a raw VMDK virtual hard disk

4. Creating and configuring virtual machines

5. How to install when dual booting Windows and Linux

6. Installing Windows 11

7. Installing Kali Linux

8. How to add a new boot option to UEFI

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

9.1 Renaming files and folders on an EFI partition in Linux

9.2 Renaming files and folders on an EFI partition in Windows


Flash drive with Windows 11 and Kali Linux

In this tutorial, I will show you how to install two operating systems Windows 11 and Kali Linux on a flash drive. Instead of a flash drive, you can use a USB drive. As a result, we will get a bootable USB flash drive that can be inserted into the USB socket of any computer and boot into either Windows 11 or Kali Linux.

We will install operating systems in VirtualBox:

  • firstly, thanks to this approach, it is completely safe and we are guaranteed not to delete data from any disks on the computer;
  • secondly, although Windows boots from a USB drive, this OS refuses to be installed on a USB flash drive or an external drive.

All systems will be fully installed as if they were installed on disks inside the computer.

As a storage device, I will use a 256 GB USB 3.2 Gen1 flash drive (USB Flash Samsung BAR Plus [MUF-256BE3/APC] 256 GB). On a laptop, the flash drive is connected to a SuperSpeed USB 10 Gbps (USB 3.1, also known as USB 3.1 Gen 2) port. Looking ahead, operating systems in this combination work very quickly.

My plan for partitioning a 256 GB flash drive:

  • Windows 11 will be allocated 100 GB.
  • 50 GB will be allocated for Kali Linux OS files, as well as for installing tools. The remaining space (about 100 GB) will be given to the user's personal files (/home folder) – this partition will be encrypted.

If necessary, you can reinstall operating systems individually.

Preparing a flash drive for installation

Extensive experience installing Windows and Linux suggests that the ideal option is when the flash drive is cleared, that is, when the partition table is deleted from it. If the flash drive was used as a bootable or Live flash drive, on which an ISO image was burned, if the flash drive was used to store files (with an MBR partition table), or if any OS was already installed on the flash drive, then you will almost certainly encounter an error at the disk partitioning stage. Errors occur both in Windows, which, for example, is not able to create the GPT partition table it needs if MBR is already present (for example, from the factory my flash drive comes with this partition table and the exFAT file system), and Linux, which for some reason automatically mounts all existing partitions, as a result of which the installer cannot make a new disk partition.

To avoid any of these errors, clean your flash drive as shown in the article “How to recover USB drive/flash drive after flashing an ISO image or installing OS”. After this stage, the flash drive will no longer be detected in the system (for example, Windows will offer to format it) – this is the effect we need. If it is impossible to use a flash drive, then everything will be fine for the installer.

Using a flash drive as a raw VMDK virtual hard disk

VirtualBox can work with USB devices, including USB media. But we need to connect the USB flash drive in a special way. In fact, everything is quite simple, we need to perform 2 simple steps:

1. Create a file that will be something like a link to a USB flash drive as a device. This is just a simple text file that is created with a command like:

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

2. The second action that we need to perform is when creating a virtual machine, instead of creating a new virtual disk, specify the same file that we created in the first step.

That's all! As a result, VirtualBox will work with a flash drive not as a USB device, but as with a regular media. The most important consequence of this, why we did all this: now virtual operating systems will also perceive a USB flash drive as a regular SATA drive – this is necessary to trick Windows, which refuses to install on the media if it recognizes a USB flash drive or an external drive.

All the details and commands on how to create a link file to a USB flash drive are shown in the article “How to install Windows on a USB storage”. It describes the process of creating a file for Windows and Linux.

Creating and configuring virtual machines

The created bootable USB flash drive with Windows and Linux can be used on real computers, that is, it is possible to boot from a USB device on laptops and desktop computers. But at the same time, you can also boot from the same flash drive in the VirtualBox virtual computer. We will also perform the installation itself in VirtualBox. In order for this to work, we need to set such settings in VirtualBox so that both systems (Windows and Linux) can work. Well, or at least their installers worked fine. This is what is shown below.

Start creating a new virtual machine.

Enter any name, select “Linux” as the Type, select “Debian (64-bit)” as the Version.

Specify the amount of RAM you want to allocate to the virtual machine.

Then select “Use an existing virtual hard disk file”.

Click the “Choose a virtual hard disk file” button.

Click the “Add” button.

Locate the .vmdk file in the file system that was created in the previous step, in my case the file is called flash.vmdk.

Choose this drive.

You will see the size of the selected disk, click the “Create” button.

Go to the virtual machine settings.

On the System → Motherboard tab, enable the “Enable EFI (special OSes only)” setting.

On the System → Processor tab, enable the “Enable PAE/NX setting”. Optionally, add processor cores.

In the Display → Screen tab, select “VboxSVGA” as the graphics controller. If desired, you can add video Memory.

You can leave all other settings unchanged.

How to install when dual booting Windows and Linux

As a general rule, Windows is always installed first.

The fact is that Windows does not take into account other operating systems and they will be absent in the menu of its bootloader.

In turn, Linux “respects” all OSes it can find and adds them to its bootloader.

Therefore, we will install Linux after Windows, as a result of which the Linux bootloader will be used.

Installing Windows 11

You can install both Windows 10 and Windows 11 using the method shown below. For Windows 10, there are no special installation image requirements, and the Windows 11 image must have a patch that does not check for TRIM.

Start the virtual machine.

Select the Windows installation image file.

Restart the machine via menu “Machine” → “Reset”.

When you turn on the virtual machine, press any button to start booting from disk.

Next, a typical Windows installation begins.

At the disk partitioning stage, select the disk where you want to install Windows and click the “New” button.

Enter the size in Megabytes you want to allocate under Windows and click the “Apply” button.

The installer warns that additional partitions will be created that are necessary for normal Windows operation.

When the partitions are created, click the “Next” button.

Wait for the installation to complete.

Next, the system will offer to add keyboard layouts – we will not dwell on trivial settings.

Think of a name for your computer.

See also: Windows Computer name: how to change and use

Select “Set up for personal use” and click the “Next” button.

In order not to create a Microsoft account, but to use an offline account, at the stage shown in the screenshot, scroll down and click “Sing-in options”.

Find and select “Offline account” option.

You will be persuaded, but click “Skip for now”.

Think of and enter a username.

Think up, remember and enter the password. If you want to log in to the computer without a password, then leave this field blank.

Do not rush to click “Next” at this stage.

Scroll through the list carefully – you may want to disable some/all options.

If you have disabled all options, then the “Next” button will change to “Accept”.

After the installation is complete, the system will boot, but the screen will be small in the virtual machine.

If you plan to use this flash drive only on a real computer and you do not need to boot in a virtual machine, then just proceed to install Kali Linux. If you plan to use USB media for booting on real and virtual computers, then install the VirtualBox Guest Additions.

After that, the screen will be large even when booting into VirtualBox.

It is highly recommended to disable hibernation. The essence of hibernation is that a copy of RAM is constantly saved to disk – in our case, to a flash card. The speed of the flash card slows down a lot if you read and write data in several threads (you will notice this during the installation of Windows updates). Due to the constant load on the disk, the system starts to work more slowly, especially if you perform other read and write activities on the flash drive. In addition to this, the hiberfil.sys file (which stores a copy of the RAM) is very large (so that all the RAM can fit on it). This leads to useless waste of valuable disk space.

To disable hibernation and delete the hiberfil.sys file, open a command prompt (Win+x → Windows Terminal (Admin)) and enter the command:

powercfg /H OFF

You will notice that after disabling hibernation and deleting the hiberfil.sys file, the system is much more responsive and fast.

If you encounter an error while booting Windows

Windows created a temporary paging file on your computer because of a problem that occurred with your paging file configuration when you started your computer. The total paging file size for all disk drives may be somewhat larger than the size you specified.

then I don’t know how to help. This is not a critical error – just close the window, there will be no more consequences. I get this message when booting from a USB flash drive, but this message does not appear when booting from an external USB drive. I tried different recipes from the Internet but they didn't help.

Installing Kali Linux

Insert the Kali Linux installation image into the virtual CD-ROM.

If you cannot boot from the Kali Linux installation ISO when booting the virtual computer, then turn on or restart the computer while holding the SHIFT key.

Select “Use a device”.

Select CD-ROM.

In the boot menu, select “Graphical install”:

Select the desired operating system language. In this guide, I will skip the typical installation steps and focus only on partitioning disks. If something is not clear to you on other steps, then see “How to install Kali Linux (step by step tutorial)”.

Let me remind you that according to my plan, 50 GB will be allocated for Kali Linux OS files, as well as for installing tools. The remaining space (about 100 GB) will be given to the user's personal files (/home folder) – this partition will be encrypted.

You will find the theory about working with encrypted partitions in the instruction “How to install Kali Linux with full disk encryption or encrypted user’s home folder”, but only the configuration steps will be shown here.

When you come to the partitioning of disks, then select “Manual”.

We need to add only two partitions:

  • root partition (/)
  • user's home folder (/home)

The EFI partition has already been created by Windows, Kali Linux can use this partition to install the necessary bootloader.

ATTENTION: During the operation of a flash drive with two operating systems, the following turned out: after installation, while using Windows, it creates an additional partition “Windows recovery environment”. The size of this partition in my case was 616 megabytes. The space for this partition is taken from the partition allocated for Windows installation. This volume is created at the end of “Microsoft basic data” and, it seems, its presence should not affect anything. But in fact, after creating the Windows recovery environment, the next partition on which Kali Linux is installed turns out to be corrupted. That is, after the automatic creation of this partition, Windows works as usual, and Kali Linux no longer boots. To prevent the partition with Kali Linux from being corrupted, it is necessary to leave unallocated space between the Windows and Linux partitions. In this article, I indent 100 MB, but most likely even several tens of megabytes would be enough – you can experiment with this value.

Select an unoccupied area (“FREE SPACE”).

Let's create a new partition.

Now we are creating a “buffer” between the Windows and Linux partitions, it is necessary so that the Linux partition is not damaged during the creation of the Windows recovery environment. 100 MB is enough.

Select “Beginning”.

In the “Use as” field, select “do not use”. Then click “Done setting up the partition”.

Select an unoccupied area (“FREE SPACE”).

Let's Create a new partition.

Select a partition size. This partition will be the root partition, OS files will be installed on it and programs will be installed here. It is not recommended to make this partition less than 20 GB.

Select “Beginning”.

In the “Use As” field, select “Ext4 journaling file system”. For “Mount point” select “/”. Then click “Done setting up the partition”.

Now let's move on to creating an encrypted partition. Select “Configure encrypted volumes”.

We are warned that in order to start creating an encrypted disk, the current partition scheme (the two partitions that we just created) must be written to the disk – these changes cannot be undone. Select “Yes”.

Select “Create encrypted volumes”.

Choose where exactly this volume will be placed. Be especially careful if you have multiple disks. In the screenshot, the free space of a single disk is selected.

Select “Done setting up the partition”.

Again, you need to save the current partition scheme to disk. Select “Yes”.

I only need one volume, so I choose “Finish”.

We are warned that the selected partition will be overwritten with random data and information from it will be lost. If so, select “Yes”. If the partition is large, then this process will take quite a long time.

Enter the password to decrypt the partition.

So far, we have only created an encrypted partition that has no volumes or mount points. All this is configured in LVM.

Go to “Configure the Logical Volume Manager”.

Again, you need to write down the current partition scheme, again “Yes”.

In this step, we “Create volume group”.

Come up with a name – for example, after the name of the machine.

Select a device for the new volume group. This device is the encrypted partition created in the previous step.

Now we Create a logical volume.

Choose a group – it is one.

Name the volume – the name can be arbitrary, but it's in your best interest to make it self-explanatory.

Specify the volume size.

One volume is enough for me, so I choose “Finish”.

Now you can observe the created volume, but it is not used in any way and no file system has been selected for it. Click on volume record.

In the “Use As” field, select “Ext4 journaling file system”.

For “Mount point” choose “/home”. Then click “Done setting up the partition”.

We complete the partitioning of the disk, select “Finish partitioning and write changes to disk” → “Continue”.

I am warned that I have not created a swap file – I have 32 gigabytes of RAM, I do not need a swap file, so I choose “No”.

We are once again warned that the data will be written to the disk and the information available on it will be lost, select “Yes”.

The following installation steps are normal for a typical installation.

See also: Kali Linux post-installation tips and settings

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:

diskpart

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:

Exit DISKPART:

exit

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.

Recommended for you:

One Comment to How to install Windows 11 and Kali Linux on the same flash drive

  1. FriendFromPoland says:

     

     

    Great tutorial. Thank you.

     

     

Leave a Reply

Your email address will not be published. Required fields are marked *