Generate partitioning scripts using nix

This commit is contained in:
Manuel Thalmann 2024-06-22 23:32:57 +02:00
parent 60497bcc2e
commit 4bd86f8de7
6 changed files with 15 additions and 162 deletions

View file

@ -1,33 +0,0 @@
#!/bin/bash
function dualbootPartition() {
{
# Delete placeholders for swap and Linux partition
echo "d";
echo "2";
echo "d";
echo "3";
# Create swap partition
echo "n";
echo "";
echo "";
echo "+${SWAP_SIZE}G";
echo "y";
echo "t";
echo "2";
echo "19";
# Fill remaining space with Linux partition
echo "n";
echo "";
echo "";
echo "";
echo "y";
echo "t";
echo "3";
echo "23";
echo "w";
} | fdisk "$OS_DISK";
}

View file

@ -2,19 +2,6 @@
pushd "${BASH_SOURCE%/*}" > /dev/null;
. "./partition.sh";
extraMounts()
{
disks=($(bash -c "echo $OS_DISK*"));
mount --mkdir -o force -t ntfs3 "${disks[-1]}" "$ARCH_MOUNT_ROOT/mnt/win";
}
function initializePartitions() {
dualbootPartition;
}
SKIP_FORMAT_EFI=1 \
ARCH_MOUNT_ROOT="/mnt" \
ARCH_DISK=nvme0n1 \
ARCH_HOSTNAME="der-geret" \
USER_DISPLAYNAME="Manuel Thalmann" \
. "../../../scripts/Arch/OS/setup.sh";

View file

@ -0,0 +1,9 @@
{ ... }: {
imports = [
../../../scripts/Arch/OS/partition.nix
];
config = {
partition.os.deviceName = "nvme0n1";
};
}

View file

@ -1,8 +1,6 @@
#!/bin/bash -e
pushd "${BASH_SOURCE%/*}" > /dev/null;
ARCH_MOUNT_ROOT="/mnt" \
ARCH_DISK=nvme0n1 \
ARCH_HOSTNAME="manu-surface" \
USER_DISPLAYNAME="Manuel Thalmann" \
. "../../../scripts/Arch/OS/setup.sh";

View file

@ -1,10 +1,10 @@
#!/bin/bash -e
pushd "${BASH_SOURCE%/*}" > /dev/null;
PARTITION_MODULE="${PARTITION_MODULE:-"./partition.nix"}";
ARCH_TIMEZONE="${ARCH_TIMEZONE:-"Europe/Zurich"}";
ARCH_DISK="${ARCH_DISK}";
ARCH_HOSTNAME="${ARCH_HOSTNAME}";
ARCH_MOUNT_ROOT="${ARCH_MOUNT_ROOT:-"/mnt"}";
ARCH_MOUNT_ROOT="${ARCH_MOUNT_ROOT:-"$(../../eval-module.sh "$PARTITION_MODULE" partition.rootDir --raw)"}";
ARCH_LANG="${ARCH_LANG:-"en_US.UTF-8"}";
ARCH_KEYMAP="${ARCH_KEYMAP:-"de_CH-latin1"}";
ARCH_X11_KEYMAP="${ARCH_X11_KEYMAP:-"ch"}";
@ -22,9 +22,7 @@ tempDir="$tempRoot/$relativeDir";
loadkeys "$ARCH_KEYMAP";
timedatectl set-timezone "$ARCH_TIMEZONE";
OS_MOUNT_ROOT="${ARCH_MOUNT_ROOT}";
OS_DISK="${ARCH_DISK}" \
OS_LABEL="Arch" \
. "../../Common/OS/partition.sh";
pacman-key --init;

View file

@ -1,109 +1,3 @@
#!/bin/bash
pushd "${BASH_SOURCE%/*}" > /dev/null;
source "../Scripts/hooks.sh";
source "../Scripts/is-truthy.sh";
source "../Scripts/choose-disk.sh";
OS_MOUNT_ROOT="${OS_ROOT:-"/mnt"}";
OS_DISK="${OS_DISK}";
BOOT_LABEL="${BOOT_LABEL:-Boot}";
OS_LABEL="${OS_LABEL:-Linux}";
SWAP_LABEL="${SWAP_LABEL:-Swap}";
BOOT_MOUNTPOINT="${BOOT_MOUNTPOINT:-"/boot"}";
SKIP_FORMAT_EFI="${SKIP_FORMAT_EFI}";
memory="$(cat /proc/meminfo | awk -F " " '/^MemTotal/ { print $2 }')";
swapSize="$(echo "$memory" | awk '{ print int((($1 / 1024 / 1024) * 0.75) + 0.5)}')";
if [ ! -z "$OS_DISK" ] && [ ! -e "$OS_DISK" ]
then
OS_DISK="/dev/${OS_DISK}"
fi;
if [ -z "$OS_DISK" ] || [ ! -e "$OS_DISK" ]
then
chooseDisk OS_DISK "Which disk do you wish to format for installing the OS?";
fi;
function partitionDisk() {
{
echo "g";
echo "n";
echo "";
echo "";
echo "+1G";
echo "y";
echo "t";
echo "1";
echo "n";
echo "";
echo "";
echo "+${SWAP_SIZE}G";
echo "y";
echo "t";
echo "";
echo "19";
echo "n";
echo "";
echo "";
echo "";
echo "y";
echo "t";
echo "";
echo "23";
echo "w";
} | fdisk "$OS_DISK";
}
OS_DISK="${OS_DISK}" \
SWAP_SIZE="$swapSize" \
runHook initializePartitions \
partitionDisk;
while true
do
disks=($(bash -c "echo $OS_DISK*"));
[ "${#disks[@]}" -ge 4 ] && break;
done;
bootDisk="${BOOT_DISK:-"${disks[1]}"}";
swapDisk="${SWAP_DISK:-"${disks[2]}"}";
linuxDisk="${LINUX_DISK:-"${disks[3]}"}";
labels=("$SWAP_LABEL" "$OS_LABEL");
if ! isTruthy "$SKIP_FORMAT_EFI"
then
mkfs.fat -F 32 -n "$BOOT_LABEL" "$bootDisk";
labels+=("$BOOT_LABEL");
fi
mkswap -L "$SWAP_LABEL" "$swapDisk";
mkfs.ext4 -L "$OS_LABEL" -F "$linuxDisk";
for label in ${labels[*]};
do
while true;
do
[ -b "/dev/disk/by-label/$label" ] && break;
done;
done
mount "/dev/disk/by-label/$OS_LABEL" "$OS_MOUNT_ROOT";
if ! isTruthy "$SKIP_FORMAT_EFI"
then
bootDisk="/dev/disk/by-label/$BOOT_LABEL";
fi
mount --mkdir "$bootDisk" "$OS_MOUNT_ROOT$BOOT_MOUNTPOINT";
swapon "/dev/disk/by-label/$SWAP_LABEL";
if command -v extraMounts
then
extraMounts;
fi;
popd > /dev/null;
PARTITION_MODULE="${PARTITION_MODULE:-"./partition.nix"}";
eval "$(../../eval-module.sh "$PARTITION_MODULE" partition.script --raw)";