Skip to content

Instantly share code, notes, and snippets.

@superboum
Last active August 13, 2025 12:22
Show Gist options
  • Save superboum/1c7adcd967d3e15dfbd30d04b9ae6144 to your computer and use it in GitHub Desktop.
Save superboum/1c7adcd967d3e15dfbd30d04b9ae6144 to your computer and use it in GitHub Desktop.

Revisions

  1. superboum revised this gist Nov 23, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions build.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/bin/bash
    # SPDX-License-Identifier: MIT

    set -e # Exit on error

  2. superboum renamed this gist Nov 23, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion LICENCE → LICENCE.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    Copyright 2022 Quentin Dufour
    MIT LICENSE

    Copyright 2018 Quentin Dufour

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  3. superboum revised this gist Nov 23, 2023. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions LICENCE
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    Copyright 2022 Quentin Dufour

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  4. superboum created this gist Dec 26, 2018.
    71 changes: 71 additions & 0 deletions build.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/bin/bash

    set -e # Exit on error

    DEVICE=$1
    [ -z "${DEVICE}" ] && echo "Usage $0 /dev/sdX" && exit 1

    udevadm info -n ${DEVICE} -q property
    echo "Selected device is ${DEVICE}"
    read -p "[Press enter to continue or CTRL+C to stop]"

    echo "Umount ${DEVICE}"
    umount ${DEVICE}* || true

    echo "Set partition table to GPT (UEFI)"
    parted ${DEVICE} --script mktable gpt

    echo "Create EFI partition"
    parted ${DEVICE} --script mkpart EFI fat16 1MiB 10MiB
    parted ${DEVICE} --script set 1 msftdata on

    echo "Create OS partition"
    parted ${DEVICE} --script mkpart LINUX btrfs 10MiB 100%

    echo "Format partitions"
    mkfs.vfat -n EFI ${DEVICE}1
    mkfs.btrfs -f -L LINUX ${DEVICE}2

    echo "Mount OS partition"
    ROOTFS="/tmp/installing-rootfs"
    mkdir -p ${ROOTFS}
    mount ${DEVICE}2 ${ROOTFS}

    echo "Debootstrap system"
    debootstrap --variant=minbase --arch amd64 buster ${ROOTFS} http://deb.debian.org/debian/

    echo "Mount EFI partition"
    mkdir -p ${ROOTFS}/boot/efi
    mount ${DEVICE}1 ${ROOTFS}/boot/efi

    echo "Get ready for chroot"
    mount --bind /dev ${ROOTFS}/dev
    mount -t devpts /dev/pts ${ROOTFS}/dev/pts
    mount -t proc proc ${ROOTFS}/proc
    mount -t sysfs sysfs ${ROOTFS}/sys
    mount -t tmpfs tmpfs ${ROOTFS}/tmp

    echo "Entering chroot, installing Linux kernel and Grub"
    cat << EOF | chroot ${ROOTFS}
    set -e
    export HOME=/root
    export DEBIAN_FRONTEND=noninteractive
    debconf-set-selections <<< "grub-efi-amd64 grub2/update_nvram boolean false"
    apt-get remove -y grub-efi grub-efi-amd64
    apt-get update
    apt-get install -y linux-image-amd64 linux-headers-amd64 grub-efi
    grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --no-nvram --removable
    update-grub
    EOF


    echo "Unmounting filesystems"
    umount ${ROOTFS}/dev/pts
    umount ${ROOTFS}/dev
    umount ${ROOTFS}/proc
    umount ${ROOTFS}/sys
    umount ${ROOTFS}/tmp
    umount ${ROOTFS}/boot/efi
    umount ${ROOTFS}

    echo "Done"