1
1
#! /bin/bash
2
-
3
2
#
4
3
# AlmaLinux specific functions
5
4
#
6
5
# (c) 2021, Hetzner Online GmbH
7
6
#
8
7
9
-
10
8
# generate_config_mdadm "NIL"
11
9
generate_config_mdadm () {
12
- if [ -n " $1 " ]; then
13
- local mdadmconf=" /etc/mdadm.conf"
14
- {
15
- echo " DEVICE partitions"
16
- echo " MAILADDR root"
17
- } > " $FOLD /hdd$mdadmconf "
18
- execute_chroot_command " mdadm --examine --scan >> $mdadmconf " ; declare -i EXITCODE=$?
19
- return $EXITCODE
20
- fi
10
+ [[ -z " $1 " ]] && return 0
11
+
12
+ local mdadmconf=' /etc/mdadm.conf'
13
+ {
14
+ echo ' DEVICE partitions'
15
+ echo ' MAILADDR root'
16
+ } > " ${FOLD} /hdd${mdadmconf} "
17
+
18
+ execute_chroot_command " mdadm --examine --scan >> ${mdadmconf} "
19
+ return $?
21
20
}
22
21
23
22
# generate_new_ramdisk "NIL"
24
23
generate_new_ramdisk () {
25
- if [ -n " $1 " ]; then
26
-
27
- # pick the latest kernel
28
- VERSION=" $( find " $FOLD /hdd/boot/" -name " vmlinuz-*" | cut -d ' -' -f 2- | sort -V | tail -1) "
29
-
30
- blacklist_unwanted_and_buggy_kernel_modules
31
- configure_kernel_modules
32
-
33
- local dracutfile=" $FOLD /hdd/etc/dracut.conf.d/99-$C_SHORT .conf"
34
- {
35
- echo " ### $COMPANY - installimage"
36
- echo ' add_dracutmodules+=" lvm mdraid "'
37
- echo ' add_drivers+=" raid0 raid1 raid10 raid456 "'
38
- # echo 'early_microcode="no"'
39
- echo ' hostonly="no"'
40
- echo ' hostonly_cmdline="no"'
41
- echo ' lvmconf="yes"'
42
- echo ' mdadmconf="yes"'
43
- echo ' persistent_policy="by-uuid"'
44
- } > " $dracutfile "
45
-
46
- execute_chroot_command " dracut -f --kver $VERSION "
47
- declare -i EXITCODE=$?
48
- return " $EXITCODE "
49
- fi
24
+ [[ -z " $1 " ]] && return 0
25
+
26
+ blacklist_unwanted_and_buggy_kernel_modules
27
+ configure_kernel_modules
28
+
29
+ local dracutfile=" ${FOLD} /hdd/etc/dracut.conf.d/99-${C_SHORT} .conf"
30
+ cat << EOF > "$dracutfile "
31
+ ### ${COMPANY} - installimage
32
+ add_dracutmodules+=" lvm mdraid "
33
+ add_drivers+=" raid0 raid1 raid10 raid456 "
34
+ hostonly="no"
35
+ hostonly_cmdline="no"
36
+ lvmconf="yes"
37
+ mdadmconf="yes"
38
+ persistent_policy="by-uuid"
39
+ EOF
40
+
41
+ # generate initramfs for the latest kernel
42
+ execute_chroot_command " dracut -f --kver $( find " ${FOLD} /hdd/boot/" -name ' vmlinuz-*' | cut -d ' -' -f 2- | sort -V | tail -1) "
43
+ return $?
50
44
}
51
45
52
46
#
@@ -55,91 +49,82 @@ generate_new_ramdisk() {
55
49
# Generate the GRUB bootloader configuration.
56
50
#
57
51
generate_config_grub () {
58
- [ -n " $1 " ] || return
59
- # we should not have to do anything, as grubby (new-kernel-pkg) should have
60
- # already generated a grub.conf
61
- # even though grub2-mkconfig will generate a device.map on the fly, the
62
- # anaconda installer still creates this
63
- DMAPFILE=" $FOLD /hdd/boot/grub2/device.map"
64
- [ -f " $DMAPFILE " ] && rm " $DMAPFILE "
65
-
66
- local -i i=0
67
- for (( i= 1 ; i<= COUNT_DRIVES; i++ )) ; do
68
- local j; j=" $(( i - 1 )) "
69
- local disk; disk=" $( eval echo " \$ DRIVE$i " ) "
70
- echo " (hd$j ) $disk " >> " $DMAPFILE "
71
- done
72
- debug ' # device map:'
73
- cat " $DMAPFILE " | debugoutput
74
-
75
- local elevator=' '
76
- if is_virtual_machine; then
77
- elevator=' elevator=noop'
52
+ local grubdefconf=" ${FOLD} /hdd/etc/default/grub"
53
+ local exitcode
54
+ local grub_cmdline_linux=' biosdevname=0 rd.auto=1 consoleblank=0'
55
+
56
+ # rebuild device map
57
+ rm -f " ${FOLD} /hdd/boot/grub2/device.map"
58
+ build_device_map ' grub2'
59
+
60
+ if [[ " $IMG_VERSION " -gt 93 ]] && [[ " $IMG_VERSION " -lt 810 ]]; then
61
+ grub_cmdline_linux+=' crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M'
62
+ else
63
+ grub_cmdline_linux+=' crashkernel=auto'
78
64
fi
79
65
80
- local grub_cmdline_linux= ' biosdevname=0 crashkernel=auto '
81
- is_virtual_machine && grub_cmdline_linux+= ' elevator=noop '
82
- (( USE_KERNEL_MODE_SETTING == 0 )) && grub_linux_default +=' nomodeset'
83
- grub_cmdline_linux+= ' rd.auto=1 consoleblank=0 '
66
+ # nomodeset can help avoid issues with some GPUs.
67
+ if (( USE_KERNEL_MODE_SETTING == 0 )) ; then
68
+ grub_cmdline_linux +=' nomodeset'
69
+ fi
84
70
71
+ # 'noop' scheduler is used in VMs to reduce overhead.
72
+ if is_virtual_machine; then
73
+ grub_cmdline_linux+=' elevator=noop'
74
+ fi
75
+
76
+ # disable memory-mapped PCI configuration
85
77
if has_threadripper_cpu; then
86
78
grub_cmdline_linux+=' pci=nommconf'
87
79
fi
88
80
89
- if [ " $SYSARCH " == " arm64" ]; then
81
+ if [[ " $SYSARCH " == " arm64" ] ]; then
90
82
grub_cmdline_linux+=' console=ttyAMA0 console=tty0'
91
83
fi
92
84
93
- sed -i " s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\" $grub_cmdline_linux \" /" " $FOLD /hdd/etc/default/grub"
94
-
95
- if (( IMG_VERSION > 85 )) && (( IMG_VERSION <= 92 )) && [[ -z " $GRUB_DEFAULT_OVERRIDE " ]]; then
96
- GRUB_DEFAULT_OVERRIDE=' saved'
97
- fi
85
+ sed -i " s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\" ${grub_cmdline_linux} \" /" " $grubdefconf "
98
86
99
- if [[ -n " $GRUB_DEFAULT_OVERRIDE " ]]; then sed -i " s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=$GRUB_DEFAULT_OVERRIDE /" " $FOLD /hdd/etc/default/grub" ; fi
87
+ # set $GRUB_DEFAULT_OVERRIDE to specify custom GRUB_DEFAULT Value ( https://www.gnu.org/software/grub/manual/grub/grub.html#Simple-configuration )
88
+ [[ -n " $GRUB_DEFAULT_OVERRIDE " ]] && sed -i " s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=${GRUB_DEFAULT_OVERRIDE} /" " $grubdefconf "
100
89
101
- rm -f " $FOLD /hdd/boot/grub2/grub.cfg"
102
- if [ " $UEFI " -eq 1 ]; then
103
- execute_chroot_command " grub2-mkconfig -o /boot/efi/EFI/almalinux/grub.cfg 2>&1" ; declare -i EXITCODE=" $? "
90
+ # Generate grub.cfg
91
+ if [[ " $IMG_VERSION " -gt 93 ]] && [[ " $IMG_VERSION " -lt 810 ]]; then
92
+ # https://docs.rockylinux.org/en/latest/reference/grub2/grub2-mkconfig/
93
+ execute_chroot_command ' grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline 2>&1'
104
94
else
105
- execute_chroot_command " grub2-mkconfig -o /boot/grub2/grub.cfg 2>&1" ; declare -i EXITCODE= " $? "
95
+ execute_chroot_command ' grub2-mkconfig -o /boot/grub2/grub.cfg 2>&1'
106
96
fi
107
- uuid_bugfix
108
- return " $EXITCODE "
97
+ exitcode=$?
98
+
99
+ grub2_uuid_bugfix ' almalinux'
100
+ return " $exitcode "
109
101
}
110
102
103
+
111
104
write_grub () {
112
- if [ " $UEFI " -eq 1 ]; then
113
- # we must NOT use grub2-install here. This will replace the prebaked
114
- # grubx64.efi (which looks for grub.cfg in ESP) with a new one, which
115
- # looks for in in /boot/grub2 (which may be more difficult to read)
116
- rm -f " $FOLD /hdd/boot/grub2/grubenv"
117
- execute_chroot_command " ln -s /boot/efi/EFI/almalinux/grubenv /boot/grub2/grubenv"
118
- declare -i EXITCODE=$?
105
+ local exitcode
106
+ if [[ " $UEFI " -eq 1 ]]; then
107
+ execute_chroot_command " grub2-install --target=${SYSARCH} -efi --efi-directory=/boot/efi/ --bootloader-id=${IAM} --force --removable --no-nvram 2>&1"
108
+ exitcode=$?
119
109
else
120
- # only install grub2 in mbr of all other drives if we use swraid
121
- for (( i= 1 ; i<= COUNT_DRIVES; i++ )) ; do
122
- if [ " $SWRAID " -eq 1 ] || [ " $i " -eq 1 ] ; then
123
- local disk; disk=" $( eval echo " \$ DRIVE" $i ) "
124
- execute_chroot_command " grub2-install --no-floppy --recheck $disk 2>&1"
125
- declare -i EXITCODE=$?
110
+ # Only install grub2 in MBR of all other drives if we use SWRAID
111
+ for (( i = 1 ; i <= COUNT_DRIVES; i++ )) ; do
112
+ if [[ " $SWRAID " -eq 1 || " $i " -eq 1 ]]; then
113
+ execute_chroot_command " grub2-install --no-floppy --recheck $( eval echo " \$ DRIVE${i} " ) 2>&1"
114
+ exitcode=$?
126
115
fi
127
116
done
128
117
fi
129
-
130
- return " $EXITCODE "
118
+ return " $exitcode "
131
119
}
132
120
133
- #
134
121
# os specific functions
135
- # for purpose of e.g. debian-sys-maint mysql user password in debian/ubuntu LAMP
136
- #
137
122
run_os_specific_functions () {
138
123
randomize_mdadm_array_check_time
139
124
140
125
# selinux autorelabel if enabled
141
- egrep -q " SELINUX=(enforcing|permissive)" " $FOLD /hdd/etc/sysconfig/selinux" &&
142
- touch " $FOLD /hdd/.autorelabel"
126
+ grep -Eq ' SELINUX=(enforcing|permissive)' " ${ FOLD} /hdd/etc/sysconfig/selinux" &&
127
+ touch " ${ FOLD} /hdd/.autorelabel"
143
128
144
129
return 0
145
130
}
0 commit comments