Instructions to write an iso with persistence USING a Linux script.

# .......1.........2.........3.........4.........5.........6....
Download a kali iso from:
  https://www.kali.org/downloads/
Verify the SHA256Sum checksum
Copy the script to a file
  CHECK THE USB DEVICE!
  use 'lsblk' to list attached devices
  Is it /dev/sdb? If not, edit script.
Name the file 'kali-persistence.sh'
Put the iso AND the script in the SAME folder
Open terminal to the folder
Make 'kali-persistence.sh' executable:
  chmod u+x kali-persistence.sh
Run the script as root:
  ./kali-persistence.sh {nameofiso}.iso
Run the script as user:
  sudo ./kali-persistence.sh {nameofiso}.iso
  Enter password when prompted
Progress is displayed while writing the iso
If a previous label is detected
  Type 'y' at the prompt to proceed
Progress is NOT displayed while partitioning the USB drive
When finished, Disk and Device info displayed
  Look to see if the Device info is reasonable.

To use the live USB drive:
Reboot
Use WHATEVER! key is need to boot from the USB drive
SOME boot menu keys by manufacturer

Acer      F12, F9, Esc
Asus      F8, Esc
Dell      F12
Fujitsu   F12, Esc
HP        F9, Esc
Lenovo    F12,F8, F10, Novo
Samsung   F12, F2, Esc
Sony      F11, F10, Esc
Toshiba   F12
others?   F12, Esc
Apple     Option

Choose: 'Live USB Persistence'
Login: root
Password: toor

# .......1.........2.........3.........4.........5.........6....
Writing the iso should look something like the following.
I am writing 'kali-linux-light-2019.1a-i386.iso'
To a 4gb USB drive, leaving about 3gb persistence.
For a NON-light kali iso, use an 8gb or larger USB drive.

# .......1.........2.........3.........4.........5.........6....
root@kali:~/Downloads/kali# ls -la
total 1049596
drwxr-xr-x 2 root root       4096 Apr 10 08:57 .
drwxr-xr-x 3 root root       4096 Apr 10 08:57 ..
-rw-r--r-- 1 root root 1074769920 Mar 21 15:22 kali-linux-light-2019.1a-i386.iso
-rw-r--r-- 1 root root       1865 Apr  9 08:46 kali-persistence.sh

root@kali:~/Downloads/kali# chmod u+x kali-persistence.sh

root@kali:~/Downloads/kali# ls -la
total 1049596
drwxr-xr-x 2 root root       4096 Apr 10 08:57 .
drwxr-xr-x 3 root root       4096 Apr 10 08:57 ..
-rw-r--r-- 1 root root 1074769920 Mar 21 15:22 kali-linux-light-2019.1a-i386.iso
-rwxr--r-- 1 root root       1865 Apr  9 08:46 kali-persistence.sh

root@kali:~/Downloads/kali# ./kali-persistence.sh kali-linux-light-2019.1a-i386.iso

Write kali-linux-light-2019.1a-i386.iso to /dev/sdb
1069547520 bytes (1.1 GB, 1020 MiB) copied, 92 s, 11.6 MB/s
1024+1 records in
1024+1 records out
1074769920 bytes (1.1 GB, 1.0 GiB) copied, 92.516 s, 11.6 MB/s

Persistence on /dev/sdb3 from 1075 to 4016
Information: You may need to update /etc/fstab.

mke2fs 1.44.5 (15-Dec-2018)
/dev/sdb3 contains a ext3 file system labelled 'persistence'
	last mounted on /mnt/kaliUSB on Wed Apr 10 08:24:02 2019
Proceed anyway? (y,N) y
Creating filesystem with 718080 4k blocks and 179520 inodes
Filesystem UUID: f34264ea-4ca9-4952-8813-959535b2a9fe
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

Disk /dev/sdb: 3.8 GiB, 4016046080 bytes, 7843840 sectors
Disk model: Transcend 4GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4e1a8e59

Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1  *         64 2097151 2097088 1024M 17 Hidden HPFS/NTFS
/dev/sdb2       2097152 2098559    1408  704K  1 FAT12
/dev/sdb3       2099200 7843839 5744640  2.8G 83 Linux

# .......1.........2.........3.........4.........5.........6....
# This is the script:
# .......1.........2.........3.........4.........5.........6....
#!/bin/bash
# vi:nowrap
# write iso with persistence
# sudo ./kali-persistence.sh {nameofiso}.iso

# *** IMPORTANT *** edit DEVICE as needed ***

DEVICE=/dev/sdb

if [ ! -e $DEVICE ] # device exists ?
then
  echo;echo "device $DEVICE ?";echo;exit 10
fi

ISO=${1}
if [ ! -e "$ISO" ] # iso exists ?
then
  echo;echo ".iso $ISO ?";echo;exit 10
fi

# writing the iso creates 2 partitions
  echo;echo "Write $ISO to $DEVICE"
  dd bs=1M if=$ISO of=$DEVICE oflag=direct status=progress && sync

  PERSIS=3 # write persistence to partition 3
  START=$(du -B1000000 $ISO | cut -f1)
  END=$(lsblk --noheadings --nodeps --bytes --output SIZE $DEVICE)
  END=$(($END / 1000000))
  echo;echo "Persistence on $DEVICE$PERSIS from $START to $END"
  parted $DEVICE mkpart primary $START $END &&
  sleep 1
  mkfs.ext3 -L persistence $DEVICE$PERSIS &&
  mkdir -p /mnt/kaliUSB &&
  mount $DEVICE$PERSIS /mnt/kaliUSB &&
  sh -c "echo '/ union' > /mnt/kaliUSB/persistence.conf" &&
  umount $DEVICE$PERSIS &&
  rm -fr /mnt/kaliUSB/
  fdisk -l $DEVICE

# .......1.........2.........3.........4.........5.........6....


