Skip to content

Improve Autoinstaller. #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions dracut/autoinstaller/autoinstall.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
# ===
# Disk Configuration
# ===
# disk_expr: jq expression to select the disk from the output of `lsblk --json`
# default: .blockdevices[0].name
#disk_expr=".blockdevices[0].name"

# disk: the disk to install to
# default: the first disk that isn't the installer
#disk=/dev/hda

# bootpartitionsize: controls how large the boot partition will be
# default: 500M
#bootpartitionsize=500M

# swapsize: how large should the swap partition be
# default: equal to the installed physical memory
#swapsize=

# ===
# XBPS Configuration
# ===
Expand Down Expand Up @@ -54,6 +50,12 @@
# default: en_US.UTF-8
#libclocale=en.US.UTF-8

# hostname_expr: Expression to derive the hostname from the output of
# `ip --json -r a`. The default finds all interfaces that are up and
# possess a global address, and then picks the first one.
# hostname_expr: [.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]
#hostname_expr='[.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]'

# hostname: static hostname for the system
# default: derived from DNS
#hostname=VoidLinux
Expand Down
79 changes: 51 additions & 28 deletions dracut/autoinstaller/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,44 @@ VAI_get_address() {

VAI_partition_disk() {
# Paritition Disk
sfdisk "${disk}" <<EOF
,$bootpartitionsize
,${swapsize}K
;

if [ -d /sys/firmware/efi ] ; then
VAI_info_msg "Partitioning Disk for UEFI Boot"
sfdisk "${disk}" <<EOF
label: gpt
,100M,U,
,,L,
EOF
else
VAI_info_msg "Partitioning Disk for BIOS Boot"
sfdisk "${disk}" <<EOF
label: dos
,,L,*
EOF
fi
}

VAI_format_disk() {
# Make Filesystems
mkfs.ext4 -F "${disk}1"
mkfs.ext4 -F "${disk}3"
if [ "${swapsize}" -ne 0 ] ; then
mkswap -f "${disk}2"
if [ -d /sys/firmware/efi ] ; then
mkfs.vfat -F32 "${disk}1"
mkfs.ext4 -F "${disk}2"
else
mkfs.ext4 -F "${disk}1"
fi
}

VAI_mount_target() {
# Mount targetfs
mkdir -p "${target}"
mount "${disk}3" "${target}"
mkdir "${target}/boot"
mount "${disk}1" "${target}/boot"

if [ -d /sys/firmware/efi ] ; then
mount "${disk}2" "${target}"
mkdir -p "${target}/boot/efi"
mount "${disk}1" "${target}/boot/efi"
else
mount "${disk}1" "${target}"
fi
}

VAI_install_xbps_keys() {
Expand All @@ -70,7 +86,12 @@ VAI_install_xbps_keys() {

VAI_install_base_system() {
# Install a base system
XBPS_ARCH="${XBPS_ARCH}" xbps-install -Sy -R "${xbpsrepository}" -r /mnt base-system grub
_grub="grub"
if [ -d /sys/firmware/efi ] ; then
_grub="${_grub} grub-x86_64-efi"
fi

XBPS_ARCH="${XBPS_ARCH}" xbps-install -Sy -R "${xbpsrepository}" -r /mnt base-system ${_grub}

# Install additional packages
if [ -n "${pkgs}" ] ; then
Expand All @@ -80,6 +101,11 @@ VAI_install_base_system() {
}

VAI_prepare_chroot() {
# Mount efivars if this is an EFI system
if [ -d /sys/firmware/efi ] ; then
mount -t efivarfs none /sys/firmware/efi/efivars
fi

# Mount dev, bind, proc, etc into chroot
mount -t proc proc "${target}/proc"
mount --rbind /sys "${target}/sys"
Expand Down Expand Up @@ -128,7 +154,7 @@ VAI_configure_grub() {
echo "hostonly=yes" > "${target}/etc/dracut.conf.d/hostonly.conf"

# Choose the newest kernel
kernel_version="$(chroot "${target}" xbps-query linux | awk -F "[-_]" '/pkgver/ {print $2}')"
kernel_version="$(xbps-uhelper -r ${target} version linux | sed 's/_.*//')"

# Install grub
chroot "${target}" grub-install "${disk}"
Expand All @@ -141,14 +167,13 @@ VAI_configure_grub() {
VAI_configure_fstab() {
# Grab UUIDs
uuid1="$(blkid -s UUID -o value "${disk}1")"
uuid2="$(blkid -s UUID -o value "${disk}2")"
uuid3="$(blkid -s UUID -o value "${disk}3")"

# Installl UUIDs into /etc/fstab
echo "UUID=$uuid3 / ext4 defaults,errors=remount-ro 0 1" >> "${target}/etc/fstab"
echo "UUID=$uuid1 /boot ext4 defaults 0 2" >> "${target}/etc/fstab"
if [ "${swapsize}" -ne 0 ] ; then
echo "UUID=$uuid2 swap swap defaults 0 0" >> "${target}/etc/fstab"
if [ -d /sys/firmware/efi ] ; then
uuid2="$(blkid -s UUID -o value "${disk}2")"
echo "UUID=$uuid1 /boot/efi vfat defaults 0 0" >> "${target}/etc/fstab"
echo "UUID=$uuid2 / ext4 defaults,errors=remount-ro 0 1" >> "${target}/etc/fstab"

else
echo "UUID=$uuid1 / ext4 defaults,errors=remount-ro 0 1" >> "${target}/etc/fstab"
fi
}

Expand Down Expand Up @@ -195,11 +220,10 @@ VAI_end_action() {

VAI_configure_autoinstall() {
# -------------------------- Setup defaults ---------------------------
bootpartitionsize="500M"
disk="$(lsblk -ipo NAME,TYPE,MOUNTPOINT | awk '{if ($2=="disk") {disks[$1]=0; last=$1} if ($3=="/") {disks[last]++}} END {for (a in disks) {if(disks[a] == 0){print a; break}}}')"
hostname="$(ip -4 -o -r a | awk -F'[ ./]' '{x=$7} END {print x}')"
# XXX: Set a manual swapsize here if the default doesn't fit your use case
swapsize="$(awk -F"\n" '/MemTotal/ {split($0, b, " "); print b[2] }' /proc/meminfo)";
disk_expr=".blockdevices[0].name"
disk="/dev/$(lsblk --json | jq -r "$disk_expr")"
hostname_expr='[.[]|select(.operstate=="UP").addr_info.[]|select(.scope=="global").local].[0]'
hostname="$(ip --json -r a | jq -r "$hostname_expr")"
target="/mnt"
timezone="America/Chicago"
keymap="us"
Expand Down Expand Up @@ -256,7 +280,7 @@ VAI_main() {
VAI_print_step "Configuring installer"
VAI_configure_autoinstall

VAI_print_step "Configuring disk using scheme 'Atomic'"
VAI_print_step "Configuring disk"
VAI_partition_disk
VAI_format_disk

Expand Down Expand Up @@ -307,4 +331,3 @@ if getargbool 0 auto ; then
# Very important to release this before returning to dracut code
set +e
fi

2 changes: 1 addition & 1 deletion dracut/autoinstaller/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ depends() {
}

install() {
inst /usr/bin/awk
inst /usr/bin/chmod
inst /usr/bin/chroot
inst /usr/bin/clear
Expand All @@ -21,6 +20,7 @@ install() {
inst /usr/bin/dhclient-script
inst /usr/bin/halt
inst /usr/bin/install
inst /usr/bin/jq
inst /usr/bin/lsblk
inst /usr/bin/mkdir
inst /usr/bin/mkfs.ext4
Expand Down
2 changes: 1 addition & 1 deletion mknet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ else
info_msg "Selecting u-boot bootloader"
bootloader_pkg=uboot-mkimage
fi
run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy ${KERNELPKG-linux} dracut binutils dracut-network dialog ${INITRAMFS_COMPRESSION-xz} ${bootloader_pkg}"
run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy ${KERNELPKG-linux} dracut binutils dracut-network dialog jq ${INITRAMFS_COMPRESSION-xz} ${bootloader_pkg}"
run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"

# Dracut needs to know the kernel version that will be using this
Expand Down