-
Notifications
You must be signed in to change notification settings - Fork 144
/
centos.sh
138 lines (113 loc) · 3.8 KB
/
centos.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
133
134
135
136
137
138
#!/bin/bash
#
# CentOS specific functions
#
# (c) 2008-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 exitcode
local grub_cmdline_linux='biosdevname=0 rd.auto=1 consoleblank=0 crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M'
# rebuild device map
rm -f "${FOLD}/hdd/boot/grub2/device.map"
build_device_map 'grub2'
# 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}\"/" "${FOLD}/hdd/etc/default/grub"
# 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}/" "${FOLD}/hdd/etc/default/grub"
# 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'
exitcode=$?
grub2_uuid_bugfix 'centos'
return "$exitcode"
}
write_grub() {
if [[ "$UEFI" -eq 1 ]]; then
execute_chroot_command "grub2-install --target=${SYSARCH}-efi --efi-directory=/boot/efi/ --force --removable --no-nvram 2>&1"
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"
fi
done
fi
return $?
}
#
# os specific functions
# for purpose of e.g. debian-sys-maint mysql user password in debian/ubuntu LAMP
#
run_os_specific_functions() {
randomize_mdadm_array_check_time
if [[ "$IMG_VERSION" -lt 90 ]]; then
execute_chroot_command 'chkconfig iptables off'
execute_chroot_command 'chkconfig ip6tables off'
is_plesk_install || execute_chroot_command 'chkconfig postfix off'
fi
#
# setup env in cpanel image
#
debug "# Testing and setup of cpanel image"
if [[ -f "${FOLD}/hdd/etc/wwwacct.conf" && -f "${FOLD}/hdd/etc/cpupdate.conf" ]]; then
grep -q -i cpanel <<< "$IMAGE_FILE" && {
setup_cpanel || return 1
}
fi
# selinux autorelabel if enabled
if grep -Eq 'SELINUX=(enforcing|permissive)' "${FOLD}/hdd/etc/sysconfig/selinux"; then
touch "${FOLD}/hdd/.autorelabel"
fi
mkdir -p "${FOLD}/hdd/var/run/netreport"
return 0
}
# vim: ai:ts=2:sw=2:et