]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/CreatePersistentImg.sh
7 outputfile
=persistence.dat
10 echo 'Usage: sudo ./CreatePersistentImg.sh [ -s size ] [ -t fstype ] [ -l LABEL ] [ -c CFG ] [ -e ]'
11 echo ' OPTION: (optional)'
12 echo ' -s size in MB, default is 1024'
13 echo ' -t filesystem type, default is ext4 ext2/ext3/ext4/xfs are supported now'
14 echo ' -l label, default is casper-rw'
15 echo ' -c configfile name inside the persistence file. File content is "/ union"'
16 echo ' -o outputfile name, default is persistence.dat'
17 echo ' -e enable encryption, disabled by default (only few distros support this)'
22 if [ "$1" = "-s" ]; then
25 elif [ "$1" = "-t" ]; then
28 elif [ "$1" = "-l" ]; then
31 elif [ "$1" = "-c" ]; then
34 elif [ "$1" = "-o" ]; then
37 elif [ "$1" = "-e" ]; then
38 read -s -p "Encryption passphrase: " passphrase
40 elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
52 if [ -z "$label" ]; then
53 echo "The label can NOT be empty."
58 if echo $size | grep -q "^[0-9][0-9]*$"; then
60 if echo $fstype | grep -q '^xfs$'; then
64 if [ $size -lt $vtMinSize ]; then
65 echo "size too small ($size)"
69 echo "Invalid size $size"
74 # check file system type
75 # nodiscard must be set for ext2/3/4
76 # -K must be set for xfs
77 if echo $fstype | grep -q '^ext[234]$'; then
79 elif [ "$fstype" = "xfs" ]; then
82 echo "unsupported file system $fstype"
86 if [ "$outputdir" != "persistence.dat" ]; then
87 mkdir -p "$(dirname "$outputfile")"
90 # 00->ff avoid sparse file
91 dd if=/dev
/zero bs
=1M count
=$size | tr '\000' '\377' > "$outputfile"
94 freeloop
=$(losetup -f)
96 losetup
$freeloop "$outputfile"
98 if [ ! -z "$passphrase" ]; then
99 printf "$passphrase" | cryptsetup
-q --verbose luksFormat
$freeloop -
100 printf "$passphrase" | cryptsetup
-q --verbose luksOpen
$freeloop persist_decrypted
-
102 freeloop
="/dev/mapper/persist_decrypted"
105 mkfs
-t $fstype $fsopt -L $label $freeloop
109 if [ -n "$config" ]; then
110 if [ -d .
/persist_tmp_mnt
]; then
111 rm -rf .
/persist_tmp_mnt
114 mkdir .
/persist_tmp_mnt
115 if mount
$freeloop .
/persist_tmp_mnt
; then
116 echo '/ union' > .
/persist_tmp_mnt
/$config
118 umount .
/persist_tmp_mnt
120 rm -rf .
/persist_tmp_mnt
123 if [ ! -z "$passphrase" ]; then
124 cryptsetup luksClose
$freeloop