-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_arch_btrfs.sh
138 lines (104 loc) · 3.52 KB
/
install_arch_btrfs.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
#!/bin/bash
#GPL3.0-ONLY
# MODIFIED OF MISTER @Eliminater74
# Ensure you have root privileges
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
# Check for active network connection
echo "Checking network connection..."
if ! ping -c 1 archlinux.org &> /dev/null; then
exit 1
fi
# Update system clock
timedatectl set-ntp true
# List available storage devices
echo "Available storage devices:"
lsblk
# Prompt for the storage device to use
echo "Enter the device you want to install Arch Linux on"
echo "0 = exit, 1 = NVME, 2 = HDD/SSD(virtualdisk)"
read -r disktype
if [ $disktype -eq 1 ]; then
$nvme
elif [ $disktype -eq 2 ]; then
# Ensure the user has provided a valid device
if [ ! -b "$dev" ]; then
echo "Invalid device: $dev"
exit 1
fi
# Prompt for username and password
read -p "Enter your username: " username
while true; do
read -s -p "Enter your password: " password
echo
read -s -p "Confirm your password: " password_confirm
echo
[ "$password" = "$password_confirm" ] && break
echo "Passwords do not match. Please try again."
done
# Encrypt the password
encrypted_password=$(openssl passwd -6 "$password")
# Partition the disk
echo "Partitioning the disk..."
parted -s "$dev" mklabel gpt
parted -s "$dev" mkpart primary fat32 1MiB 512MiB
parted -s "$dev" mkpart primary linux-swap
parted -s "$dev" set 1 esp on
parted -s "$dev" mkpart primary btrfs 512MiB 100%
# Format the partitions
echo "Formatting the partitions..."
mkfs.fat -F32 "${dev}p1"
mkfs.btrfs "${dev}p2"
# Mount the BTRFS partition and create subvolumes
echo "Setting up BTRFS..."
mount "${dev}2" /mnt
btrfs su cr /mnt/@
btrfs su cr /mnt/@home
btrfs su cr /mnt/@snapshots
umount /mnt
# Remount the BTRFS subvolumes
mount -o noatime,space_cache,compress=zstd,subvol=@ "${dev}2" /mnt
mkdir -p /mnt/{boot,home,.snapshots}
mount -o noatime,space_cache,compress=zstd,subvol=@home "${dev}2" /mnt/home
mount -o noatime,space_cache,compress=zstd,subvol=@snapshots "${dev}2" /mnt/.snapshots
mount "${dev}1" /mnt/boot
# Install essential packages
echo "Installing essential packages..."
pacstrap /mnt base linux linux-firmware btrfs-progs grub grub-btrfs rsync efibootmgr snapper reflector snap-pac zram-generator sudo micro xorg-server xorg-apps git plasma-meta plasma-wayland-session kde-utilities kde-system dolphin-plugins kde-graphics neofetch zsh man-db man-pages texinfo samba chromium nano sddm sddm-kcm gnome-disk-utility ksysguard kate xorg plasma plasma-wayland-session kde-applications
# Generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# Chroot into the new system
arch-chroot /mnt /bin/bash <<EOF
# Set timezone
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
hwclock --systohc
# Localization
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
# Network configuration
echo "archlinux" > /etc/hostname
cat << EOL > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 archlinux.localdomain archlinux
EOL
# Set root password
echo "root:${encrypted_password}" | chpasswd -e
# Create user
useradd -m -G wheel -s /bin/zsh $username
echo "${username}:${encrypted_password}" | chpasswd -e
sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
# Install bootloader
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
grub-mkconfig -o /boot/grub/grub.cfg
# Enable necessary services
systemctl enable sddm
systemctl enable NetworkManager
systemctl enable zram-generator
EOF
# Unmount all partitions and reboot
umount -R /mnt
reboot