-
Notifications
You must be signed in to change notification settings - Fork 0
/
archLinuxInstall.sh
149 lines (111 loc) · 4.02 KB
/
archLinuxInstall.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
loadkeys us
if [ -d /sys/firmware/efi/efivars ]; then
uefi_available=true
else
uefi_available=false
fi
if [ -e /sys/firmware/bios ]; then
bios_available=true
else
bios_available=false
fi
if [ "$uefi_available" == true ] && [ "$bios_available" == true ]; then
read -p "Both UEFI and BIOS are available. Which mode do you want to use? (uefi/bios): " boot_mode
while [[ "$boot_mode" != "uefi" && "$boot_mode" != "bios" ]]; do
echo "Invalid choice. Please enter 'uefi' or 'bios'."
read -p "Which mode do you want to use? (uefi/bios): " boot_mode
done
elif [ "$uefi_available" == true ]; then
boot_mode="uefi"
echo "Only UEFI is available. Proceeding with UEFI installation."
elif [ "$bios_available" == true ]; then
boot_mode="bios"
echo "Only BIOS is available. Proceeding with BIOS installation."
else
echo "Neither UEFI nor BIOS is available on this system. Exiting."
exit 1
fi
timedatectl set-ntp true
total_space=$(lsblk -dn -o SIZE -b /dev/sda | awk '{ print int($1/1024/1024/1024) }')
echo "Total disk space available: $total_space GiB"
# Reserved space for boot partition
if [ "$boot_mode" == "uefi" ]; then
reserved_space=1 # GiB
else
reserved_space=0 # BIOS doesn't require a separate boot partition
fi
echo "Note: $reserved_space GiB will be reserved for the $boot_mode boot partition."
read -p "Enter hostname: " hostname
read -s -p "Enter root password: " root_password
echo
read -p "Enter space for root partition (in GiB, excluding $reserved_space GiB for $boot_mode boot partition): " root_space
while [[ $root_space -le $reserved_space || $root_space -gt $total_space ]]; do
echo "Invalid root partition size. Please enter a value between $((reserved_space + 1)) and $total_space GiB."
read -p "Enter space for root partition (in GiB, excluding $reserved_space GiB for $boot_mode boot partition): " root_space
done
read -p "Do you want a swap partition? (yes/no): " create_swap
if [ "$create_swap" == "yes" ]; then
read -p "Enter swap space (in GiB): " swap_space
while [[ $swap_space -le 0 || $((root_space + swap_space)) -gt $total_space ]]; do
echo "Invalid swap partition size. Please enter a value between 1 and $((total_space - root_space)) GiB."
read -p "Enter swap space (in GiB): " swap_space
done
swap_end=$((root_space + swap_space))
else
swap_end=$root_space
fi
if [ "$boot_mode" == "uefi" ]; then
parted /dev/sda --script mklabel gpt \
mkpart primary fat32 1MiB 1GiB \
set 1 esp on \
mkpart primary ext4 1GiB "${root_space}GiB"
echo "UEFI boot partition is taking 1 GiB space."
if [ "$create_swap" == "yes" ]; then
parted /dev/sda --script mkpart primary linux-swap "${root_space}GiB" "${swap_end}GiB"
fi
mkfs.fat -F32 /dev/sda1
mkfs.ext4 /dev/sda2
if [ "$create_swap" == "yes" ]; then
mkswap /dev/sda3
swapon /dev/sda3
fi
mount /dev/sda2 /mnt
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
else
parted /dev/sda --script mklabel msdos \
mkpart primary ext4 1MiB "${root_space}GiB"
echo "BIOS boot partition is taking $reserved_space GiB space."
if [ "$create_swap" == "yes" ]; then
parted /dev/sda --script mkpart primary linux-swap "${root_space}GiB" "${swap_end}GiB"
fi
mkfs.ext4 /dev/sda1
if [ "$create_swap" == "yes" ]; then
mkswap /dev/sda2
swapon /dev/sda2
fi
mount /dev/sda1 /mnt
fi
reflector --verbose --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
pacstrap /mnt base linux linux-firmware
genfstab -U /mnt >> /mnt/etc/fstab
arch-chroot /mnt <<EOF
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
hwclock --systohc
echo "$hostname" > /etc/hostname
pacman -S --noconfirm networkmanager
systemctl enable NetworkManager
echo "root:$root_password" | chpasswd
if [ "$boot_mode" == "uefi" ]; then
pacman -S --noconfirm grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
else
pacman -S --noconfirm grub
grub-install --target=i386-pc /dev/sda
fi
grub-mkconfig -o /boot/grub/grub.cfg
EOF
echo "$hostname" > /mnt/hostname.txt
umount -R /mnt
reboot