-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpine_setup.sh
More file actions
90 lines (73 loc) · 2.27 KB
/
alpine_setup.sh
File metadata and controls
90 lines (73 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# --- UEFI CONFIGURATION ---
DISK="/dev/vda"
IP_ADDR="185.249.74.171"
GATEWAY="185.249.74.1"
NETMASK="255.255.255.255"
ROOT_PASS="alpine123"
ALPINE_REL="3.23"
ALPINE_VER="3.23.3"
echo "!!! STARTING UEFI INSTALL ON $DISK !!!"
sleep 2
# 1. Partitioning (GPT for UEFI)
parted -s $DISK mklabel gpt
parted -s $DISK mkpart ESP fat32 1MiB 513MiB
parted -s $DISK set 1 esp on
parted -s $DISK mkpart primary ext4 513MiB 100%
# 2. Formatting
mkfs.vfat -F 32 "${DISK}1"
mkfs.ext4 -F "${DISK}2"
# 3. Mounting
mkdir -p /mnt/alpine
mount "${DISK}2" /mnt/alpine
mkdir -p /mnt/alpine/boot/efi
mount "${DISK}1" /mnt/alpine/boot/efi
# 4. Bootstrap Alpine
cd /tmp
wget https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_REL}/releases/x86_64/alpine-minirootfs-${ALPINE_VER}-x86_64.tar.gz
tar -xvpzf alpine-minirootfs-${ALPINE_VER}-x86_64.tar.gz -C /mnt/alpine
# 5. Prepare Chroot
cp /etc/resolv.conf /mnt/alpine/etc/resolv.conf
for dir in /dev /dev/pts /proc /sys /run; do mount --bind $dir /mnt/alpine$dir; done
# 6. Internal Setup Script
cat <<EOF > /mnt/alpine/setup.sh
#!/bin/sh
echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_REL}/main" > /etc/apk/repositories
echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_REL}/community" >> /etc/apk/repositories
apk update
# Install UEFI Bootloader & Kernel
apk add linux-virt grub-efi efibootmgr iproute2 openssh
# Set Root Password
echo "root:${ROOT_PASS}" | chpasswd
# Configure Networking
cat <<NET > /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address ${IP_ADDR}
netmask ${NETMASK}
gateway ${GATEWAY}
up ip route add ${GATEWAY} dev eth0
up ip route add default via ${GATEWAY}
NET
# Install GRUB for UEFI
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=alpine --removable --no-nvram
# Create GRUB Config
cat <<GCFG > /etc/default/grub
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR="Alpine"
GRUB_CMDLINE_LINUX_DEFAULT="modules=ext4 quiet root=${DISK}2"
GCFG
grub-mkconfig -o /boot/grub/grub.cfg
# Enable Services
rc-update add networking boot
rc-update add sshd default
EOF
# 7. Execute Internal Setup
chroot /mnt/alpine /bin/sh /setup.sh
rm /mnt/alpine/setup.sh
# 8. Cleanup
umount -l /mnt/alpine/boot/efi
umount -l /mnt/alpine
echo "UEFI INSTALL DONE! Unmount GParted and Reboot."