After downloading Kali Linux the next step is the creation of a bootable USB. This is due to failed GRUB installation happens because of Bootable flag option. USB stick (>4 GB) – To install Kali Linux from USB. We can boot Live system or installing through USB. Kali Linux ISO – ISO file contains the boot information, which will be written to the USB stick and make the USB bootable.
by Flavio De Stefano
This tutorial is for everyone who wants a USB stick with a full Kali installation to use with your Mac(s). This is not intended to perform a Live Kali installation with persistence.
The problem when you perform a Kali installation on a USB stick is that Kali partitions the disk with the VFAT file system. Mac OS only recognizes HFS+ partitions along with some files needed for it.
So, you need:
- Your Mac
- A USB stick with Kali ISO installer
- A target USB stick, SD card or an SSD external drive where you’re going to install Kali (16GB and USB 3.0 recommended)
This tutorial was heavily inspired by this tutorial with proper fixes for Kali. https://medium.com/@mmiglier/ubuntu-installation-on-usb-stick-with-pure-efi-boot-mac-compatible-469ad33645c9
USB Live installation
First of all, install Kali on a USB stick by following this tutorial. I’m not gonna bother you on how to proceed on this step, but start here:
When you’re ready, reboot your Mac. Insert both your USB sticks, then press ALT and select the EFI boot to start the Live installer.
Kali installer will ask you different questions about your timezone and keyboard layout.
Proceed until it asks you to partition disks, here select: Manual. Then select your USB target drive (where you want to install Kali). You can recognize by various factors, for example by its size. Click Continue: this will partition your drive.
Now, back again to the same screen and select the FREE SPACE under the USB target drive. Click Continue and select Automatically partition the free space. Follow the recommended option. Then click on Finish partitioning and write the change to disk.
The installation process now will copy data to disk. Wait until it finishes (this is gonna take ~30 minutes).
Boot from GRUB Live
Once finished, your Mac will reboot and you have to press ALT again. Select EFI boot again.
What we have to do now is to load our installed Kali system via Live GRUB, because our installed system doesn’t have a recognizable boot-loader by MacOS.
Once GRUB is loaded, press c to get the GRUB command-line-interface.
Now you have to understand in which HD is your Kali installation. To do this, when GRUB cli is loaded, type ls; eject your USB stick and type ls again.
You’ll notice that an hd{X} disappeared: that is your drive. Now you have to find your gpt. Probably it’s the gpt2, but just to be sure, type:
If the command says
unicode..
it’s the correct gpt; try other gpts otherwise. Now find your UUID of the partition, and annotate it.Now we cant set the parameters to GRUB to boot (use the tab key to use autocomplete):
This should boot your Full Kali Installation using the Live GRUB. You could differentiate from Live environment by the password it recognizes during the login process.
Fixing the EFI partition
Once you’re logged in in your Kali installation, open the Terminal and type:
and find your drive.
Now, open gdisk (installed by default on Kali) to partition the drive (be very careful here):
Print the partition table and confirm that the first partition has type EF00:
Now we have to:
- delete that EF00 partition
- create a new HFS+ once in its place
Now we have an unformatted HFS+ partition. To format, we need some tools; but to obtain these tools we need to add the Debian source-list to apt.
We can format that partition:
Now we have to edit the /etc/fstab file:
This will launch Gedit. In this file, localize these lines:
# /boot/efi was on /dev/sd{X}1 during installation
UUID={XXXXXXX} /boot/efi vfat defaults 0 1
and delete them.
Now, unmount the boot partition, localizing it using:
Then run this to add the necessary entries to your fstab file:
Now we have to reinstall GRUB so it can use the newly formatted HFS+ partition for its EFI data:
We then need to “bless” the bootloader code, so that the Mac bootloader will boot it. To do that we need hfsbless binary that is not available via apt. No problem, just clone the repository and build:
Then bless:
The final step is to create the grub configuration:
Perfecto! Now reboot and you should see your USB stick in the Mac bootloader by pressing ALT.
Virtualizing the USB via Virtualbox
If you ever need to boot this USB stick via Virtualbox (on Mac OSX), there is a simple trick to do that.
First of all, you’ve to create a VMDK disk that points to the sectors of your USB stick. So, let’s identify that disk:
In our case, it is /dev/disk3. Let’s unmount before proceeding:
With VirtualBox installed, run:
Perfecto. Now, run Virtualbox UI and create a new machine with the following settings:
When VirtualBox asks you for a disk, let’s point to that VMDK created before:
Before starting up the machine, let’s go to Settings and adjust your process counts, video and memory.
The important things are to set Enable EFI under System > Motherboard.
This will allow you to boot via EFI. Now start the virtual machine and immediately press F12.
Select Boot Maintenance Manager:
Select Boot from file:
Then select {SATA_DRIVE} > EFI > Kali > System > Library > CoreServices > boot.efi
And, voilà:
Stay tuned :)