I assume:
-You like creating customized debian-live images
-You like using them with persistence to store changes
-You copy the image and create the partitions by hand which is great to learn how to do it but you would like to make it all automatically using a script.
Well you're reading the right post then, but be warned that:
-This script is very simple and written and tested for personal use at home.
-No magic regexes used, just a logical sequence of variables and commands.
-You really must know what you're doing if you decide to try this script. Use at your own risk. The commands in the following script are very useful but if misused they can cause a filesystem mayhem and even destroy important data.
Here it is:
#!/bin/bash
## Script to automatically copy a customized debian live system image to a usb flash drive and create a partition for persistence
############ BE WARNED!!!! ###############
## This script assumes you know what you're doing!!! Using dd, parted and mkfs can end up in data loss!!!
## X = # Letter of your device /dev/sdX could be /dev/sdb or /dev/sdc ...
## In order to know your device name you can run ls -l /dev/disk/by-id
## Y/Z = # Numbers of your partitions. /dev/sdXY could be /dev/sdb1 or /dev/sdc2 ...
X= # For example < c >
Y= # For example <1>
Z= # For example <2>
START= # Number in MB where the partition must start for example <166> or <1024>
END= # Number in MB where the partition must end for example <4007>
cd /directory/where/your/image/is
dd if=binary.img of=/dev/sd$X
umount /dev/sd$X$Y
parted /dev/sd$X mkpart primary $START $END && mkfs.ext2 -L live-rw /dev/sd$X$Z