Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[Quick Tutorial] Setting up Kali Linux Live USB with Encrypted Persistent Storage

Figured I'd share this, since I just found out about this tonight. It also helped me get Kali Linux working with my pain-in-the-ass UEFI.

Keep in mind that when reading from/writing to an encrypted partition, the disk I/O speed is significantly slower. (An initial execution of apt-get update && apt-get upgrade will likely take in excess of three hours, possibly longer.) Even unencrypted storage partitions on a USB drive are going to be much slower than even HDDs or SSDs. However, this will allow persistent data across reboots.

Step 1: Changing the USB Partition Scheme

I created this from an Ubuntu instance, so some of these steps will be linux specific.

The first thing I did was fire up gparted, and select the USB device. (/dev/sdb for me, your results may vary) Then I went to Device -> Create Partition Table... and selected "gpt", which is the new scheme that is used on UEFI devices, and supercedes the older "MBR" standard. However, if your computer uses BIOS instead of UEFI, "gpt" will not work. Instead, try "msdos", which is the default. This will wipe ALL data on the device, including all partitions. You do not need to recreate partitions yet, and it will actually probably be easier if you don't.

Step 2: Cloning The Kali Linux Image

Linux and OS X provide the awesome "dd" utility, which makes the process a snap. You can see Windows, OS X, and Linux specific instructions in the Kali Docs. I'll cover the Linux ones here as well.

To clone the image using dd, simply run this command: (Note: Ensure that /dev/sdb is indeed the correct path to the device, and that you have backed up anything important or you will lose data.)

Syntax highlighted snippet of this step

Code
# if is the input file. In this case, the Kali image
# of is the output file. In this case, the path to the device, NOT to a mounted partition (E.g. NOT /dev/sdb1, only /dev/sdb, /dev/sdc, etc.)
# bs is Block Size, or the size of the chunks that will be transfered to the device. 512k or 1M should be about perfect
dd if=/path/to/kali-image.iso of=/dev/sdb bs=1M



And theeeennnnn? No and then. That's it for this step.

Step 3: Creating an encrypted storage partition

This is the final step, and can be done from the same instance where you installed Kali, or from a live instance of Kali itself. Keep in mind, if you do this in Kali, you will still have to restart for the changes to take effect.

Now, you can either create the storage partition in gparted, or use the command line all the way through. Be sure to format the partition as ext3 if you use gparted.

Syntax highlighted snippet of this step

Code
# Start here if you didn't set up the partition in gparted
size=5gb # This is the size of the storage partition that you want. Make sure it doesn't exceed the unallocated space on the drive (the space not taken up by Kali most likely)
read bytes _ < <(du -bcm /path/to/kali-image.iso |tail -1); echo β # This will get the size of the disk image, and thus get the necessary offset for the beginning of the new primary partition.
parted /dev/sdb mkpart primary β $size # This creates the partition
# Start here if you already set up the partition in gparted
cryptsetup --verbose --verify-passphrase luksFormat /dev/sdb3 # Initialize encryption on the partition
cryptsetup luksOpen /dev/sdb3 my_usb # Decrypt the partition and prepare for mounting
mkfs.ext3 -L persistence /dev/mapper/my_usb # Create ext3 filesystem with label persistence, and map virtual device to /dev/mapper/my_usb
e2label /dev/mapper/my_usb persistence # Label drive persistence
mkdir -p /mnt/my_usb # Make directories recursively to create a mountpath for the USB drive
mount /dev/mapper/my_usb /mnt/my_usb # Mount the drive
echo "/ union" > /mnt/my_usb/persistence.conf # Create a peristence.conf file to tell Kali to use that partition for storage.
umount /dev/mapper/my_usb # Unmount the drive
cryptsetup luksClose /dev/mapper/my_usb # Remove the decrypted mapped drive

Now you should be able to restart, and when you go to the startup screen, you'll see a couple new options in the boot menu:

[img]http://docs.kali.org/wp-content/uploads/2014/01/Screen-Shot-2014-05-25-at-5.58.00-PM-e1401035177510.png[/img]

With an encrypted partition, you can use both encrypted, and unencrypted storage I believe.

Hope this helps you out!
Get a signed message before dealing: Keybase
Still here sometimes.
Thanks alot, so you mean when running kali linux on a USB of 16GB for example that has say 11Gigs of free storage, I can do whatever I want in kali linux and It'll be stored just like installing kali linux normally or running it from a VM ? (which means i don't have to apt-get update && apt-get upgrade && apt-get dist-upgrade each time i make a live boot ?)
(Jan 23, 2015 09:56 AM)firasuke3967 Wrote:  Thanks alot, so you mean when running kali linux on a USB of 16GB for example that has say 11Gigs of free storage, I can do whatever I want in kali linux and It'll be stored just like installing kali linux normally or running it from a VM ? (which means i don't have to apt-get update && apt-get upgrade && apt-get dist-upgrade each time i make a live boot ?)

Mhmm. It creates a persistent filesystem on the free space, and mounts it as /

Just keep in mind it's a hell of a lot slower than writing to memory.
Get a signed message before dealing: Keybase
Still here sometimes.
Ya I know that , thanks a lot for this useful information.
This is a nice tutorial, thanks for sharing!
thank you so much, I've been trying to figure this out with my teachers haha especially for the apt-get update
(Jan 26, 2015 09:27 AM)Ombree Wrote:  thank you so much, I've been trying to figure this out with my teachers haha especially for the apt-get update

Glad to hear that it helped you out :)

(Jan 25, 2015 10:16 AM)NoScript Wrote:  This is a nice tutorial, thanks for sharing!

Glad you enjoyed it!
Get a signed message before dealing: Keybase
Still here sometimes.
this tutorial is lack of screenshots or even a video wouldn of been great...
(Feb 3, 2015 07:29 PM)Fizure Wrote:  this tutorial is lack of screenshots or even a video wouldn of been great...

I'll try and throw some together, though there's really not too much to it.
Get a signed message before dealing: Keybase
Still here sometimes.
Thank you for sharing the idea. 🤝
“You are confined only by the walls you build yourself.”
Is the any way I can use a 4 GB USB?


Possibly Related Threads...
Thread / Author Replies Views Last Post
by foidslayer81Sep 20, 2026 10:23 PM 5 145 Sep 20, 2026 10:23 PM
Last Post: 7
by Pr0m3th3usJun 20, 2026 06:56 AM 4 130 Jun 20, 2026 06:56 AM
Last Post: Pr0m3th3us
by Pr0m3th3usFeb 6, 2025 08:23 PM 13 376 Feb 6, 2025 08:23 PM
Last Post: Pr0m3th3us