4 echo "$0, Wrong argument number"
5 echo " launch with $0 <devicename> <binary.img>"
8 if [ ! -f ./password ]; then
9 echo "Create a file ./password that is needed for encrypting luks persistence"
12 if [ $(id -u) != 0 ];then
13 echo "Must run as root"
16 if [ ! -x "$(which parted)" ];then
17 echo "parted executable must be in search path and persmission garanted"
20 if [ ! -x "$(which cryptsetup)" ];then
21 echo "cryptsetup executable must be in search path and persmission garanted"
26 echo "Creating on device $device"
29 # Check for bad block on the device:
30 ###badblocks -c 10240 -s -w -t random -v "${devicel}" || exit 1
33 # Random data on the device:
34 ###dd if=/dev/urandom of="${devicel}" || exit 1
37 # DD THE binary.img to a usb
38 #dd if=binary.img of="${device}" || exit 1
41 img_bytes=$(stat -c %s $2)
42 img_bytes=$((img_bytes+1))
44 parted "${device}" -- mkpart primary "${img_bytes}B" -1 || exit 1
47 cryptsetup --verbose --batch-mode luksFormat "${device}2" <<<password || exit 1
50 cryptsetup luksOpen "${device}2" my_usb <<<password || exit 1
52 # Make FS with label: "persistence"
53 mkfs.ext3 -L persistence /dev/mapper/my_usb || exit 1
56 if [ ! -d "/mnt/my_usb" ];then
57 mkdir -p /mnt/my_usb || exit 1
61 mount /dev/mapper/my_usb /mnt/my_usb/ -o noatime,nodiratime || exit 1
63 # Make the persistence.conf file
64 echo "/ union" > /mnt/persistence.conf || exit 1
67 umount /dev/mapper/my_usb || exit 1
70 cryptsetup luksClose /dev/mapper/my_usb || exit 1