--- /dev/null
+#!/bin/bash
+
+if [ $# != 2 ];then
+ echo "$0, Wrong argument number"
+ echo " launch with $0 <devicename> <binary.img>"
+ exit 1
+fi
+if [ ! -f ./password ]; then
+ echo "Create a file ./password that is needed for encrypting luks persistence"
+ exit 1
+fi
+if [ $(id -u) != 0 ];then
+ echo "Must run as root"
+ exit 1
+fi
+if [ ! -x $(which parted) ];then
+ echo "parted executable must be in search path and persmission garanted"
+ exit 1
+fi
+if [ ! -x $(which cryptsetup) ];then
+ echo "cryptsetup executable must be in search path and persmission garanted"
+ exit 1
+fi
+device=$1
+
+echo "Creating on device $device"
+sleep 3
+
+# Check for bad block on the device:
+###badblocks -c 10240 -s -w -t random -v "${devicel}" || exit 1
+
+
+# Random data on the device:
+###dd if=/dev/urandom of="${devicel}" || exit 1
+
+
+# DD THE binary.img to a usb
+#dd if=binary.img of="${device}" || exit 1
+
+# Make the partition
+img_bytes=$(stat -c %s $2)
+img_bytes=$((img_bytes+1))
+
+parted "${device}" -- mkpart primary "${img_bytes}B" -1 || exit 1
+
+# Ecnrypt partition
+cryptsetup --verbose --batch-mode luksFormat "${device}2" <<<password || exit 1
+
+# Open partition
+cryptsetup luksOpen "${device}2" my_usb <<<password || exit 1
+
+# Make FS with label: "persistence"
+mkfs.ext3 -L persistence /dev/mapper/my_usb || exit 1
+
+# Make a mount point
+if [ ! -d "/mnt/my_usb" ];then
+ mkdir -p /mnt/my_usb || exit 1
+fi
+
+# Mount the partition
+mount /dev/mapper/my_usb /mnt/my_usb/ -o noatime,nodiratime || exit 1
+
+# Make the persistence.conf file
+echo "/ union" > /mnt/persistence.conf || exit 1
+
+# Umount
+umount /dev/mapper/my_usb || exit 1
+
+# Close LUKS
+cryptsetup luksClose /dev/mapper/my_usb || exit 1
+
+echo "All done."