gpt -> mbr. systemd-boot -> grub
This commit is contained in:
parent
63fe56e777
commit
59cbe65447
3 changed files with 54 additions and 46 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
{
|
{
|
||||||
boot.loader.systemd-boot = {
|
boot.loader = {
|
||||||
|
grub = {
|
||||||
enable = true;
|
enable = true;
|
||||||
configurationLimit = 10;
|
device = "/dev/sda";
|
||||||
|
};
|
||||||
|
timeout = 1;
|
||||||
};
|
};
|
||||||
boot.loader.efi.canTouchEfiVariables = true;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
SSD='/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_116314040'
|
SSD='/dev/sda'
|
||||||
MNT='/mnt'
|
MNT='/mnt'
|
||||||
SWAP_GB=1
|
SWAP_GB=1
|
||||||
|
|
||||||
|
|
@ -14,50 +14,61 @@ wait_for_device() {
|
||||||
echo "Device $device is ready."
|
echo "Device $device is ready."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install a package if it's not already installed
|
swapoff --all
|
||||||
install_if_missing() {
|
udevadm settle
|
||||||
local cmd="$1"
|
|
||||||
local package="$2"
|
|
||||||
if ! command -v "$cmd" &> /dev/null; then
|
|
||||||
echo "$cmd not found, installing $package..."
|
|
||||||
nix-env -iA "nixos.$package"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install_if_missing "sgdisk" "gptfdisk"
|
|
||||||
install_if_missing "partprobe" "parted"
|
|
||||||
|
|
||||||
wait_for_device $SSD
|
wait_for_device $SSD
|
||||||
|
|
||||||
echo "Wiping filesystem on $SSD..."
|
echo "Wiping filesystem on $SSD..."
|
||||||
wipefs -a $SSD
|
wipefs -a $SSD
|
||||||
|
|
||||||
echo "Clearing partition table on $SSD..."
|
echo "Creating new MBR partition table on $SSD..."
|
||||||
sgdisk --zap-all $SSD
|
fdisk $SSD << EOF
|
||||||
|
o
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
|
||||||
echo "Partitioning $SSD..."
|
echo "Partitioning $SSD..."
|
||||||
sgdisk -n1:1M:+1G -t1:EF00 -c1:BOOT $SSD
|
fdisk $SSD << EOF
|
||||||
sgdisk -n2:0:+"$SWAP_GB"G -t2:8200 -c2:SWAP $SSD
|
n
|
||||||
sgdisk -n3:0:0 -t3:8304 -c3:ROOT $SSD
|
p
|
||||||
|
1
|
||||||
|
|
||||||
|
+512M
|
||||||
|
a
|
||||||
|
n
|
||||||
|
p
|
||||||
|
2
|
||||||
|
|
||||||
|
+${SWAP_GB}G
|
||||||
|
t
|
||||||
|
2
|
||||||
|
82
|
||||||
|
n
|
||||||
|
p
|
||||||
|
3
|
||||||
|
|
||||||
|
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
|
||||||
partprobe -s $SSD
|
partprobe -s $SSD
|
||||||
udevadm settle
|
udevadm settle
|
||||||
|
wait_for_device "${SSD}1"
|
||||||
wait_for_device ${SSD}-part1
|
wait_for_device "${SSD}2"
|
||||||
wait_for_device ${SSD}-part2
|
wait_for_device "${SSD}3"
|
||||||
wait_for_device ${SSD}-part3
|
|
||||||
|
|
||||||
echo "Formatting partitions..."
|
echo "Formatting partitions..."
|
||||||
mkfs.vfat -F 32 -n BOOT "${SSD}-part1"
|
mkfs.ext4 -L BOOT "${SSD}1"
|
||||||
mkswap -L SWAP "${SSD}-part2"
|
mkswap -L SWAP "${SSD}2"
|
||||||
mkfs.ext4 -L ROOT "${SSD}-part3"
|
mkfs.ext4 -L ROOT "${SSD}3"
|
||||||
|
|
||||||
echo "Mounting partitions..."
|
echo "Mounting partitions..."
|
||||||
mount -o X-mount.mkdir "${SSD}-part3" "$MNT"
|
mount -o X-mount.mkdir "${SSD}3" "$MNT"
|
||||||
mkdir -p "$MNT/boot"
|
mkdir -p "$MNT/boot"
|
||||||
mount -t vfat -o fmask=0077,dmask=0077,iocharset=iso8859-1 "${SSD}-part1" "$MNT/boot"
|
mount "${SSD}1" "$MNT/boot"
|
||||||
|
|
||||||
echo "Enabling swap..."
|
echo "Enabling swap..."
|
||||||
swapon "${SSD}-part2"
|
swapon "${SSD}2"
|
||||||
|
|
||||||
echo "Partitioning and setup complete:"
|
echo "Partitioning and setup complete:"
|
||||||
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
|
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,16 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(modulesPath + "/installer/scan/not-detected.nix")
|
(modulesPath + "/profiles/qemu-guest.nix")
|
||||||
];
|
];
|
||||||
|
|
||||||
boot.initrd.availableKernelModules = [
|
boot.initrd.availableKernelModules = [
|
||||||
"ahci"
|
"ahci"
|
||||||
"nvme"
|
"xhci_pci"
|
||||||
"sd_mod"
|
|
||||||
"sdhci_pci"
|
|
||||||
"sr_mod"
|
|
||||||
"usb_storage"
|
|
||||||
"virtio_pci"
|
"virtio_pci"
|
||||||
"virtio_scsi"
|
"virtio_scsi"
|
||||||
"xhci_pci"
|
"sd_mod"
|
||||||
|
"sr_mod"
|
||||||
];
|
];
|
||||||
boot.initrd.kernelModules = [ ];
|
boot.initrd.kernelModules = [ ];
|
||||||
boot.kernelModules = [ ];
|
boot.kernelModules = [ ];
|
||||||
|
|
@ -33,14 +30,12 @@
|
||||||
|
|
||||||
fileSystems."/boot" = {
|
fileSystems."/boot" = {
|
||||||
device = "/dev/disk/by-label/BOOT";
|
device = "/dev/disk/by-label/BOOT";
|
||||||
fsType = "vfat";
|
fsType = "ext4";
|
||||||
options = [
|
|
||||||
"fmask=0022"
|
|
||||||
"dmask=0022"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
swapDevices = [ { device = "/dev/disk/by-label/SWAP"; } ];
|
swapDevices = [
|
||||||
|
{ device = "/dev/disk/by-label/SWAP"; }
|
||||||
|
];
|
||||||
|
|
||||||
networking.useDHCP = lib.mkDefault true;
|
networking.useDHCP = lib.mkDefault true;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue