-
Notifications
You must be signed in to change notification settings - Fork 36
/
autopart-hibernation.ks.in
72 lines (60 loc) · 2.19 KB
/
autopart-hibernation.ks.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#test name: autopart-hibernation
%ksappend repos/default.ks
zerombr
clearpart --all --initlabel
autopart --hibernation
%ksappend common/common_no_storage_and_payload.ks
%ksappend payload/default_packages.ks
%post
err=0
# Test if swap is equal or greater than ram size
# Path to swap partition
swap_device="$(blkid --match-token TYPE=\"swap\" | grep -v /dev/zram)"
if [ "$(echo "$swap_device" | wc -l)" -ne 1 ]; then
echo "Too many swap devices were created" >> /root/RESULT
err=1
fi
swap_device_uuid="$(echo "$swap_device" | sed -e 's/.* UUID="\([^ ]*\)".*/\1/')"
swap_device_path="$(echo "$swap_device" | cut -d ":" -f1)"
if [ -z "$swap_device_uuid" ] || [ -z "$swap_device_path" ]; then
echo "SWAP partition was not created" >> /root/RESULT
err=1
elif [ -z "$(grep $swap_device_uuid /etc/fstab)" ] && [ -z "$(grep $swap_device_path /etc/fstab)" ]; then
echo "SWAP is missing from fstab" >> /root/RESULT
err=1
fi
# Test if Grub is configured to resume from sleep.
grub_path="/etc/default/grub"
grub_param="GRUB_CMDLINE_LINUX"
cmdline_uuid="$(grep $grub_param $grub_path | grep -o "resume=UUID=$swap_device_uuid")"
cmdline_path="$(grep $grub_param $grub_path | grep -o "resume=$swap_device_path")"
if [ -z "$cmdline_uuid" ] && [ -z "$cmdline_path" ]; then
echo "\"resume\" parameter is missing from $grub_param in $grub_path" >> /root/RESULT
err=1
fi
# Mount swap so we can accurately measure it's size.
swapon "$swap_device"
# Size of swap in bytes
swap_size=$(swapon --raw --bytes --noheadings | grep -v "zram" | cut -d ' ' -f 3)
# Size of total memory in bytes
mem_size="$(free -b | awk '$1 == "Mem:" {print $2}')"
# Check if swap is large enough for current memory configuration
if [ -z "$swap_size" ]; then
swap_size=0
fi
if [ "$swap_size" -le "$mem_size" ]; then
echo "SWAP of size ${swap_size}B is too small to hibernate with ${mem_size}B of memory" >> /root/RESULT
err=1
fi
if [ "$err" -eq 0 ]; then
echo "SUCCESS" >> /root/RESULT
else
echo "blkid:" >> /root/RESULT
blkid >> /root/RESULT
echo "fstab:" >> /root/RESULT
cat /etc/fstab | sed -e '/^$/d' -e '/^#/d' >> /root/RESULT
echo "grub:" >> /root/RESULT
cat $grub_path >> /root/RESULT
fi
exit $err
%end