Created
July 3, 2020 11:15
-
-
Save PeterHeja/9c277806a735a29f837aed23644c6f11 to your computer and use it in GitHub Desktop.
Primitive ubuntu setup with debootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export PROVISION_USER="provision" | |
export SYSTEM_FQDN="example.local" | |
export SYSTEM_NAME="example" | |
export TIMEZONE="Europe/Budapest" | |
export EFI_PART_NUM="1" | |
export BOOT_PART_NUM="2" | |
export DATA_PART_NUM="3" | |
# THIS SCRIPT IS INCOMPLETE! | |
# You have to run this by hand. | |
apt-get update && \ | |
apt-get dist-upgrade -y && \ | |
apt-get install -y \ | |
vim openssh-server \ | |
lvm2 xfsprogs \ | |
efibootmgr \ | |
man rsync pciutils \ | |
linux-image-generic linux-headers-generic grub-efi | |
useradd "${PROVISION_USER}" -s /bin/bash -m | |
usermod -aG sudo "${PROVISION_USER}" | |
########################## | |
# REPLACE THIS PASSWORD! # | |
########################## | |
echo "Password not changed" && exit 1 | |
echo "${PROVISION_USER}:testpasswd" | chpasswd | |
########################## | |
# REPLACE THIS PASSWORD! # | |
########################## | |
cat >/etc/netplan/50-default.yaml <<EOF | |
network: | |
version: 2 | |
renderer: networkd | |
ethernets: | |
eno1: | |
dhcp4: true | |
EOF | |
locale-gen en_US | |
locale-gen en_US.UTF-8 | |
update-locale | |
echo "${SYSTEM_FQDN}" > /etc/hostname | |
echo "127.0.0.1 ${SYSTEM_NAME} ${SYSTEM_FQDN}" >> /etc/hosts | |
echo "${TIMEZONE}" > /etc/timezone | |
# This is a manual step | |
blkid | egrep '(sda)|(insert your volume group name here)' | |
UUID="insert root fs uuid" / xfs defaults 0 1 | |
UUID="insert boot fs uuid" /boot vfat defaults 0 0 | |
UUID="insert home fs uuid" /home xfs defaults 0 0 | |
mount -t efivarfs efivarfs /sys/firmware/efi/efivars | |
# needed for some systems | |
efibootmgr -c -d /dev/sda -p 2 -l '\EFI\ubuntu\grubx64.efi' -L "Windows Boot Manager" | |
grub-install \ | |
--target=x86_64-efi \ | |
--efi-directory=/boot \ | |
--bootloader-id=ubuntu \ | |
--recheck \ | |
--debug \ | |
/dev/sda1 | |
efibootmgr -c -d /dev/sda -p "${EFI_PART_NUM}" -l '\EFI\ubuntu\grubx64.efi' -L "Windows Boot Manager" | |
update-initramfs -k all -c | |
update-grub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export TARGET_DISK="/dev/sda" | |
export TARGET_DIR="/mnt/target/" | |
export TMPFS_DIR="${TARGET_DIR}" | |
export EFI_PART_NUM="1" | |
export BOOT_PART_NUM="2" | |
export DATA_PART_NUM="3" | |
export ARCH="amd64" | |
export RELEASE="bionic" | |
export SYSTEM="example" | |
export PREFIX="e" | |
# _h = host disk, the root/whatever | |
export LVM_PREFIX="${PREFIX}_h" | |
apt-get update | |
apt-get install -y debootstrap vim | |
mkdir $TARGET_DIR $TMPFS_DIR | |
mount tmpfs -t tmpfs -o size=6G $TMPFS_DIR | |
parted $TARGET_DISK <<EOF | |
mklabel gpt | |
mkpart ESP fat32 1MiB 2MiB | |
name 1 grub | |
set 1 bios_grub on | |
mkpart primary ext2 2MiB 1GiB | |
name 2 boot | |
set 2 boot on | |
mkpart primary xfs 1GiB 100% | |
name 3 bernoulli | |
set 3 lvm on | |
set 1 boot off | |
quit | |
EOF | |
pvcreate "${TARGET_DISK}${DATA_PART_NUM}" | |
vgcreate "${LVM_PREFIX}_vg00" "${TARGET_DISK}${DATA_PART_NUM}" | |
lvcreate -L 8G -n root "${LVM_PREFIX}_vg00" | |
lvcreate -L 8G -n home "${LVM_PREFIX}_vg00" | |
mkfs.xfs "/dev/mapper/${LVM_PREFIX}_vg00-root" | |
mkfs.xfs "/dev/mapper/${LVM_PREFIX}_vg00-home" | |
mkfs.fat -F 32 "${TARGET_DISK}${EFI_PART_NUM}" | |
mkdir "${TARGET_DIR}" | |
mount "/dev/mapper/${LVM_PREFIX}_vg00-root" "${TARGET_DIR}" | |
mkdir "${TARGET_DIR}/home" | |
mount "/dev/mapper/${LVM_PREFIX}_vg00-home" "${TARGET_DIR}/home" | |
mkdir "${TARGET_DIR}/boot/" | |
mount "${TARGET_DISK}${EFI_PART_NUM}" "${TARGET_DIR}/boot" | |
debootstrap --arch $ARCH $RELEASE $TARGET_DIR | |
mount --bind /dev "${TARGET_DIR}dev" | |
mount -t devpts /dev/pts "${TARGET_DIR}dev/pts" | |
mount -t proc proc "${TARGET_DIR}proc" | |
mount -t sysfs sysfs "${TARGET_DIR}sys" | |
mount -t tmpfs tmpfs "${TARGET_DIR}tmp" | |
echo 'deb http://security.ubuntu.com/ubuntu bionic-security main' >> "${TARGET_DIR}/etc/apt/sources.list" | |
chroot "${TMPFS_DIR}" bin/bash | |
export PS1="(chroot) ${PS1}" | |
umount -lr "${TARGET_DIR}" | |
vgchange -an "${LVM_PREFIX}_vg00" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment