]>
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)'
28 if [ $uid -ne 0 ]; then
29 print_err
"Please use sudo or run the script as root."
34 if [ "$1" = "-s" ]; then
37 elif [ "$1" = "-t" ]; then
40 elif [ "$1" = "-l" ]; then
43 elif [ "$1" = "-c" ]; then
46 elif [ "$1" = "-o" ]; then
49 elif [ "$1" = "-e" ]; then
50 read -s -p "Encryption passphrase: " passphrase
52 elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
64 if [ -z "$label" ]; then
65 echo "The label can NOT be empty."
70 if echo $size | grep -q "^[0-9][0-9]*$"; then
72 if echo $fstype | grep -q '^xfs$'; then
76 if [ $size -lt $vtMinSize ]; then
77 echo "size too small ($size)"
81 echo "Invalid size $size"
86 # check file system type
87 # nodiscard must be set for ext2/3/4
88 # -K must be set for xfs
89 if echo $fstype | grep -q '^ext[234]$'; then
91 elif [ "$fstype" = "xfs" ]; then
94 echo "unsupported file system $fstype"
98 if [ "$outputdir" != "persistence.dat" ]; then
99 mkdir -p "$(dirname "$outputfile")"
102 # 00->ff avoid sparse file
103 dd if=/dev
/zero bs
=1M count
=$size | tr '\000' '\377' > "$outputfile"
106 freeloop
=$(losetup -f)
108 losetup
$freeloop "$outputfile"
110 if [ ! -z "$passphrase" ]; then
111 printf "$passphrase" | cryptsetup
-q --verbose luksFormat
$freeloop -
112 printf "$passphrase" | cryptsetup
-q --verbose luksOpen
$freeloop persist_decrypted
-
114 freeloop
="/dev/mapper/persist_decrypted"
117 mkfs
-t $fstype $fsopt -L $label $freeloop
121 if [ -n "$config" ]; then
122 if [ -d .
/persist_tmp_mnt
]; then
123 rm -rf .
/persist_tmp_mnt
126 mkdir .
/persist_tmp_mnt
127 if mount
$freeloop .
/persist_tmp_mnt
; then
128 echo '/ union' > .
/persist_tmp_mnt
/$config
130 umount .
/persist_tmp_mnt
132 rm -rf .
/persist_tmp_mnt
135 if [ ! -z "$passphrase" ]; then
136 cryptsetup luksClose
$freeloop