Skip to content

Instantly share code, notes, and snippets.

@stif
Last active April 18, 2023 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stif/1bd805afdae2e107e9a151073a47aa2f to your computer and use it in GitHub Desktop.
Save stif/1bd805afdae2e107e9a151073a47aa2f to your computer and use it in GitHub Desktop.
APU2 Ubuntu Installation
#!/bin/bash
DISKLABEL_SYSTEM="Root"
DISKLABEL_STORAGE="Docker"
PARTSIZE_ROOT="8" # in GB
PARTSIZE_SWAP="12" # root+swap (eg 4G root + 4G swap = 8G)
INSTALL_DEVICE=/dev/sda
parted -s $INSTALL_DEVICE mklabel msdos
parted -s $INSTALL_DEVICE unit GB mkpart primary ext2 -- 0 $PARTSIZE_ROOT
#parted -s $INSTALL_DEVICE unit GB mkpart primary linux-swap -- $PARTSIZE_ROOT $PARTSIZE_SWAP
parted -s $INSTALL_DEVICE unit GB mkpart primary ext2 -- $PARTSIZE_ROOT -2
parted -s $INSTALL_DEVICE set 1 boot on
partprobe $INSTALL_DEVICE
fdisk -l $INSTALL_DEVICE
read -p "Press enter to continue"
mkfs.ext4 -L root /dev/sda1
read -p "Press enter to continue"
mkfs.btrfs -f -L docker /dev/sda2
read -p "Press enter to continue"
#mkswap /dev/sda2
#swapon /dev/sda2
mount /dev/sda1 /mnt
read -p "Press enter to continue"
pacman -Sy
pacman -S --noconfirm debootstrap ubuntu-keyring
#debootstrap --arch amd64 xenial /mnt # 16.04
#debootstrap --include=nano --arch amd64 bionic /mnt # 18.04
#debootstrap --include=nano --arch amd64 focal /mnt # 20.04
debootstrap --include=nano --arch amd64 jammy /mnt # 22.04
read -p "Press enter to continue"
cd /mnt
mount -t proc proc proc
mount --rbind /sys sys
mount --rbind /dev dev
cp /etc/resolv.conf etc/resolv.conf
read -p "Press enter to continue"
sudo grub-install --boot-directory=/mnt/boot /dev/sda # does not work any more in chroot..
chroot /mnt /bin/bash
#!/bin/bash
export PATH="$PATH:/usr/sbin:/sbin:/bin"
#date MMDDhhmm
echo "Install Ubuntu on APU2 Part2.."
read -p "Press enter to continue"
# generate locale
sed -i '/^#.* de_AT.* /s/^#//' /etc/locale.gen
sed -i '/^#.* en_US.* /s/^#//' /etc/locale.gen
locale-gen
# set timezone
sudo ln -fs /usr/share/zoneinfo/Europe/Vienna /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
#date
#read -p "enter date (YYMMDD) or press enter: " dateString
#date -s $dateString
date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^ Date:' | cut -d' ' -f 5-)"
read -p "Press enter to continue"
#make sure time and date is right (because of Certifiacates) eg date MMDDHHMMYY
# add repositories and install base packages
#Ubuntu 22.04
echo "deb http://at.archive.ubuntu.com/ubuntu jammy-security main universe" >> /etc/apt/sources.list
echo "deb http://at.archive.ubuntu.com/ubuntu jammy-updates main universe" >> /etc/apt/sources.list
apt update
apt upgrade
apt install -y linux-image-generic grub-pc bridge-utils htop wget psmisc openssh-server hdparm software-properties-common
#apt-transport-https ca-certificates curl software-properties-common #for docker
# write grub config
cat <<EOF > /etc/default/grub
#
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_RECORDFAIL_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
# Uncomment to get a beep at grub start
GRUB_INIT_TUNE="480 440 1"
EOF
grub-install /dev/sda
update-grub
# write fstab config
cat <<EOF > /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sda1 / ext4 errors=remount-ro 0 1
#/dev/sda2 swap swap defaults 0 0
/dev/sda2 /var/lib/docker btrfs defaults 0 2
EOF
# create User
adduser maintain
usermod -aG sudo,adm maintain
# get MAC Address of first Network Interface and add 3
# this will be the MAC Address of the new MacVlan Interface
ENP1S0_MAC=`cat /sys/class/net/enp1s0/address`
re="^(([0-9A-Fa-f]{2}[:-]){5})([0-9A-Fa-f]{2})$"
if [[ $ENP1S0_MAC =~ $re ]]; then
first_tuples=${BASH_REMATCH[1]}
last_tuple=${BASH_REMATCH[3]}
#new_tuple=$(($last_tuple+3))
new_tuple=`printf "%X" $((16#$last_tuple+3))`
NEW_MAC=$first_tuples$new_tuple
fi
echo "MAC Address of enp1s0 Network Interface: "$ENP1S0_MAC
echo "MAC Address of macvlan Network Interface: "$NEW_MAC
# netplan network config
cat <<EOF > /etc/netplan/enp1s0.yaml
network:
version: 2
# renderer: networkd
ethernets:
enp1s0:
dhcp4: true
EOF
sudo netplan apply
## systemd-networkd config
#systemctl enable systemd-networkd
#cat <<EOF > /etc/systemd/network/91-macvlan0.network
#[Match]
#Name=enp1s0
#[Network]
#MACVLAN=macvlan0
##LinkLocalAddressing=no
#EOF
#cat > 92-macvlan0.netdev <<EOF
#[NetDev]
#Name=macvlan0
#Kind=macvlan
#MACAddress=$NEW_MAC
#[MACVLAN]
#Mode=bridge
#EOF
#cat <<EOF > /etc/systemd/network/93-macvlan0.network
#[Match]
#Name=macvlan0
#[Network]
#DHCP=yes
#IPForward=yes
##LinkLocalAddressing=no
#EOF
#cat <<EOF > /etc/systemd/network/94-enp2s0.network
#[Match]
#Name=enp2s0
#[Network]
#DHCP=ipv4
#EOF
#cat <<EOF > /etc/systemd/network/95-enp3s0.network
#[Match]
#Name=enp3s0
#[Network]
#DHCP=ipv4
#EOF
echo cnt-host > /etc/hostname
#nano /etc/hosts #add cnt-host after localhost
#127.0.0.1 localhost cnt-host
cat <<EOF > /etc/hosts
127.0.0.1 localhost cnt-host
::1 localhost ip6-localhost ip6-loopback cnt-host
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
#nano /etc/inputrc #enable search history "page up"and "page down"
#nano /etc/dhcp/dhclient.conf #set timeout to 30
#nano /etc/systemd/system/network-online.target.wants/networking.service #TimeoutStartSec=30sec
sed -i 's/^timeout 300;/timeout 30;/' /etc/dhcp/dhclient.conf
#sed -i 's/^TimeoutStartSec=5min/TimeoutStartSec=30sec/' /etc/systemd/system/network-online.target.wants/networking.service # missing in systemd-networkd!!
#echo -e "[Service]\nTimeoutStartSec=20sec" > /etc/systemd/system/networking.service.d/timeout.conf
#sudo bash -c 'echo -e "[Service]\nTimeoutStartSec=20sec" > /etc/systemd/system/networking.service.d/timeout.conf'
# configure unattended upgrades (software-properties-common needs to be installed prior!)
sed -i 's/^\/\/Unattended-Upgrade::Remove-Unused-Kernel-Packages "false";/Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";/' /etc/apt/apt.conf.d/50unattended-upgrades
sed -i 's/^\/\/Unattended-Upgrade::Remove-Unused-Dependencies "false";/Unattended-Upgrade::Remove-Unused-Dependencies "true";/' /etc/apt/apt.conf.d/50unattended-upgrades
sed -i 's/^\/\/Unattended-Upgrade::Automatic-Reboot "false";/Unattended-Upgrade::Automatic-Reboot "true";/' /etc/apt/apt.conf.d/50unattended-upgrades
sed -i 's/^\/\/Unattended-Upgrade::Automatic-Reboot-Time "02:00";/Unattended-Upgrade::Automatic-Reboot-Time "02:00";/' /etc/apt/apt.conf.d/50unattended-upgrades
read -p "Press enter to continue"
# install docker
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y docker-ce
sudo systemctl enable docker
# updated e2fsck
cd ~
wget http://launchpadlibrarian.net/651988780/e2fsprogs_1.47.0-1ubuntu1_amd64.deb
wget http://launchpadlibrarian.net/651988783/libext2fs2_1.47.0-1ubuntu1_amd64.deb
sudo dpkg -i libext2fs2_1.47.0-1ubuntu1_amd64.deb
sudo dpkg -i 2fsprogs_1.47.0-1ubuntu1_amd64.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment