Added sylinux installation for bios systems
This commit is contained in:
parent
25adbb0b68
commit
bae6327c59
|
@ -39,10 +39,11 @@ Here is a quick overview of what this script does:
|
||||||
* Select best gentoo portage mirrors
|
* Select best gentoo portage mirrors
|
||||||
* Install git (so you can add your portage overlays later)
|
* Install git (so you can add your portage overlays later)
|
||||||
* Install `sys-kernel/vanilla-kernel-bin` (temporarily, until you replace it)
|
* Install `sys-kernel/vanilla-kernel-bin` (temporarily, until you replace it)
|
||||||
* Copy kernel to efi partition
|
- EFI: Copy kernel to efi partition
|
||||||
* Create boot entry using efibootmgr
|
- EFI: Create boot entry using efibootmgr (or install syslinux for BIOS boot)
|
||||||
|
- BIOS: Install syslinux
|
||||||
* Generate fstab
|
* Generate fstab
|
||||||
* Lets you set a root password
|
* Ask for a root password
|
||||||
|
|
||||||
Also, optionally the following will be done:
|
Also, optionally the following will be done:
|
||||||
|
|
||||||
|
|
|
@ -34,14 +34,20 @@ check_config() {
|
||||||
[[ -n $DISK_ID_EFI ]] || [[ -n $DISK_ID_BOOT ]] \
|
[[ -n $DISK_ID_EFI ]] || [[ -n $DISK_ID_BOOT ]] \
|
||||||
|| die "You must assign DISK_ID_EFI or DISK_ID_BOOT"
|
|| die "You must assign DISK_ID_EFI or DISK_ID_BOOT"
|
||||||
|
|
||||||
[[ -v "DISK_ID_BOOT" ]] && [[ -v "DISK_ID_TO_UUID[$DISK_ID_BOOT]" ]] \
|
[[ -v "DISK_ID_BOOT" ]] && [[ ! -v "DISK_ID_TO_UUID[$DISK_ID_BOOT]" ]] \
|
||||||
|| die "Missing uuid for DISK_ID_BOOT, have you made sure it is used?"
|
&& die "Missing uuid for DISK_ID_BOOT, have you made sure it is used?"
|
||||||
[[ -v "DISK_ID_EFI" ]] && [[ -v "DISK_ID_TO_UUID[$DISK_ID_EFI]" ]] \
|
[[ -v "DISK_ID_EFI" ]] && [[ ! -v "DISK_ID_TO_UUID[$DISK_ID_EFI]" ]] \
|
||||||
|| die "Missing uuid for DISK_ID_EFI, have you made sure it is used?"
|
&& die "Missing uuid for DISK_ID_EFI, have you made sure it is used?"
|
||||||
[[ -v "DISK_ID_SWAP" ]] && [[ -v "DISK_ID_TO_UUID[$DISK_ID_SWAP]" ]] \
|
[[ -v "DISK_ID_SWAP" ]] && [[ ! -v "DISK_ID_TO_UUID[$DISK_ID_SWAP]" ]] \
|
||||||
|| die "Missing uuid for DISK_ID_SWAP, have you made sure it is used?"
|
&& die "Missing uuid for DISK_ID_SWAP, have you made sure it is used?"
|
||||||
[[ -v "DISK_ID_ROOT" ]] && [[ -v "DISK_ID_TO_UUID[$DISK_ID_ROOT]" ]] \
|
[[ -v "DISK_ID_ROOT" ]] && [[ ! -v "DISK_ID_TO_UUID[$DISK_ID_ROOT]" ]] \
|
||||||
|| die "Missing uuid for DISK_ID_ROOT, have you made sure it is used?"
|
&& die "Missing uuid for DISK_ID_ROOT, have you made sure it is used?"
|
||||||
|
|
||||||
|
if [[ -v "DISK_ID_EFI" ]]; then
|
||||||
|
IS_EFI=true
|
||||||
|
else
|
||||||
|
IS_EFI=false
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $INSTALL_ANSIBLE == true ]]; then
|
if [[ $INSTALL_ANSIBLE == true ]]; then
|
||||||
[[ $INSTALL_SSHD == true ]] \
|
[[ $INSTALL_SSHD == true ]] \
|
||||||
|
@ -154,10 +160,11 @@ disk_create_gpt() {
|
||||||
device_desc="$device"
|
device_desc="$device"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
disk_id_to_resolvable[$new_id]="raw:$device"
|
local uuid="${DISK_ID_TO_UUID[$new_id]}"
|
||||||
|
disk_id_to_resolvable[$new_id]="uuid:$uuid"
|
||||||
|
|
||||||
einfo "Creating new gpt partition table ($new_id) on $device_desc"
|
einfo "Creating new gpt partition table ($new_id) on $device_desc"
|
||||||
sgdisk -Z "$device" >/dev/null \
|
sgdisk -Z -U "$uuid" "$device" >/dev/null \
|
||||||
|| die "Could not create new gpt partition table ($new_id) on '$device'"
|
|| die "Could not create new gpt partition table ($new_id) on '$device'"
|
||||||
partprobe "$device"
|
partprobe "$device"
|
||||||
}
|
}
|
||||||
|
@ -180,8 +187,9 @@ disk_create_partition() {
|
||||||
|
|
||||||
local device="$(resolve_id_to_device "$id")"
|
local device="$(resolve_id_to_device "$id")"
|
||||||
local partuuid="${DISK_ID_TO_UUID[$new_id]}"
|
local partuuid="${DISK_ID_TO_UUID[$new_id]}"
|
||||||
|
local extra_args=""
|
||||||
case "$type" in
|
case "$type" in
|
||||||
'boot') type='ef02' ;;
|
'boot') type='ef02' extra_args='--attributes=0:set:2';;
|
||||||
'efi') type='ef00' ;;
|
'efi') type='ef00' ;;
|
||||||
'swap') type='8200' ;;
|
'swap') type='8200' ;;
|
||||||
'raid') type='fd00' ;;
|
'raid') type='fd00' ;;
|
||||||
|
@ -193,7 +201,8 @@ disk_create_partition() {
|
||||||
disk_id_to_resolvable[$new_id]="partuuid:$partuuid"
|
disk_id_to_resolvable[$new_id]="partuuid:$partuuid"
|
||||||
|
|
||||||
einfo "Creating partition ($new_id) with type=$type, size=$size on $device"
|
einfo "Creating partition ($new_id) with type=$type, size=$size on $device"
|
||||||
sgdisk -n "0:0:$arg_size" -t "0:$type" -u 0:"$partuuid" "$device" >/dev/null \
|
# shellcheck disable=SC2086
|
||||||
|
sgdisk -n "0:0:$arg_size" -t "0:$type" -u 0:"$partuuid" $extra_args "$device" >/dev/null \
|
||||||
|| die "Could not create new gpt partition ($new_id) on '$device' ($id)"
|
|| die "Could not create new gpt partition ($new_id) on '$device' ($id)"
|
||||||
partprobe "$device"
|
partprobe "$device"
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ USED_LUKS=false
|
||||||
|
|
||||||
# An array of disk related actions to perform
|
# An array of disk related actions to perform
|
||||||
DISK_ACTIONS=()
|
DISK_ACTIONS=()
|
||||||
|
# An associative array from partuuid to disk uuid
|
||||||
|
declare -A DISK_PARTUUID_TO_GPT_UUID
|
||||||
# An associative array to check for existing ids (maps to uuids)
|
# An associative array to check for existing ids (maps to uuids)
|
||||||
declare -A DISK_ID_TO_UUID
|
declare -A DISK_ID_TO_UUID
|
||||||
# An associative set to check for correct usage of size=remaining in gpt tables
|
# An associative set to check for correct usage of size=remaining in gpt tables
|
||||||
|
@ -126,6 +128,7 @@ create_partition() {
|
||||||
[[ ${arguments[size]} == "remaining" ]] \
|
[[ ${arguments[size]} == "remaining" ]] \
|
||||||
&& DISK_GPT_HAD_SIZE_REMAINING[${arguments[id]}]=true
|
&& DISK_GPT_HAD_SIZE_REMAINING[${arguments[id]}]=true
|
||||||
|
|
||||||
|
DISK_PARTUUID_TO_GPT_UUID[${DISK_ID_TO_UUID[$new_id]}]="${DISK_ID_TO_UUID[$id]}"
|
||||||
DISK_ACTIONS+=("action=create_partition" "$@" ";")
|
DISK_ACTIONS+=("action=create_partition" "$@" ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,14 +89,12 @@ install_sshd() {
|
||||||
|| die "Could not create group 'sshusers'"
|
|| die "Could not create group 'sshusers'"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_kernel() {
|
install_kernel_efi() {
|
||||||
# Install vanilla kernel and efibootmgr, to be able to boot the system.
|
try emerge --verbose sys-boot/efibootmgr
|
||||||
einfo "Installing binary vanilla kernel"
|
|
||||||
try emerge --verbose sys-kernel/vanilla-kernel-bin sys-boot/efibootmgr
|
|
||||||
|
|
||||||
# Copy kernel to EFI
|
# Copy kernel to EFI
|
||||||
local kernel_version
|
local kernel_version
|
||||||
kernel_version="$(find "/boot" -name "vmlinuz-*" -printf '%f\n' | sort -V | tail -1)" \
|
kernel_version="$(find "/boot" -name "vmlinuz-*" -printf '%f\n' | sort -V | tail -n 1)" \
|
||||||
|| die "Could not list newest kernel file"
|
|| die "Could not list newest kernel file"
|
||||||
kernel_version="${kernel_version#vmlinuz-}" \
|
kernel_version="${kernel_version#vmlinuz-}" \
|
||||||
|| die "Could not find kernel version"
|
|| die "Could not find kernel version"
|
||||||
|
@ -112,11 +110,46 @@ install_kernel() {
|
||||||
local linuxdev
|
local linuxdev
|
||||||
linuxdev="$(get_device_by_partuuid "$PARTITION_UUID_ROOT")" \
|
linuxdev="$(get_device_by_partuuid "$PARTITION_UUID_ROOT")" \
|
||||||
|| die "Could not resolve partition UUID '$PARTITION_UUID_ROOT'"
|
|| die "Could not resolve partition UUID '$PARTITION_UUID_ROOT'"
|
||||||
local efidev
|
local efipartdev
|
||||||
efidev="$(get_device_by_partuuid "$PARTITION_UUID_EFI")" \
|
efipartdev="$(get_device_by_partuuid "$PARTITION_UUID_EFI")" \
|
||||||
|| die "Could not resolve partition UUID '$PARTITION_UUID_EFI'"
|
|| die "Could not resolve partition UUID '$PARTITION_UUID_EFI'"
|
||||||
local efipartnum="${efidev: -1}"
|
local efipartnum="${efipartdev: -1}"
|
||||||
try efibootmgr --verbose --create --disk "$PARTITION_DEVICE" --part "$efipartnum" --label "gentoo" --loader '\EFI\vmlinuz.efi' --unicode "root=$linuxdev initrd=\\EFI\\initramfs.img"
|
local gptuuid="${DISK_PARTUUID_TO_GPT_UUID[$PARTITION_UUID_EFI]}"
|
||||||
|
local gptdev
|
||||||
|
gptdev="$(get_device_by_uuid "$gptuuid")" \
|
||||||
|
|| die "Could not resolve GPT UUID '$gptuuid'"
|
||||||
|
try efibootmgr --verbose --create --disk "$gptdev" --part "$efipartnum" --label "gentoo" --loader '\EFI\vmlinuz.efi' --unicode "root=$linuxdev initrd=\\EFI\\initramfs.img"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_kernel_bios() {
|
||||||
|
try emerge --verbose sys-boot/syslinux
|
||||||
|
|
||||||
|
# Install syslinux MBR record
|
||||||
|
einfo "Copying syslinux MBR record"
|
||||||
|
local bootdev
|
||||||
|
bootdev="$(get_device_by_partuuid "$PARTITION_UUID_BOOT")" \
|
||||||
|
|| die "Could not resolve partition UUID '$PARTITION_UUID_BOOT'"
|
||||||
|
local gptuuid="${DISK_PARTUUID_TO_GPT_UUID[$PARTITION_UUID_BOOT]}"
|
||||||
|
local gptdev
|
||||||
|
gptdev="$(get_device_by_uuid "$gptuuid")" \
|
||||||
|
|| die "Could not resolve GPT UUID '$gptuuid'"
|
||||||
|
try dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/gptmbr.bin of="$gptdev"
|
||||||
|
|
||||||
|
# Install syslinux
|
||||||
|
einfo "Installing syslinux"
|
||||||
|
syslinux --install "$bootdev"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_kernel() {
|
||||||
|
# Install vanilla kernel
|
||||||
|
einfo "Installing binary vanilla kernel"
|
||||||
|
try emerge --verbose sys-kernel/vanilla-kernel-bin
|
||||||
|
|
||||||
|
if [[ $IS_EFI == "true" ]]; then
|
||||||
|
install_kernel_efi
|
||||||
|
else
|
||||||
|
install_kernel_bios
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_ansible() {
|
install_ansible() {
|
||||||
|
@ -153,10 +186,16 @@ main_install_gentoo_in_chroot() {
|
||||||
passwd -l root \
|
passwd -l root \
|
||||||
|| die "Could not change root password"
|
|| die "Could not change root password"
|
||||||
|
|
||||||
# Mount efi partition
|
if [[ $IS_EFI == "true" ]]; then
|
||||||
mount_efivars
|
# Mount efi partition
|
||||||
einfo "Mounting efi partition"
|
mount_efivars
|
||||||
mount_by_partuuid "$PARTITION_UUID_EFI" "/boot/efi"
|
einfo "Mounting efi partition"
|
||||||
|
mount_by_partuuid "$PARTITION_UUID_EFI" "/boot/efi"
|
||||||
|
else
|
||||||
|
# Mount boot partition
|
||||||
|
einfo "Mounting boot partition"
|
||||||
|
mount_by_partuuid "$PARTITION_UUID_BOOT" "/boot"
|
||||||
|
fi
|
||||||
|
|
||||||
# Sync portage
|
# Sync portage
|
||||||
einfo "Syncing portage tree"
|
einfo "Syncing portage tree"
|
||||||
|
@ -193,8 +232,13 @@ main_install_gentoo_in_chroot() {
|
||||||
|| die "Could not overwrite /etc/fstab"
|
|| die "Could not overwrite /etc/fstab"
|
||||||
echo "PARTUUID=$PARTITION_UUID_ROOT / ext4 defaults,noatime,errors=remount-ro,discard 0 1" >> /etc/fstab \
|
echo "PARTUUID=$PARTITION_UUID_ROOT / ext4 defaults,noatime,errors=remount-ro,discard 0 1" >> /etc/fstab \
|
||||||
|| die "Could not append entry to fstab"
|
|| die "Could not append entry to fstab"
|
||||||
echo "PARTUUID=$PARTITION_UUID_EFI /boot/efi vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
if [[ $IS_EFI == "true" ]]; then
|
||||||
|| die "Could not append entry to fstab"
|
echo "PARTUUID=$PARTITION_UUID_EFI /boot/efi vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
||||||
|
|| die "Could not append entry to fstab"
|
||||||
|
else
|
||||||
|
echo "PARTUUID=$PARTITION_UUID_BOOT /boot vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \
|
||||||
|
|| die "Could not append entry to fstab"
|
||||||
|
fi
|
||||||
if [[ -v "PARTITION_UUID_SWAP" ]]; then
|
if [[ -v "PARTITION_UUID_SWAP" ]]; then
|
||||||
echo "PARTUUID=$PARTITION_UUID_SWAP none swap defaults,discard 0 0" >> /etc/fstab \
|
echo "PARTUUID=$PARTITION_UUID_SWAP none swap defaults,discard 0 0" >> /etc/fstab \
|
||||||
|| die "Could not append entry to fstab"
|
|| die "Could not append entry to fstab"
|
||||||
|
@ -245,7 +289,9 @@ main_install() {
|
||||||
|
|
||||||
gentoo_umount
|
gentoo_umount
|
||||||
install_stage3
|
install_stage3
|
||||||
mount_efivars
|
|
||||||
|
[[ $IS_EFI == "true" ]] \
|
||||||
|
&& mount_efivars
|
||||||
gentoo_chroot "$GENTOO_INSTALL_REPO_BIND/scripts/main.sh" install_gentoo_in_chroot
|
gentoo_chroot "$GENTOO_INSTALL_REPO_BIND/scripts/main.sh" install_gentoo_in_chroot
|
||||||
gentoo_umount
|
gentoo_umount
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ eerror() {
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
eerror "$*"
|
eerror "$*"
|
||||||
echo "Aborted." >&2
|
kill "$GENTOO_INSTALL_REPO_SCRIPT_PID"
|
||||||
kill "$GENTOO_INSTALL_REPO_SCRIPT_PID" >/dev/null
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue