]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/CreatePersistentImg.sh
7 outputfile
=persistence.dat
10 echo 'Usage: CreatePersistentImg.sh [ -s size ] [ -t fstype ] [ -l LABEL ] [ -c CFG ]'
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'
21 if [ "$1" = "-s" ]; then
24 elif [ "$1" = "-t" ]; then
27 elif [ "$1" = "-l" ]; then
30 elif [ "$1" = "-c" ]; then
33 elif [ "$1" = "-o" ]; then
36 elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
48 if [ -z "$label" ]; then
49 echo "The label can NOT be empty."
54 if echo $size | grep -q "^[0-9][0-9]*$"; then
55 if [ $size -le 1 ]; then
56 echo "Invalid size $size"
60 echo "Invalid size $size"
65 # check file system type
66 # nodiscard must be set for ext2/3/4
67 # -K must be set for xfs
68 if echo $fstype | grep -q '^ext[234]$'; then
70 elif [ "$fstype" = "xfs" ]; then
73 echo "unsupported file system $fstype"
77 if [ "$outputdir" != "persistence.dat" ]; then
78 mkdir -p "$(dirname "$outputfile")"
81 # 00->ff avoid sparse file
82 dd if=/dev
/zero bs
=1M count
=$size | tr '\000' '\377' > "$outputfile"
85 freeloop
=$(losetup -f)
87 losetup
$freeloop "$outputfile"
89 mkfs
-t $fstype $fsopt -L $label $freeloop
93 if [ -n "$config" ]; then
94 if [ -d .
/persist_tmp_mnt
]; then
95 rm -rf .
/persist_tmp_mnt
98 mkdir .
/persist_tmp_mnt
99 if mount
$freeloop .
/persist_tmp_mnt
; then
100 echo '/ union' > .
/persist_tmp_mnt
/$config
102 umount .
/persist_tmp_mnt
104 rm -rf .
/persist_tmp_mnt