-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathalmalinux.sh
132 lines (108 loc) · 3.62 KB
/
almalinux.sh
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
128
129
130
131
132
#!/bin/bash
#
# AlmaLinux specific functions
#
# (c) 2021, Hetzner Online GmbH
#
# generate_config_mdadm "NIL"
generate_config_mdadm() {
[[ -z "$1" ]] && return 0
local mdadmconf='/etc/mdadm.conf'
{
echo 'DEVICE partitions'
echo 'MAILADDR root'
} > "${FOLD}/hdd${mdadmconf}"
execute_chroot_command "mdadm --examine --scan >> ${mdadmconf}"
return $?
}
# generate_new_ramdisk "NIL"
generate_new_ramdisk() {
[[ -z "$1" ]] && return 0
blacklist_unwanted_and_buggy_kernel_modules
configure_kernel_modules
local dracutfile="${FOLD}/hdd/etc/dracut.conf.d/99-${C_SHORT}.conf"
cat << EOF > "$dracutfile"
### ${COMPANY} - installimage
add_dracutmodules+=" lvm mdraid "
add_drivers+=" raid0 raid1 raid10 raid456 "
hostonly="no"
hostonly_cmdline="no"
lvmconf="yes"
mdadmconf="yes"
persistent_policy="by-uuid"
EOF
# generate initramfs for the latest kernel
execute_chroot_command "dracut -f --kver $(find "${FOLD}/hdd/boot/" -name 'vmlinuz-*' | cut -d '-' -f 2- | sort -V | tail -1)"
return $?
}
#
# generate_config_grub <version>
#
# Generate the GRUB bootloader configuration.
#
generate_config_grub() {
local grubdefconf="${FOLD}/hdd/etc/default/grub"
local exitcode
local grub_cmdline_linux='biosdevname=0 rd.auto=1 consoleblank=0'
# rebuild device map
rm -f "${FOLD}/hdd/boot/grub2/device.map"
build_device_map 'grub2'
if [[ "$IMG_VERSION" -gt 93 ]] && [[ "$IMG_VERSION" -lt 810 ]]; then
grub_cmdline_linux+=' crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M'
else
grub_cmdline_linux+=' crashkernel=auto'
fi
# nomodeset can help avoid issues with some GPUs.
if ((USE_KERNEL_MODE_SETTING == 0)); then
grub_cmdline_linux+=' nomodeset'
fi
# 'noop' scheduler is used in VMs to reduce overhead.
if is_virtual_machine; then
grub_cmdline_linux+=' elevator=noop'
fi
# disable memory-mapped PCI configuration
if has_threadripper_cpu; then
grub_cmdline_linux+=' pci=nommconf'
fi
if [[ "$SYSARCH" == "arm64" ]]; then
grub_cmdline_linux+=' console=ttyAMA0 console=tty0'
fi
sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"${grub_cmdline_linux}\"/" "$grubdefconf"
# set $GRUB_DEFAULT_OVERRIDE to specify custom GRUB_DEFAULT Value ( https://www.gnu.org/software/grub/manual/grub/grub.html#Simple-configuration )
[[ -n "$GRUB_DEFAULT_OVERRIDE" ]] && sed -i "s/^GRUB_DEFAULT=.*/GRUB_DEFAULT=${GRUB_DEFAULT_OVERRIDE}/" "$grubdefconf"
# Generate grub.cfg
if [[ "$IMG_VERSION" -gt 93 ]] && [[ "$IMG_VERSION" -lt 810 ]]; then
# https://docs.rockylinux.org/en/latest/reference/grub2/grub2-mkconfig/
execute_chroot_command 'grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline 2>&1'
else
execute_chroot_command 'grub2-mkconfig -o /boot/grub2/grub.cfg 2>&1'
fi
exitcode=$?
grub2_uuid_bugfix 'almalinux'
return "$exitcode"
}
write_grub() {
local exitcode
if [[ "$UEFI" -eq 1 ]]; then
execute_chroot_command "grub2-install --target=${SYSARCH}-efi --efi-directory=/boot/efi/ --bootloader-id=${IAM} --force --removable --no-nvram 2>&1"
exitcode=$?
else
# Only install grub2 in MBR of all other drives if we use SWRAID
for ((i = 1; i <= COUNT_DRIVES; i++)); do
if [[ "$SWRAID" -eq 1 || "$i" -eq 1 ]]; then
execute_chroot_command "grub2-install --no-floppy --recheck $(eval echo "\$DRIVE${i}") 2>&1"
exitcode=$?
fi
done
fi
return "$exitcode"
}
# os specific functions
run_os_specific_functions() {
randomize_mdadm_array_check_time
# selinux autorelabel if enabled
grep -Eq 'SELINUX=(enforcing|permissive)' "${FOLD}/hdd/etc/sysconfig/selinux" &&
touch "${FOLD}/hdd/.autorelabel"
return 0
}
# vim: ai:ts=2:sw=2:et