--- Prompt Section (collect all user input here) ---
Disk Selection
echo "Available disks:"
lsblk -d -o NAME,SIZE,MODEL
while true; do
read -p "Enter Disk (e.g. sda, nvme0n1): " disk_input
disk="/dev/{disk_input%/}"
if [ ! -b "disk" ]; then
echo "Disk $disk does not exist. Try again."
continue
fi
break
done
Hostname
while true; do
read -p "Hostname: " hostname
[[ -z "$hostname" ]] && echo "Hostname cannot be empty." && continue
break
done
Root Password
while true; do
read -s -p "Root password: " root_password
echo
read -s -p "Confirm root password: " root_password2
echo
[[ "rootpassword"!="root_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$root_password" ]] && echo "Password cannot be empty." && continue
break
done
Assistant
Username
while true; do
read -p "Username: " user
[[ -z "$user" ]] && echo "Username cannot be empty." && continue
break
done
User Password
while true; do
read -s -p "User password: " user_password
echo
read -s -p "Confirm user password: " user_password2
echo
[[ "userpassword"!="user_password2" ]] && echo "Passwords do not match." && continue
[[ -z "$user_password" ]] && echo "Password cannot be empty." && continue
break
done
Export variables for later use
export disk hostname root_password user user_password
Partition Naming
if [[ "disk"==∗nvme∗]];thenpart1="{disk}p1"
part2="diskp2"elsepart1="{disk}1"
part2="${disk}2"
fi
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@ "part2"/mntmkdir−p/mnt/home,var,.snapshotsmount−onoatime,compress=lzo,ssd,spacecache=v2,discard=async,subvol=@home"part2" /mnt/home
mount -o noatime,compress=lzo,ssd,space_cache=v2,discard=async,subvol=@var "part2"/mnt/vapart2" /mnt/.snapshots
set +e
pacstrap /mnt "installpkgs[@]"if[? -ne 0 ]; then
echo "pacstrap failed. Please check the package list and network connection."
exit 1
fi
set -e
umount -lR /mnt
echo "Installation completed. Please reboot your system."
Your script is a well-structured Arch Linux installer focusing on btrfs subvolumes and a plethora of software packages. It interactively collects user input, partitions the disk, formats and mounts btrfs subvolumes, installs the system using pacstrap, and finally runs a chroot script for further configuration.
Here are some notes and suggestions to improve or fix possible issues:
You're creating subvolumes in /mnt/@ and checking for /mnt/@home, /mnt/@var, and /mnt/@.snapshots, but:
The first line creates /mnt/@ (a root subvolume).
The rest test for /mnt/@home etc., but these subvolumes should be created under /mnt/@, i.e., /mnt/@/home, /mnt/@/var, /mnt/@/.snapshots.
To keep consistent with your mount options (see below where you mount subvolumes @home, @var, @.snapshots), these should be top-level subvolumes created at /mnt/@home rather than inside /mnt/@.
So your logic is correct if you want subvolumes at the root of the btrfs filesystem.
Inside the installation environment (script run as root), it should be fine, but if running from outside (e.g., live ISO), ensure you have root and this file path is accessible.
You can pre-mount /mnt/etc and save mirrorlist there if you prefer to have the target system preconfigured.
and then in your chroot script copy this to /etc/pacman.d/mirrorlist.
Alternatively, run pacstrap first, then run reflector inside the chroot.
6. Handling pacstrap Errors
You're doing:
bash
set +e
pacstrap /mnt "${install_pkgs[@]}"
if [ $? -ne 0 ]; then
echo "pacstrap failed. Please check the package list and network connection."
exit 1
fi
set -e
Better style would be:
bash
if ! pacstrap /mnt "${install_pkgs[@]}"; then
echo "pacstrap failed. Please check the package list and network connection."
exit 1
fi
to avoid set +e mess.
7. Password Security
The script exports passwords as plain text variables and writes them to /mnt/root/install.conf:
Consider changing reflector to run inside chroot or save mirrorlist inside /mnt/etc/pacman.d/ instead of directly overwriting host /etc/pacman.d/mirrorlist.
If you want, I can help you write or review the corresponding chroot.sh or help integrate encryption, LUKS, or other features. Let me know!