1 # This file is part of the 'dragora-installer'.
3 # Purpose: Swap detector, formatter.
5 # A function to produce the fstab entry for the physical swap partition
8 printf '%-43s %-14s %-12s %-16s %-3s %s\n' \
9 "$1" "swap" "swap" "defaults" "0" "0" >> "${SUBTMPDIR}/fstab"
12 # Get and print device size
15 lsblk --noheadings --nodeps --output SIZE "$1"
18 # Add device names to the checklist (to be shown)
21 while IFS= read -r line
23 echo "\"${line}\" \"$(get_size $line)\" ON \\" >> "$2"
27 echo " 2> \${SUBTMPDIR}/$3" >> "$2"
30 ### Detection, addition of active and inactive swap devices
32 swaplist="$(blkid -s TYPE | awk -F ":" '/swap/{ print $1 }')"
34 if test -z "$swaplist"
37 --backtitle "\\ZbSwap detection" \
38 --title "NO SWAP PARTITION DETECTED" \
40 "No swap partition has been detected.
42 Setting up a swap partition is recommended because
43 it will enable the system to use available physical
44 memory (RAM) more efficiently and also provide a
45 safeguard in situations where RAM is exhausted.
47 If you want to make use of hibernation (suspend to
48 disk), a swap partition of sufficient size is
51 Would you like to proceed without a swap partition?" 16 55 || \
55 Please create a swap partition using fdisk(8) or cfdisk(8).
56 Then re-run the installer to give it the proper formatting.
58 You can also use mkswap(8) and swapon(8) to format and
59 activate the partition in advance.
63 unset add_fstabEntry get_size set_checklist swaplist
67 rm -f "${SUBTMPDIR}/MakeSwap_active.list" \
68 "${SUBTMPDIR}/MakeSwap_inactive.list"
69 for device in $swaplist
71 if swapon --noheadings --show=NAME | grep -q "$device"
73 echo "$device" >> "${SUBTMPDIR}/MakeSwap_active.list"
75 echo "$device" >> "${SUBTMPDIR}/MakeSwap_inactive.list"
78 unset -v device swaplist
80 ### ^ End Of 'Detection, addition of active and inactive swap devices'
82 ### Check for active swap devices
84 if test -s "${SUBTMPDIR}/MakeSwap_active.list"
86 # Compose output file to be shown
90 ' --backtitle "\\ZbActive Swap devices" \' \
91 ' --title "ACTIVE SWAP DEVICES" \' \
92 ' --nocancel --cr-wrap --checklist \' \
93 '"The following swap devices have already been activated:' \
95 'By default all partitions are marked to be added to the' \
96 'file system representation table (/etc/fstab) in order to' \
97 'be loaded at boot time. You can deselect the partition(s)' \
98 'you do not want to add or load at system startup using' \
99 'the \\Z3[Space]\\Zn key, then press \\Z3[Enter]\Zn to continue." \
100 16 65 3 \' > "${SUBTMPDIR}/MakeSwap_active"
102 set_checklist "${SUBTMPDIR}/MakeSwap_active.list" \
103 "${SUBTMPDIR}/MakeSwap_active" return-MakeSwap_active
106 if test -s "${SUBTMPDIR}/MakeSwap_active"
108 . "${SUBTMPDIR}/MakeSwap_active"
110 if test -s "${SUBTMPDIR}/return-MakeSwap_active"
112 # Append new line for reading
113 echo "" >> "${SUBTMPDIR}/return-MakeSwap_active"
115 IFS= read -r REPLY < "${SUBTMPDIR}/return-MakeSwap_active" || exit 2;
119 add_fstabEntry "$device"
122 unset -v REPLY device
126 ### ^ End Of 'Check for active swap devices'
128 ### Check for inactive swap devices
130 if test -s "${SUBTMPDIR}/MakeSwap_inactive.list"
132 # Compose output file to be shown
135 'dialog --colors \' \
136 ' --backtitle "\\ZbInactive Swap devices" \' \
137 ' --title "INACTIVE SWAP DEVICES" \' \
138 ' --nocancel --cr-wrap --checklist \' \
139 '"The following swap partitions has been detected:' \
141 'By default all partitions found will be formatted and added' \
142 'to the file system representation table (/etc/fstab) in order' \
143 'to be loaded at boot time. You can deselect the partition(s)' \
144 'you do not want to format or load at system startup using' \
145 'the \\Z3[Space]\\Zn key, then press \\Z3[Enter]\Zn to continue." \
146 16 65 3 \' > "${SUBTMPDIR}/MakeSwap_inactive"
148 set_checklist "${SUBTMPDIR}/MakeSwap_inactive.list" \
149 "${SUBTMPDIR}/MakeSwap_inactive" return-MakeSwap_inactive
152 if test -s "${SUBTMPDIR}/MakeSwap_inactive"
154 . "${SUBTMPDIR}/MakeSwap_inactive"
156 if test -s "${SUBTMPDIR}/return-MakeSwap_inactive"
158 # Append new line for reading
159 echo "" >> "${SUBTMPDIR}/return-MakeSwap_inactive"
161 IFS= read -r REPLY < "${SUBTMPDIR}/return-MakeSwap_inactive" || exit 2;
165 # Set up temporary random files related to the menu
166 tempfile="${SUBTMPDIR}/return_MakeSwap_format${RANDOM-0}$$"
167 progressfile="${tempfile}.progress"
170 --backtitle "\\ZbInactive Swap device" \
171 --title "SWAP FORMAT FOR $device" \
172 --ok-label "Format" \
173 --cancel-label "Ignore & Continue" \
174 --cr-wrap --checklist \
175 "A swap device has been chosen.
177 We offer the possibility to format it properly,
178 as well as you can simply ignore this part and
179 continue if you previously formatted it:
181 Device name: $device [$(get_size $device)]" 14 51 1 \
182 "$device" "Check for bad blocks (slow)" off \
183 2> $tempfile || continue;
185 if test -s "$tempfile"
187 slowcmd "mkswap -c $device" "$progressfile" | \
189 --backtitle "\\ZbSwap format for $device" \
191 --sleep 3 --progressbox \
192 "Formatting $device - Checking for bad blocks..." $(( LINES / 2 )) $COLUMNS
194 slowcmd "mkswap $device" "$progressfile" | \
196 --backtitle "\\ZbSwap format for $device" \
198 --sleep 3 --progressbox \
199 "Formatting $device - No bad blocks check." $(( LINES / 2 )) $COLUMNS
202 # Activate device, adding the entry for the fstab
204 slowcmd "swapon -v -f $device" "$progressfile" | \
206 --backtitle "\\ZbSwap activation for $device" \
208 --sleep 3 --progressbox \
209 "Activating swap device $device ..." $(( LINES / 2 )) $COLUMNS
210 add_fstabEntry "$device"
213 unset -v REPLY device tempfile progressfile
217 ### ^ End Of 'Check for inactive swap devices'
219 unset -f add_fstabEntry get_size set_checklist