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 and addition of inactive/active swap devices
32 swaplist="$(fdisk -l | awk '/Linux 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?" 17 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}$$"
169 --backtitle "\\ZbInactive Swap device" \
170 --title "SWAP FORMAT FOR $device" \
171 --ok-label "Format" \
172 --cancel-label "Ignore & Continue" \
173 --cr-wrap --checklist \
174 "A swap device has been chosen.
176 We offer the possibility to format it properly,
177 as well as you can simply ignore this part and
178 continue if you previously formatted it:
180 Device name: $device [$(get_size $device)]" 14 51 1 \
181 "$device" "Check for bad blocks (slow)" off \
182 2> $tempfile || continue;
186 echo "Making swap device $device ..."
189 if test -s "$tempfile"
197 echo "Activating swap device (${device}) ..."
200 swapon -v -f "$device"
202 add_fstabEntry "$device"
205 unset -v REPLY device tempfile
209 ### ^ End Of 'Check for inactive swap devices'
211 unset -f add_fstabEntry get_size set_checklist