How to Install Kali Linux on a USB Stick with Pure EFI Boot on a Mac (and Let‘s Throw in Virtualization!)

As a full-stack developer and cybersecurity enthusiast, I‘ve always been fascinated by the versatility and power of Kali Linux. For those unfamiliar, Kali Linux is a Debian-based distribution specifically designed for advanced penetration testing and security auditing. Its vast collection of tools makes it an essential asset for any security professional or curious developer looking to explore the world of ethical hacking.

One of the great things about Kali Linux is its portability. By installing Kali on a USB stick, you can carry your entire penetration testing environment with you wherever you go. This is particularly useful for on-the-go security assessments, live demonstrations, or even as a backup system in case your primary machine fails.

However, installing Kali Linux on a USB stick for Mac users comes with its own set of challenges. The default partitioning scheme used by the Kali installer is not compatible with the Mac‘s EFI boot process. But fear not! In this comprehensive guide, I‘ll walk you through the step-by-step process of installing Kali Linux on a USB stick with pure EFI boot on a Mac. And as a bonus, we‘ll also explore how to virtualize the USB installation using VirtualBox.

Prerequisites

Before we dive into the installation process, let‘s ensure you have everything you need:

  • A Mac computer
  • A USB stick with at least 16GB of storage (USB 3.0 recommended for faster performance)
  • Kali Linux ISO image (download from the official Kali website)

Step 1: Create a Kali Live USB Stick

The first step is to create a Kali Live USB stick. This will allow us to boot into the Kali installer and perform the installation on our target USB stick. Here‘s how to do it:

  1. Insert your USB stick into your Mac.
  2. Open Terminal and run the following command to identify your USB stick:
diskutil list
  1. Look for your USB stick in the list of disks. It will typically be listed as /dev/diskX, where X is a number.
  2. Once you‘ve identified your USB stick, run the following command to unmount it:
diskutil unmountDisk /dev/diskX
  1. Now, we‘ll use the dd command to write the Kali ISO image to the USB stick. Replace {KALI_ISO.iso} with the path to your downloaded Kali ISO file:
sudo dd if={KALI_ISO.iso} of=/dev/diskX bs=1m
  1. Wait for the dd command to finish. This process may take several minutes, depending on the size of the ISO and the speed of your USB stick.

Step 2: Boot from the Kali Live USB Stick

With your Kali Live USB stick created, it‘s time to boot your Mac from it:

  1. Reboot your Mac and hold down the Option (Alt) key during startup.
  2. Select the EFI boot option corresponding to your Kali Live USB stick.
  3. The Kali Linux boot menu will appear. Choose the "Live" option to boot into the Kali Live environment.

Step 3: Install Kali Linux on the Target USB Stick

Now that you‘re in the Kali Live environment, follow these steps to install Kali Linux on your target USB stick:

  1. Insert your target USB stick into your Mac.
  2. Open the Kali Linux installer and select "Graphical Install".
  3. Choose your language, location, and keyboard layout preferences.
  4. When prompted to partition disks, select "Manual".
  5. Select your target USB stick from the list of disks and create the following partitions:
    • A primary partition with at least 8GB of space for the root filesystem.
    • A primary partition with at least 512MB of space for the EFI boot partition.
    • A swap partition with size equal to your Mac‘s RAM (optional but recommended).
  6. Assign the root partition to the mount point "/" and format it as ext4.
  7. Assign the EFI boot partition to the mount point "/boot/efi" and format it as FAT32.
  8. Complete the installation process by following the remaining prompts.

Step 4: Fix the EFI Partition

After the installation is complete, we need to fix the EFI partition to make it compatible with the Mac‘s boot process. Follow these steps:

  1. Boot into the Kali Live environment again.
  2. Open Terminal and run the following command to install the necessary tools:
sudo apt update
sudo apt install gdisk hfsprogs
  1. Identify your target USB stick by running diskutil list and note down its device name (e.g., /dev/diskX).
  2. Run the following command to open the gdisk partitioning tool:
sudo gdisk /dev/diskX
  1. In the gdisk prompt, type p to print the partition table and confirm that the first partition has type EF00.

  2. Type d to delete the EF00 partition.

  3. Type n to create a new partition, and follow the prompts to create a new HFS+ partition in its place.

  4. Type w to write the changes and exit gdisk.

  5. Format the newly created HFS+ partition by running:

sudo mkfs.hfsplus /dev/diskXs1 -v Kali
  1. Mount the root partition of your Kali installation and open the /etc/fstab file:
sudo mount /dev/diskXs2 /mnt
sudo nano /mnt/etc/fstab
  1. Locate the line that mounts the /boot/efi partition and delete it.

  2. Save the changes and exit the text editor.

  3. Unmount the root partition:

sudo umount /mnt
  1. Reinstall GRUB to use the HFS+ partition for its EFI data:
sudo mkdir -p /mnt/boot/efi/EFI/Kali
sudo echo "This file is required for booting" > /mnt/boot/efi/EFI/Kali/mach_kernel
sudo echo "This file is required for booting" > /mnt/boot/efi/mach_kernel
sudo grub-install --target x86_64-efi --boot-directory=/mnt/boot --efi-directory=/mnt/boot/efi --bootloader-id=Kali
  1. Bless the bootloader code:
sudo apt install git make
git clone https://github.com/detly/mactel-boot
cd mactel-boot
make
sudo ./hfs-bless /mnt/boot/efi/EFI/Kali/System/Library/CoreServices/boot.efi
  1. Create the GRUB configuration:
sudo sed -i ‘s/GRUB_HIDDEN/#GRUB_HIDDEN/g‘ /mnt/etc/default/grub
sudo sed -i ‘s/GRUB_TIMEOUT=10/GRUB_TIMEOUT=0.1/‘ /mnt/etc/default/grub
sudo grub-mkconfig -o /mnt/boot/grub/grub.cfg

Congratulations! You now have a fully functional Kali Linux installation on your USB stick with pure EFI boot on your Mac.

Bonus: Virtualizing the USB Installation

If you want to use your Kali Linux USB installation in a virtualized environment, you can easily do so using VirtualBox. Here‘s how:

  1. Install VirtualBox on your Mac.
  2. Create a VMDK disk that points to the sectors of your USB stick:
sudo VBoxManage internalcommands createrawvmdk -filename ~/Kali.vmdk -rawdisk /dev/diskX
chmod 777 ~/Kali.vmdk
chmod 777 /dev/diskX
  1. Open VirtualBox and create a new virtual machine.
  2. When prompted for a disk, select the VMDK file you created in step 2.
  3. Go to the virtual machine settings and make the following adjustments:
    • Enable EFI under System > Motherboard.
    • Allocate appropriate CPU cores, memory, and video settings based on your requirements.
  4. Start the virtual machine and press F12 to access the boot menu.
  5. Select "Boot from file" and navigate to {SATA_DRIVE} > EFI > Kali > System > Library > CoreServices > boot.efi.

Your Kali Linux USB installation should now boot within VirtualBox, providing you with a convenient virtualized penetration testing environment.

Conclusion

Installing Kali Linux on a USB stick with pure EFI boot on a Mac may seem daunting at first, but with the right steps and a bit of patience, it‘s a relatively straightforward process. By following this guide, you can create a portable and versatile penetration testing environment that you can use on any Mac.

Remember to always use Kali Linux responsibly and ethically. Happy hacking!