2021-04-28 14:06:52 +00:00
|
|
|
# shellcheck source=./scripts/protection.sh
|
2021-04-19 22:51:48 +00:00
|
|
|
source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1
|
2019-12-31 14:28:42 -01:00
|
|
|
|
|
|
|
|
|
|
|
################################################
|
|
|
|
# Functions
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function install_stage3() {
|
2019-12-31 14:28:42 -01:00
|
|
|
prepare_installation_environment
|
2020-04-21 12:33:42 +00:00
|
|
|
apply_disk_configuration
|
2019-12-31 14:28:42 -01:00
|
|
|
download_stage3
|
|
|
|
extract_stage3
|
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function configure_base_system() {
|
2023-10-13 00:47:14 +00:00
|
|
|
if [[ $MUSL == "true" ]]; then
|
|
|
|
einfo "Installing musl-locales"
|
|
|
|
try emerge --verbose sys-apps/musl-locales
|
|
|
|
else
|
2023-10-12 23:18:00 +00:00
|
|
|
einfo "Generating locales"
|
|
|
|
echo "$LOCALES" > /etc/locale.gen \
|
|
|
|
|| die "Could not write /etc/locale.gen"
|
|
|
|
locale-gen \
|
|
|
|
|| die "Could not generate locales"
|
2023-10-13 00:47:14 +00:00
|
|
|
fi
|
2023-10-12 23:18:00 +00:00
|
|
|
|
2023-10-13 00:47:14 +00:00
|
|
|
if [[ $SYSTEMD == "true" ]]; then
|
2020-10-03 17:04:55 +00:00
|
|
|
einfo "Setting machine-id"
|
|
|
|
systemd-machine-id-setup \
|
|
|
|
|| die "Could not setup systemd machine id"
|
|
|
|
|
|
|
|
# Set hostname
|
|
|
|
einfo "Selecting hostname"
|
2020-11-26 11:29:47 -01:00
|
|
|
echo "$HOSTNAME" > /etc/hostname \
|
|
|
|
|| die "Could not write /etc/hostname"
|
|
|
|
|
|
|
|
# Set keymap
|
|
|
|
einfo "Selecting keymap"
|
|
|
|
echo "KEYMAP=$KEYMAP" > /etc/vconsole.conf \
|
|
|
|
|| die "Could not write /etc/vconsole.conf"
|
|
|
|
|
2021-05-02 13:35:20 +00:00
|
|
|
# Set locale
|
|
|
|
einfo "Selecting locale"
|
|
|
|
echo "LANG=$LOCALE" > /etc/locale.conf \
|
|
|
|
|| die "Could not write /etc/locale.conf"
|
|
|
|
|
2020-11-26 11:29:47 -01:00
|
|
|
einfo "Selecting timezone"
|
|
|
|
ln -sfn "../usr/share/zoneinfo/$TIMEZONE" /etc/localtime \
|
|
|
|
|| die "Could not change /etc/localtime link"
|
2020-10-03 17:04:55 +00:00
|
|
|
else
|
|
|
|
# Set hostname
|
|
|
|
einfo "Selecting hostname"
|
|
|
|
sed -i "/hostname=/c\\hostname=\"$HOSTNAME\"" /etc/conf.d/hostname \
|
|
|
|
|| die "Could not sed replace in /etc/conf.d/hostname"
|
|
|
|
|
|
|
|
# Set timezone
|
|
|
|
einfo "Selecting timezone"
|
|
|
|
echo "$TIMEZONE" > /etc/timezone \
|
|
|
|
|| die "Could not write /etc/timezone"
|
2022-12-20 10:51:25 -01:00
|
|
|
chmod 644 /etc/timezone \
|
|
|
|
|| die "Could not set correct permissions for /etc/timezone"
|
2020-10-03 17:04:55 +00:00
|
|
|
try emerge -v --config sys-libs/timezone-data
|
|
|
|
|
|
|
|
# Set keymap
|
|
|
|
einfo "Selecting keymap"
|
|
|
|
sed -i "/keymap=/c\\keymap=\"$KEYMAP\"" /etc/conf.d/keymaps \
|
|
|
|
|| die "Could not sed replace in /etc/conf.d/keymaps"
|
|
|
|
|
|
|
|
# Set locale
|
|
|
|
einfo "Selecting locale"
|
|
|
|
try eselect locale set "$LOCALE"
|
|
|
|
fi
|
2020-01-03 21:48:49 -01:00
|
|
|
|
|
|
|
# Update environment
|
|
|
|
env_update
|
2020-01-13 20:56:16 -01:00
|
|
|
}
|
2019-12-31 14:28:42 -01:00
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function configure_portage() {
|
2020-04-23 20:31:18 +00:00
|
|
|
# Prepare /etc/portage for autounmask
|
|
|
|
mkdir_or_die 0755 "/etc/portage/package.use"
|
|
|
|
touch_or_die 0644 "/etc/portage/package.use/zz-autounmask"
|
|
|
|
mkdir_or_die 0755 "/etc/portage/package.keywords"
|
|
|
|
touch_or_die 0644 "/etc/portage/package.keywords/zz-autounmask"
|
2022-09-28 15:47:19 +00:00
|
|
|
touch_or_die 0644 "/etc/portage/package.license"
|
2020-04-23 20:31:18 +00:00
|
|
|
|
2020-11-26 10:44:59 -01:00
|
|
|
if [[ $SELECT_MIRRORS == "true" ]]; then
|
|
|
|
einfo "Temporarily installing mirrorselect"
|
|
|
|
try emerge --verbose --oneshot app-portage/mirrorselect
|
|
|
|
|
|
|
|
einfo "Selecting fastest portage mirrors"
|
|
|
|
mirrorselect_params=("-s" "4" "-b" "10")
|
|
|
|
[[ $SELECT_MIRRORS_LARGE_FILE == "true" ]] \
|
|
|
|
&& mirrorselect_params+=("-D")
|
|
|
|
try mirrorselect "${mirrorselect_params[@]}"
|
2022-04-16 13:26:31 +00:00
|
|
|
fi
|
2020-11-26 10:44:59 -01:00
|
|
|
|
2022-04-16 13:26:31 +00:00
|
|
|
chmod 644 /etc/portage/make.conf \
|
|
|
|
|| die "Could not chmod 644 /etc/portage/make.conf"
|
2020-04-23 20:31:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 23:47:07 +00:00
|
|
|
function enable_sshd() {
|
|
|
|
einfo "Installing and enabling sshd"
|
2020-11-25 12:45:46 -01:00
|
|
|
install -m0600 -o root -g root "$GENTOO_INSTALL_REPO_DIR/contrib/sshd_config" /etc/ssh/sshd_config \
|
2020-01-13 20:56:16 -01:00
|
|
|
|| die "Could not install /etc/ssh/sshd_config"
|
2020-10-10 15:08:54 +00:00
|
|
|
enable_service sshd
|
2022-06-30 23:47:07 +00:00
|
|
|
}
|
2021-05-02 13:29:21 +00:00
|
|
|
|
2022-06-30 23:47:07 +00:00
|
|
|
function install_authorized_keys() {
|
2021-05-02 13:29:21 +00:00
|
|
|
mkdir_or_die 0700 "/root/"
|
|
|
|
mkdir_or_die 0700 "/root/.ssh"
|
|
|
|
|
|
|
|
if [[ -n "$ROOT_SSH_AUTHORIZED_KEYS" ]]; then
|
|
|
|
einfo "Adding authorized keys for root"
|
|
|
|
touch_or_die 0600 "/root/.ssh/authorized_keys"
|
2022-02-10 12:36:30 -01:00
|
|
|
echo "$ROOT_SSH_AUTHORIZED_KEYS" > "/root/.ssh/authorized_keys" \
|
2021-05-02 13:29:21 +00:00
|
|
|
|| die "Could not add ssh key to /root/.ssh/authorized_keys"
|
|
|
|
fi
|
2020-01-13 20:56:16 -01:00
|
|
|
}
|
2020-01-04 10:55:31 -01:00
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function generate_initramfs() {
|
2020-04-24 21:02:00 +00:00
|
|
|
local output="$1"
|
|
|
|
|
|
|
|
# Generate initramfs
|
|
|
|
einfo "Generating initramfs"
|
|
|
|
|
|
|
|
local modules=()
|
|
|
|
[[ $USED_RAID == "true" ]] \
|
2020-04-25 13:27:32 +00:00
|
|
|
&& modules+=("mdraid")
|
2020-04-24 21:02:00 +00:00
|
|
|
[[ $USED_LUKS == "true" ]] \
|
2020-04-25 13:27:32 +00:00
|
|
|
&& modules+=("crypt crypt-gpg")
|
2020-10-11 19:45:26 +00:00
|
|
|
[[ $USED_BTRFS == "true" ]] \
|
|
|
|
&& modules+=("btrfs")
|
2021-05-30 19:13:27 +00:00
|
|
|
[[ $USED_ZFS == "true" ]] \
|
|
|
|
&& modules+=("zfs")
|
2020-04-24 21:02:00 +00:00
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
local kver
|
|
|
|
kver="$(readlink /usr/src/linux)" \
|
|
|
|
|| die "Could not figure out kernel version from /usr/src/linux symlink."
|
2020-04-24 21:02:00 +00:00
|
|
|
kver="${kver#linux-}"
|
|
|
|
|
2022-06-30 23:47:07 +00:00
|
|
|
dracut_opts=()
|
|
|
|
if [[ $SYSTEMD == "true" && $SYSTEMD_INITRAMFS_SSHD == "true" ]]; then
|
2022-07-01 17:55:13 +00:00
|
|
|
cd /tmp || die "Could not change into /tmp"
|
2022-06-30 23:47:07 +00:00
|
|
|
try git clone https://github.com/gsauthof/dracut-sshd
|
|
|
|
try cp -r dracut-sshd/46sshd /usr/lib/dracut/modules.d
|
|
|
|
sed -e 's/^Type=notify/Type=simple/' \
|
|
|
|
-e 's@^\(ExecStart=/usr/sbin/sshd\) -D@\1 -e -D@' \
|
|
|
|
-i /usr/lib/dracut/modules.d/46sshd/sshd.service \
|
|
|
|
|| die "Could not replace sshd options in service file"
|
|
|
|
dracut_opts+=("--install" "/etc/systemd/network/20-wired.network")
|
|
|
|
modules+=("systemd-networkd")
|
|
|
|
fi
|
|
|
|
|
2020-04-24 21:02:00 +00:00
|
|
|
# Generate initramfs
|
2022-06-30 23:47:07 +00:00
|
|
|
# TODO --conf "/dev/null" \
|
|
|
|
# TODO --confdir "/dev/null" \
|
2020-04-24 21:02:00 +00:00
|
|
|
try dracut \
|
|
|
|
--kver "$kver" \
|
2022-06-08 00:47:30 +00:00
|
|
|
--zstd \
|
2020-04-25 20:37:50 +00:00
|
|
|
--no-hostonly \
|
2020-04-24 21:02:00 +00:00
|
|
|
--ro-mnt \
|
2020-04-25 20:37:50 +00:00
|
|
|
--add "bash ${modules[*]}" \
|
2022-06-30 23:47:07 +00:00
|
|
|
"${dracut_opts[@]}" \
|
2020-04-24 21:02:00 +00:00
|
|
|
--force \
|
|
|
|
"$output"
|
2022-04-16 22:04:42 +00:00
|
|
|
|
|
|
|
# Create script to repeat initramfs generation
|
|
|
|
cat > "$(dirname "$output")/generate_initramfs.sh" <<EOF
|
|
|
|
#!/bin/bash
|
|
|
|
kver="\$1"
|
2022-10-05 13:44:52 +00:00
|
|
|
output="\$2" # At setup time, this was "$output"
|
2022-06-08 00:47:30 +00:00
|
|
|
[[ -n "\$kver" ]] || { echo "usage \$0 <kernel_version> <output>" >&2; exit 1; }
|
2022-04-16 22:04:42 +00:00
|
|
|
dracut \\
|
|
|
|
--kver "\$kver" \\
|
2022-06-08 00:47:30 +00:00
|
|
|
--zstd \\
|
2022-04-16 22:04:42 +00:00
|
|
|
--no-hostonly \\
|
|
|
|
--ro-mnt \\
|
|
|
|
--add "bash ${modules[*]}" \\
|
2022-07-01 12:10:38 +00:00
|
|
|
${dracut_opts[@]@Q} \\
|
2022-04-16 22:04:42 +00:00
|
|
|
--force \\
|
2022-10-05 13:44:52 +00:00
|
|
|
"\$output"
|
2022-04-16 22:04:42 +00:00
|
|
|
EOF
|
2020-04-24 21:02:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function get_cmdline() {
|
2021-05-31 14:29:02 +00:00
|
|
|
local cmdline=("rd.vconsole.keymap=$KEYMAP_INITRAMFS")
|
|
|
|
cmdline+=("${DISK_DRACUT_CMDLINE[@]}")
|
|
|
|
|
|
|
|
if [[ $USED_ZFS != "true" ]]; then
|
|
|
|
cmdline+=("root=UUID=$(get_blkid_uuid_for_id "$DISK_ID_ROOT")")
|
2021-05-30 19:13:27 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-31 14:29:02 +00:00
|
|
|
echo -n "${cmdline[*]}"
|
2020-04-24 21:02:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function install_kernel_efi() {
|
2020-04-21 18:48:23 +00:00
|
|
|
try emerge --verbose sys-boot/efibootmgr
|
2020-01-05 22:35:15 -01:00
|
|
|
|
|
|
|
# Copy kernel to EFI
|
2020-04-25 15:56:04 +00:00
|
|
|
local kernel_file
|
|
|
|
kernel_file="$(find "/boot" -name "vmlinuz-*" -printf '%f\n' | sort -V | tail -n 1)" \
|
2020-01-05 22:35:15 -01:00
|
|
|
|| die "Could not list newest kernel file"
|
|
|
|
|
2022-04-16 13:31:11 +00:00
|
|
|
cp "/boot/$kernel_file" "/boot/efi/vmlinuz.efi" \
|
2020-01-05 22:35:15 -01:00
|
|
|
|| die "Could not copy kernel to EFI partition"
|
|
|
|
|
2020-04-24 21:02:00 +00:00
|
|
|
# Generate initramfs
|
2022-04-16 13:31:11 +00:00
|
|
|
generate_initramfs "/boot/efi/initramfs.img"
|
2020-04-24 21:02:00 +00:00
|
|
|
|
2020-01-05 22:35:15 -01:00
|
|
|
# Create boot entry
|
|
|
|
einfo "Creating efi boot entry"
|
2021-04-28 14:06:52 +00:00
|
|
|
local efipartdev
|
|
|
|
efipartdev="$(resolve_device_by_id "$DISK_ID_EFI")" \
|
|
|
|
|| die "Could not resolve device with id=$DISK_ID_EFI"
|
2021-06-03 18:43:36 +00:00
|
|
|
efipartdev="$(realpath "$efipartdev")" \
|
|
|
|
|| die "Error in realpath '$efipartdev'"
|
2022-12-21 12:10:47 -01:00
|
|
|
local sys_efipart
|
|
|
|
sys_efipart="/sys/class/block/$(basename "$efipartdev")" \
|
|
|
|
|| die "Could not construct /sys path to efi partition"
|
2022-12-20 11:07:17 -01:00
|
|
|
local efipartnum
|
2022-12-21 12:10:47 -01:00
|
|
|
efipartnum="$(cat "$sys_efipart/partition")" \
|
2022-12-20 11:07:17 -01:00
|
|
|
|| die "Failed to find partition number for EFI partition $efipartdev"
|
2021-04-28 14:06:52 +00:00
|
|
|
local gptdev
|
2022-12-21 12:10:47 -01:00
|
|
|
gptdev="/dev/$(basename "$(readlink -f "$sys_efipart/..")")" \
|
2022-12-20 11:07:17 -01:00
|
|
|
|| die "Failed to find parent device for EFI partition $efipartdev"
|
|
|
|
if [[ ! -e "$gptdev" ]] || [[ -z "$gptdev" ]]; then
|
|
|
|
gptdev="$(resolve_device_by_id "${DISK_ID_PART_TO_GPT_ID[$DISK_ID_EFI]}")" \
|
|
|
|
|| die "Could not resolve device with id=${DISK_ID_PART_TO_GPT_ID[$DISK_ID_EFI]}"
|
|
|
|
fi
|
2022-04-16 13:31:11 +00:00
|
|
|
try efibootmgr --verbose --create --disk "$gptdev" --part "$efipartnum" --label "gentoo" --loader '\vmlinuz.efi' --unicode 'initrd=\initramfs.img'" $(get_cmdline)"
|
2022-04-16 22:04:42 +00:00
|
|
|
|
|
|
|
# Create script to repeat adding efibootmgr entry
|
|
|
|
cat > "/boot/efi/efibootmgr_add_entry.sh" <<EOF
|
|
|
|
#!/bin/bash
|
2022-10-05 13:44:52 +00:00
|
|
|
# This is the command that was used to create the efibootmgr entry when the
|
|
|
|
# system was installed using gentoo-install.
|
2022-04-16 22:04:42 +00:00
|
|
|
efibootmgr --verbose --create --disk "$gptdev" --part "$efipartnum" --label "gentoo" --loader '\\vmlinuz.efi' --unicode 'initrd=\\initramfs.img'" $(get_cmdline)"
|
|
|
|
EOF
|
2020-04-21 18:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function generate_syslinux_cfg() {
|
2020-04-25 15:56:04 +00:00
|
|
|
cat <<EOF
|
|
|
|
DEFAULT gentoo
|
|
|
|
PROMPT 0
|
|
|
|
TIMEOUT 0
|
|
|
|
|
|
|
|
LABEL gentoo
|
2020-04-25 20:37:50 +00:00
|
|
|
LINUX ../vmlinuz-current
|
|
|
|
APPEND initrd=../initramfs.img $(get_cmdline)
|
2020-04-25 15:56:04 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function install_kernel_bios() {
|
2020-04-21 18:48:23 +00:00
|
|
|
try emerge --verbose sys-boot/syslinux
|
|
|
|
|
2020-04-25 15:56:04 +00:00
|
|
|
# Link kernel to known name
|
|
|
|
local kernel_file
|
|
|
|
kernel_file="$(find "/boot" -name "vmlinuz-*" -printf '%f\n' | sort -V | tail -n 1)" \
|
|
|
|
|| die "Could not list newest kernel file"
|
|
|
|
|
2020-04-25 18:15:16 +00:00
|
|
|
cp "/boot/$kernel_file" "/boot/bios/vmlinuz-current" \
|
|
|
|
|| die "Could copy kernel to /boot/bios/vmlinuz-current"
|
2020-04-21 18:48:23 +00:00
|
|
|
|
2020-04-24 21:02:00 +00:00
|
|
|
# Generate initramfs
|
2020-04-25 18:15:16 +00:00
|
|
|
generate_initramfs "/boot/bios/initramfs.img"
|
2020-04-24 21:02:00 +00:00
|
|
|
|
2020-04-21 18:48:23 +00:00
|
|
|
# Install syslinux
|
|
|
|
einfo "Installing syslinux"
|
2021-04-28 14:06:52 +00:00
|
|
|
local biosdev
|
|
|
|
biosdev="$(resolve_device_by_id "$DISK_ID_BIOS")" \
|
|
|
|
|| die "Could not resolve device with id=$DISK_ID_BIOS"
|
2020-04-25 18:15:16 +00:00
|
|
|
mkdir_or_die 0700 "/boot/bios/syslinux"
|
2020-04-25 15:56:04 +00:00
|
|
|
try syslinux --directory syslinux --install "$biosdev"
|
2020-04-25 13:12:35 +00:00
|
|
|
|
|
|
|
# Create syslinux.cfg
|
2020-10-03 14:24:48 +00:00
|
|
|
generate_syslinux_cfg > /boot/bios/syslinux/syslinux.cfg \
|
2020-04-25 15:56:04 +00:00
|
|
|
|| die "Could save generated syslinux.cfg"
|
2020-04-25 13:12:35 +00:00
|
|
|
|
2020-04-25 15:56:04 +00:00
|
|
|
# Install syslinux MBR record
|
|
|
|
einfo "Copying syslinux MBR record"
|
2021-04-28 14:06:52 +00:00
|
|
|
local gptdev
|
|
|
|
gptdev="$(resolve_device_by_id "${DISK_ID_PART_TO_GPT_ID[$DISK_ID_BIOS]}")" \
|
|
|
|
|| die "Could not resolve device with id=${DISK_ID_PART_TO_GPT_ID[$DISK_ID_BIOS]}"
|
2020-04-25 15:56:04 +00:00
|
|
|
try dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of="$gptdev"
|
2020-04-21 18:48:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function install_kernel() {
|
2020-04-21 18:48:23 +00:00
|
|
|
# Install vanilla kernel
|
2020-04-25 15:56:04 +00:00
|
|
|
einfo "Installing vanilla kernel and related tools"
|
2020-04-21 18:48:23 +00:00
|
|
|
|
|
|
|
if [[ $IS_EFI == "true" ]]; then
|
|
|
|
install_kernel_efi
|
|
|
|
else
|
|
|
|
install_kernel_bios
|
|
|
|
fi
|
2022-09-28 15:47:19 +00:00
|
|
|
|
|
|
|
einfo "Installing linux-firmware"
|
|
|
|
echo "sys-kernel/linux-firmware linux-fw-redistributable no-source-code" >> /etc/portage/package.license \
|
|
|
|
|| die "Could not write to /etc/portage/package.license"
|
|
|
|
try emerge --verbose linux-firmware
|
2020-01-13 20:56:16 -01:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function add_fstab_entry() {
|
2020-04-25 18:12:00 +00:00
|
|
|
printf '%-46s %-24s %-6s %-96s %s\n' "$1" "$2" "$3" "$4" "$5" >> /etc/fstab \
|
2020-04-25 16:06:38 +00:00
|
|
|
|| die "Could not append entry to fstab"
|
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function generate_fstab() {
|
2020-04-23 20:31:18 +00:00
|
|
|
einfo "Generating fstab"
|
2020-11-25 12:45:46 -01:00
|
|
|
install -m0644 -o root -g root "$GENTOO_INSTALL_REPO_DIR/contrib/fstab" /etc/fstab \
|
2020-04-23 20:31:18 +00:00
|
|
|
|| die "Could not overwrite /etc/fstab"
|
2022-05-13 18:41:24 +00:00
|
|
|
if [[ $USED_ZFS != "true" && -n $DISK_ID_ROOT_TYPE ]]; then
|
2021-05-30 20:39:41 +00:00
|
|
|
add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_ROOT")" "/" "$DISK_ID_ROOT_TYPE" "$DISK_ID_ROOT_MOUNT_OPTS" "0 1"
|
|
|
|
fi
|
2020-04-23 20:31:18 +00:00
|
|
|
if [[ $IS_EFI == "true" ]]; then
|
2020-05-01 10:15:37 +00:00
|
|
|
add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_EFI")" "/boot/efi" "vfat" "defaults,noatime,fmask=0177,dmask=0077,noexec,nodev,nosuid,discard" "0 2"
|
2020-04-23 20:31:18 +00:00
|
|
|
else
|
2020-05-01 10:15:37 +00:00
|
|
|
add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_BIOS")" "/boot/bios" "vfat" "defaults,noatime,fmask=0177,dmask=0077,noexec,nodev,nosuid,discard" "0 2"
|
2020-04-23 20:31:18 +00:00
|
|
|
fi
|
|
|
|
if [[ -v "DISK_ID_SWAP" ]]; then
|
2020-05-02 10:22:43 +00:00
|
|
|
add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_SWAP")" "none" "swap" "defaults,discard" "0 0"
|
2020-04-23 20:31:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function main_install_gentoo_in_chroot() {
|
2020-01-13 20:56:16 -01:00
|
|
|
[[ $# == 0 ]] || die "Too many arguments"
|
|
|
|
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'before_install'
|
|
|
|
|
2020-10-06 17:25:10 +00:00
|
|
|
# Remove the root password, making the account accessible for automated
|
|
|
|
# tasks during the period of installation.
|
|
|
|
einfo "Clearing root password"
|
|
|
|
passwd -d root \
|
2020-01-13 20:56:16 -01:00
|
|
|
|| die "Could not change root password"
|
|
|
|
|
2020-04-21 18:48:23 +00:00
|
|
|
if [[ $IS_EFI == "true" ]]; then
|
|
|
|
# Mount efi partition
|
|
|
|
mount_efivars
|
|
|
|
einfo "Mounting efi partition"
|
2020-04-22 21:48:36 +00:00
|
|
|
mount_by_id "$DISK_ID_EFI" "/boot/efi"
|
2020-04-21 18:48:23 +00:00
|
|
|
else
|
2020-04-25 18:15:16 +00:00
|
|
|
# Mount bios partition
|
|
|
|
einfo "Mounting bios partition"
|
|
|
|
mount_by_id "$DISK_ID_BIOS" "/boot/bios"
|
2020-04-21 18:48:23 +00:00
|
|
|
fi
|
2020-01-13 20:56:16 -01:00
|
|
|
|
|
|
|
# Sync portage
|
|
|
|
einfo "Syncing portage tree"
|
2021-06-02 15:35:48 +00:00
|
|
|
try emerge-webrsync
|
|
|
|
|
|
|
|
# Configure basic system things like timezone, locale, ...
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'before_configure_base_system'
|
2021-06-02 15:35:48 +00:00
|
|
|
configure_base_system
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'after_configure_base_system'
|
2021-06-02 15:35:48 +00:00
|
|
|
|
|
|
|
# Prepare portage environment
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'before_configure_portage'
|
2021-06-02 15:35:48 +00:00
|
|
|
configure_portage
|
|
|
|
|
|
|
|
# Install git (for git portage overlays)
|
|
|
|
einfo "Installing git"
|
|
|
|
try emerge --verbose dev-vcs/git
|
|
|
|
|
2021-06-02 15:16:47 +00:00
|
|
|
if [[ "$PORTAGE_SYNC_TYPE" == "git" ]]; then
|
|
|
|
mkdir_or_die 0755 "/etc/portage/repos.conf"
|
|
|
|
cat > /etc/portage/repos.conf/gentoo.conf <<EOF
|
|
|
|
[DEFAULT]
|
|
|
|
main-repo = gentoo
|
|
|
|
|
|
|
|
[gentoo]
|
|
|
|
location = /var/db/repos/gentoo
|
|
|
|
sync-type = git
|
|
|
|
sync-uri = $PORTAGE_GIT_MIRROR
|
|
|
|
auto-sync = yes
|
|
|
|
sync-depth = $([[ $PORTAGE_GIT_FULL_HISTORY == true ]] && echo -n 0 || echo -n 1)
|
|
|
|
sync-git-verify-commit-signature = yes
|
|
|
|
sync-openpgp-key-path = /usr/share/openpgp-keys/gentoo-release.asc
|
|
|
|
EOF
|
|
|
|
chmod 644 /etc/portage/repos.conf/gentoo.conf \
|
|
|
|
|| die "Could not change permissions of '/etc/portage/repos.conf/gentoo.conf'"
|
2021-06-02 15:35:48 +00:00
|
|
|
rm -rf /var/db/repos/gentoo \
|
|
|
|
|| die "Could not delete obsolete rsync gentoo repository"
|
2021-06-02 15:16:47 +00:00
|
|
|
try emerge --sync
|
|
|
|
fi
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'after_configure_portage'
|
2020-01-13 20:56:16 -01:00
|
|
|
|
2022-07-01 12:10:38 +00:00
|
|
|
einfo "Generating ssh host keys"
|
|
|
|
try ssh-keygen -A
|
|
|
|
|
2022-06-30 23:47:07 +00:00
|
|
|
# Install authorized_keys before dracut, which might need them for remote unlocking.
|
|
|
|
install_authorized_keys
|
|
|
|
|
2022-07-01 12:10:38 +00:00
|
|
|
# Install required programs and kernel now, in oder to
|
|
|
|
# prevent emerging module before an imminent kernel upgrade
|
|
|
|
try emerge --verbose sys-kernel/dracut sys-kernel/gentoo-kernel-bin app-arch/zstd
|
|
|
|
|
2020-04-23 21:56:53 +00:00
|
|
|
# Install mdadm if we used raid (needed for uuid resolving)
|
|
|
|
if [[ $USED_RAID == "true" ]]; then
|
|
|
|
einfo "Installing mdadm"
|
|
|
|
try emerge --verbose sys-fs/mdadm
|
|
|
|
fi
|
|
|
|
|
2020-04-24 21:02:00 +00:00
|
|
|
# Install cryptsetup if we used luks
|
|
|
|
if [[ $USED_LUKS == "true" ]]; then
|
|
|
|
einfo "Installing cryptsetup"
|
|
|
|
try emerge --verbose sys-fs/cryptsetup
|
|
|
|
fi
|
|
|
|
|
2023-03-28 14:10:41 +00:00
|
|
|
if [[ $SYSTEMD == "true" && $USED_LUKS == "true" ]] ; then
|
|
|
|
einfo "Enabling cryptsetup USE flag on sys-apps/systemd"
|
|
|
|
echo "sys-apps/systemd cryptsetup" > /etc/portage/package.use/systemd \
|
|
|
|
|| die "Could not write /etc/portage/package.use/systemd"
|
|
|
|
einfo "Rebuilding systemd with changed USE flag"
|
|
|
|
try emerge --verbose --changed-use --oneshot sys-apps/systemd
|
|
|
|
fi
|
|
|
|
|
2020-10-11 19:45:26 +00:00
|
|
|
# Install btrfs-progs if we used btrfs
|
|
|
|
if [[ $USED_BTRFS == "true" ]]; then
|
|
|
|
einfo "Installing btrfs-progs"
|
|
|
|
try emerge --verbose sys-fs/btrfs-progs
|
|
|
|
fi
|
|
|
|
|
2022-09-28 15:47:19 +00:00
|
|
|
try emerge --verbose dev-vcs/git
|
|
|
|
|
2021-05-30 19:01:41 +00:00
|
|
|
# Install zfs kernel module and tools if we used zfs
|
|
|
|
if [[ $USED_ZFS == "true" ]]; then
|
|
|
|
einfo "Installing zfs"
|
|
|
|
try emerge --verbose sys-fs/zfs sys-fs/zfs-kmod
|
|
|
|
|
|
|
|
einfo "Enabling zfs services"
|
|
|
|
if [[ $SYSTEMD == "true" ]]; then
|
2022-07-01 12:10:38 +00:00
|
|
|
try systemctl enable zfs.target
|
|
|
|
try systemctl enable zfs-import-cache
|
|
|
|
try systemctl enable zfs-mount
|
|
|
|
try systemctl enable zfs-import.target
|
2021-05-30 19:01:41 +00:00
|
|
|
else
|
2022-07-01 12:10:38 +00:00
|
|
|
try rc-update add zfs-import boot
|
|
|
|
try rc-update add zfs-mount boot
|
2021-05-30 19:01:41 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-04-23 20:31:18 +00:00
|
|
|
# Install kernel and initramfs
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'before_install_kernel'
|
2020-01-13 20:56:16 -01:00
|
|
|
install_kernel
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'after_install_kernel'
|
2019-12-31 14:28:42 -01:00
|
|
|
|
2020-01-05 22:35:15 -01:00
|
|
|
# Generate a valid fstab file
|
2020-04-23 20:31:18 +00:00
|
|
|
generate_fstab
|
2020-01-05 22:35:15 -01:00
|
|
|
|
2020-10-10 15:08:54 +00:00
|
|
|
# Install gentoolkit
|
2020-01-09 09:51:36 -01:00
|
|
|
einfo "Installing gentoolkit"
|
|
|
|
try emerge --verbose app-portage/gentoolkit
|
|
|
|
|
2020-10-11 23:18:39 +00:00
|
|
|
if [[ $SYSTEMD == "true" ]]; then
|
2022-06-30 23:47:07 +00:00
|
|
|
if [[ $SYSTEMD_NETWORKD == "true" ]]; then
|
|
|
|
# Enable systemd networking and dhcp
|
|
|
|
enable_service systemd-networkd
|
|
|
|
enable_service systemd-resolved
|
|
|
|
if [[ $SYSTEMD_NETWORKD_DHCP == "true" ]]; then
|
|
|
|
echo -en "[Match]\nName=${SYSTEMD_NETWORKD_INTERFACE_NAME}\n\n[Network]\nDHCP=yes" > /etc/systemd/network/20-wired.network \
|
|
|
|
|| die "Could not write dhcp network config to '/etc/systemd/network/20-wired.network'"
|
|
|
|
else
|
|
|
|
addresses=""
|
|
|
|
for addr in "${SYSTEMD_NETWORKD_ADDRESSES[@]}"; do
|
2022-07-01 12:10:38 +00:00
|
|
|
addresses="${addresses}Address=$addr\n"
|
2022-06-30 23:47:07 +00:00
|
|
|
done
|
|
|
|
echo -en "[Match]\nName=${SYSTEMD_NETWORKD_INTERFACE_NAME}\n\n[Network]\n${addresses}Gateway=$SYSTEMD_NETWORKD_GATEWAY" > /etc/systemd/network/20-wired.network \
|
|
|
|
|| die "Could not write dhcp network config to '/etc/systemd/network/20-wired.network'"
|
|
|
|
fi
|
|
|
|
chown root:systemd-network /etc/systemd/network/20-wired.network \
|
|
|
|
|| die "Could not change owner of '/etc/systemd/network/20-wired.network'"
|
|
|
|
chmod 640 /etc/systemd/network/20-wired.network \
|
|
|
|
|| die "Could not change permissions of '/etc/systemd/network/20-wired.network'"
|
|
|
|
fi
|
2022-06-08 00:47:30 +00:00
|
|
|
else
|
|
|
|
# Install and enable dhcpcd
|
|
|
|
einfo "Installing dhcpcd"
|
|
|
|
try emerge --verbose net-misc/dhcpcd
|
|
|
|
|
|
|
|
enable_service dhcpcd
|
2020-10-11 23:18:39 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-30 23:47:07 +00:00
|
|
|
if [[ $ENABLE_SSHD == "true" ]]; then
|
|
|
|
enable_sshd
|
|
|
|
fi
|
|
|
|
|
2020-01-06 19:34:44 -01:00
|
|
|
# Install additional packages, if any.
|
2020-04-25 13:24:24 +00:00
|
|
|
if [[ ${#ADDITIONAL_PACKAGES[@]} -gt 0 ]]; then
|
2020-01-06 19:34:44 -01:00
|
|
|
einfo "Installing additional packages"
|
2020-04-20 22:40:54 +00:00
|
|
|
# shellcheck disable=SC2086
|
2020-04-25 13:24:24 +00:00
|
|
|
try emerge --verbose --autounmask-continue=y -- "${ADDITIONAL_PACKAGES[@]}"
|
2020-01-06 19:34:44 -01:00
|
|
|
fi
|
|
|
|
|
2020-01-04 19:55:42 -01:00
|
|
|
if ask "Do you want to assign a root password now?"; then
|
2020-01-06 16:26:11 -01:00
|
|
|
try passwd root
|
2020-01-04 19:55:42 -01:00
|
|
|
einfo "Root password assigned"
|
|
|
|
else
|
2020-01-06 16:26:11 -01:00
|
|
|
try passwd -d root
|
2020-01-04 19:55:42 -01:00
|
|
|
ewarn "Root password cleared, set one as soon as possible!"
|
|
|
|
fi
|
|
|
|
|
2022-06-09 16:44:08 +00:00
|
|
|
# If configured, change to gentoo testing at the last moment.
|
|
|
|
# This is to ensure a smooth installation process. You can deal
|
|
|
|
# with the blockers after installation ;)
|
|
|
|
if [[ $USE_PORTAGE_TESTING == "true" ]]; then
|
|
|
|
einfo "Adding ~$GENTOO_ARCH to ACCEPT_KEYWORDS"
|
|
|
|
echo "ACCEPT_KEYWORDS=\"~$GENTOO_ARCH\"" >> /etc/portage/make.conf \
|
|
|
|
|| die "Could not modify /etc/portage/make.conf"
|
|
|
|
fi
|
|
|
|
|
2023-01-07 12:02:15 -01:00
|
|
|
maybe_exec 'after_install'
|
|
|
|
|
2020-01-04 19:55:42 -01:00
|
|
|
einfo "Gentoo installation complete."
|
2021-05-02 13:29:21 +00:00
|
|
|
[[ $USED_LUKS == "true" ]] \
|
|
|
|
&& einfo "A backup of your luks headers can be found at '$LUKS_HEADER_BACKUP_DIR', in case you want to have a backup."
|
2022-09-28 15:47:19 +00:00
|
|
|
einfo "You may now reboot your system or execute ./install --chroot $ROOT_MOUNTPOINT to enter your system in a chroot."
|
|
|
|
einfo "Chrooting in this way is always possible in case you need to fix something after rebooting."
|
2019-12-31 14:28:42 -01:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function main_install() {
|
2019-12-31 14:28:42 -01:00
|
|
|
[[ $# == 0 ]] || die "Too many arguments"
|
|
|
|
|
2020-01-02 22:29:17 -01:00
|
|
|
gentoo_umount
|
2020-01-02 22:42:31 -01:00
|
|
|
install_stage3
|
2020-04-21 18:48:23 +00:00
|
|
|
|
|
|
|
[[ $IS_EFI == "true" ]] \
|
|
|
|
&& mount_efivars
|
2021-05-30 01:10:43 +00:00
|
|
|
gentoo_chroot "$ROOT_MOUNTPOINT" "$GENTOO_INSTALL_REPO_BIND/install" __install_gentoo_in_chroot
|
2020-01-02 21:28:16 -01:00
|
|
|
}
|
|
|
|
|
2021-04-28 14:06:52 +00:00
|
|
|
function main_chroot() {
|
2021-05-30 01:17:37 +00:00
|
|
|
# Skip if already mounted
|
|
|
|
mountpoint -q -- "$1" \
|
|
|
|
|| die "'$1' is not a mountpoint"
|
|
|
|
|
2020-01-02 22:42:31 -01:00
|
|
|
gentoo_chroot "$@"
|
2019-12-31 14:28:42 -01:00
|
|
|
}
|