-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha
More file actions
127 lines (107 loc) · 3.22 KB
/
a
File metadata and controls
127 lines (107 loc) · 3.22 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#The disk containing the root partition; also see `sudo blkid`
root_disk="UUID=$(findmnt / -o UUID -n)"
# The linux kernel arguments
flags="ro quiet"
prog_name=`basename $0`
boot_dir="/boot"
sd_boot_dir="loader/entries"
sd_boot_path="$boot_dir/efi/$sd_boot_dir"
title=
prefix=
force=0
verbose=0
usage() {
echo "$prog_name [OPTIONS]"
}
help() {
usage
echo
echo "OPTIONS"
echo " -h show this help page"
echo " -f force overwrite"
echo " -v make verbose"
}
while getopts hfv opt; do
case "$opt" in
h) help
exit 0;;
f) force=1;;
v) verbose=1;;
\?) # unknown flag
usage >&2
exit 1;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 0 ]; then
echo >&2 "No extra argument allowed"
exit 1
fi
sd_boot_entry() {
cat <<-EOF
title $title
version $version
linux /$sd_boot_dir/vmlinuz-$version
initrd /$sd_boot_dir/initrd.img-$version
options root=$root_disk $flags
EOF
}
if [ ! -h "/dev/disk/by-uuid/${root_disk#UUID=}" ]; then
echo >&2 "error: root disk '$root_disk' not found"
exit 1
fi
if [ ! -d "$sd_boot_path" ]; then
echo >&2 "error: directory '$sd_boot_path' not found"
exit 1
fi
if [ ! -f /etc/machine-id ]; then
echo >&2 "error: machine id file '/etc/machine-id' not found"
exit 1
fi
prefix="`cat /etc/machine-id`-v"
if [ -f /etc/os-release ]; then
title=`sed -ne '/^PRETTY_NAME=/s/.*"\(.*\)".*/\1/p' /etc/os-release`
else
title=Debian
fi
echo "Updating Systemd boot entries"
# Copy images from the Debian install directory to the EFI partition
find "$boot_dir" -maxdepth 1 -type f -name '*.dpkg-tmp' -prune -o -name 'vmlinuz-*' -exec cp -u {} "$sd_boot_path" \;
find "$boot_dir" -maxdepth 1 -type f -name '*.dpkg-tmp' -prune -o -name 'initrd.img-*' -exec cp -u {} "$sd_boot_path" \;
# Remove files from the EFI if they are missing from the Debian install directory
find "$sd_boot_path" -maxdepth 1 -type f -name 'vmlinuz-*' | while read i; do
kernel="$boot_dir/`basename $i`"
if [ ! -f "$kernel" ]; then
rm -f "$i"
fi
done
find "$sd_boot_path" -maxdepth 1 -type f -name 'initrd.img-*' | while read i; do
initrd="$boot_dir/`basename $i`"
if [ ! -f "$initrd" ]; then
rm -f "$i"
fi
done
# Remove the conf file
find "$sd_boot_path" -maxdepth 1 -type f -name "$prefix*.conf" | sort -Vr | while read i; do
version=`basename $i | sed -e "s/$prefix//; s/.conf$//"`
kernel="$sd_boot_path/vmlinuz-$version"
initrd="$sd_boot_path/initrd.img-$version"
if [ ! -f "$kernel" -o ! -f "$initrd" ]; then
echo "Removing kernel v$version"
rm -f "$i" "$kernel" "$initrd"
fi
done
# Add new kernel entries
find "$boot_dir" -maxdepth 1 -type f -name '*.dpkg-tmp' -prune -o -name 'vmlinuz-*' -print | sort -Vr | while read i; do
version=`basename $i | sed -e 's/vmlinuz-//'`
initrd="$boot_dir/initrd.img-$version"
file="$sd_boot_path/$prefix$version.conf"
echo "Found kernel `basename $i`"
if [ ! -f "$initrd" ]; then
echo "Ignoring $i"
elif [ $force -eq 1 -o ! -f "$file" ]; then
echo "Adding $file"
sd_boot_entry "$version" > "$file"
cp -v $i "$initrd" "$sd_boot_path"
fi
done