You are not logged in.

#1 2015-06-27 20:46:21

avi9526
Member
Registered: 2015-05-15
Posts: 116

[script] Arch auto-install on encrypted disk

This script is not failsafe, it's not failsafe at all…
I write it for myself, and used it to install Arch (2015-06) on my notebook and virtual machine (with KDE desktop), maybe it will be useful for someone…

You need to have direct Internet connection (for packages), second PC (for ssh connection) and two disks. On my notebook I used 1GB USB flash disk to store GRUB and dm-crypt header and key, and the internal notebook HDD was used as dm-crypt headless storage. On virtual machine I created two disks (128М and 16G) for same purpose.

Edit variables at beginning of script to match your system (or script will fail). It takes a lot of time (because of packages) and ask for user password somewhere, so watch console.

#!/bin/bash

# Run on guest following command:
#
# passwd # define root password
# systemctl start sshd.service # start ssh server
# ip ad # check ip of machine to connect by ssh
#
# Then connect by SSH from host
#
# scp ./install root@IP:
# ssh root@IP
# fdisk -l # check available disks
# nano ./install # edit DiskBoot and DiskRoot variable to match existing disks
# chmod +x ./install
# ./install

Hostname="yed1osEm"
DiskBoot="/dev/vda"
DiskRoot="/dev/vdb"
VG="vg1"
LVSwap="swap"
SwapSize="1G"
LVRoot="root"
RootSize="10G"
LVHome="home"
HomeSize="+85%FREE"
TimeZone="Europe/Kiev"
User=avi9526

echo "--------------------------------------------------------"
echo " Creating partitions"
echo "--------------------------------------------------------"
dd if=/dev/zero of="$DiskBoot" bs=512 count=20480
parted -s -a optimal "$DiskBoot" mklabel msdos -- mkpart primary ext4 1 -1
DiskGrub="$DiskBoot"
DiskBoot="${DiskBoot}1"
# echo "Overriding partition with pseudo-random data..."
# dd if=/dev/urandom of="${DiskRoot}" bs=4M
#parted -s -a optimal "$DiskRoot" mklabel msdos -- mkpart primary 1 -1
#DiskRoot="${DiskRoot}1"
echo "--------------------------------------------------------"
echo " Setup encrypted partition"
echo "--------------------------------------------------------"
Key="$(basename "$DiskRoot").key"
Map="$(basename "$DiskRoot")_crypt"
DiskRootEnc="/dev/mapper/$Map"
Head="$(basename "$DiskRoot").header"
truncate -s 2M "$Head"
dd if=/dev/urandom of="$Key" bs=512 count=4 iflag=fullblock
cryptsetup -q luksFormat -c aes-xts-plain64 -s 512 -d "$Key" "$DiskRoot" --header "$Head"
cryptsetup -q luksOpen -d "$Key" "$DiskRoot" "$Map" --header "$Head"
echo "--------------------------------------------------------"
echo " Setup LVM2"
echo "--------------------------------------------------------"
pvcreate "$DiskRootEnc"
vgcreate "$VG" "$DiskRootEnc"
lvcreate -L $SwapSize "$VG" -n "$LVSwap"
LVSwap="/dev/mapper/$VG-$LVSwap"
mkswap "$LVSwap"
swapon "$LVSwap"
lvcreate -L $RootSize "$VG" -n "$LVRoot"
LVRoot="/dev/mapper/$VG-$LVRoot"
lvcreate -l $HomeSize "$VG" -n "$LVHome"
LVHome="/dev/mapper/$VG-$LVHome"
echo "--------------------------------------------------------"
echo " Formatting partitions and copy some data"
echo "--------------------------------------------------------"
Mount="/mnt"
mkfs.ext4 -F "$LVRoot"
mount "$LVRoot" "$Mount"
mkfs.ext4 -F "$LVHome"
mkdir "$Mount/home"
mount "$LVHome" "$Mount/home"
mkfs.ext4 -F "$DiskBoot"
mkdir "$Mount/boot"
mount "$DiskBoot" "$Mount/boot"
cp "$Head" "$Mount/boot"
cp "$Key" "$Mount/boot"
echo "--------------------------------------------------------"
echo " Install required packages"
echo "--------------------------------------------------------"
pacstrap "$Mount" base base-devel
#cp "/etc/os-release" "$Mount/etc/os-release"
genfstab -p "$Mount" >> "$Mount/etc/fstab"
echo "#!/bin/bash
echo \"--------------------------------------------------------\"
echo \" Changing partitions configuration files\"
echo \"--------------------------------------------------------\"
sed -i -r 's/(HOOKS=\".+block\s)(filesystems.*\")/\1sd-encrypt sd-lvm2 \2/g' \"/etc/mkinitcpio.conf\"
sed -i -r 's/(HOOKS=\".+udev\s)(.*\")/\1systemd \2/g' \"/etc/mkinitcpio.conf\"
sed -i -r 's/(FILES=\".*)\"/\1\/boot\/$Head \/boot\/$Key\"/g' \"/etc/mkinitcpio.conf\"
#echo \"${Map}    PARTUUID=$(blkid $DiskRoot -s PARTUUID -o value)    /boot/$Key    header=/boot/$Head\" >> \"/etc/crypttab.initramfs\"
echo \"${Map}    ${DiskRoot}    /boot/$Key    header=/boot/$Head\" >> \"/etc/crypttab.initramfs\"
sed -i -r 's|${DiskBoot}|UUID=$(blkid $DiskBoot -s UUID -o value)|g' \"/etc/fstab\"
echo \"--------------------------------------------------------\"
echo \" System settings\"
echo \"--------------------------------------------------------\"
#passwd
#nano \"/etc/locale.gen\"
sed -i -r 's/#(en_US.*)/\1/g' \"/etc/locale.gen\"
locale-gen
ln -s \"/usr/share/zoneinfo/$TimeZone\" \"/etc/localtime\"
echo \"$Hostname\" > \"/etc/hostname\"
echo \"--------------------------------------------------------\"
echo \" Installing GRUB and making initramfs image\"
echo \"--------------------------------------------------------\"
pacman -S --noconfirm grub-bios
mkinitcpio -p linux
grub-install \"$DiskGrub\" --force
grub-mkconfig -o /boot/grub/grub.cfg
echo \"--------------------------------------------------------\"
echo \" Configuring user settings\"
echo \"--------------------------------------------------------\"
pacman -S --noconfirm sudo
useradd -m -G wheel -s /bin/bash \"$User\"
echo \"********************************************************\"
passwd \"$User\"
echo \"********************************************************\"
sed -i -r 's/^#+\s*(%wheel\s+ALL=\(ALL\)\s+ALL)$/\1/g' /etc/sudoers
sed -i -r 's/^#+\s*(%sudo\s+ALL=\(ALL\)\s+ALL)$/\1/g' /etc/sudoers
passwd -l root
sed -i -r 's/^(umask\s+)[0-9]+$/\1077/g' /etc/profile
echo \"--------------------------------------------------------\"
echo \" Installing Network Manager\"
echo \"--------------------------------------------------------\"
pacman -S --noconfirm networkmanager openssh
systemctl enable NetworkManager
echo \"--------------------------------------------------------\"
echo \" Installing Login Manager\"
echo \"--------------------------------------------------------\"
pacman -S --noconfirm xorg-server sddm wget
systemctl enable sddm
echo \"--------------------------------------------------------\"
echo \" Installing Boot Splash Screen\"
echo \"--------------------------------------------------------\"
chmod +x \"get_plymouth.sh\"
Temp=\"/src/pkg\"
mkdir -p \"\$Temp\"
chmod -R 777 \"\$Temp\"
pacman -S --noconfirm cairo libdatrie libthai libxft pango docbook-xml libxslt docbook-xsl
sudo -u $User ./get_plymouth.sh \"\$Temp\"
pacman -U --noconfirm \"\$Temp/plymouth/plymouth\"*\".pkg.tar.xz\"
sed -i -r 's/(HOOKS=\".+udev\s)(.*\")/\1plymouth \2/g' \"/etc/mkinitcpio.conf\"
sed -i -r 's/(Theme=).+/\1spinfinity/g' \"/etc/plymouth/plymouthd.conf\"
sed -i -r 's/(ShowDelay=)[0-9]+/\10/g' \"/etc/plymouth/plymouthd.conf\"
mkinitcpio -p linux
sed -i -r 's/(GRUB_CMDLINE_LINUX_DEFAULT=\"quiet)(.+)/\1 splash\2/g' \"/etc/default/grub\"
sed -i -r 's/(GRUB_TIMEOUT=)[0-9]+/\12/g' \"/etc/default/grub\"
grub-mkconfig -o /boot/grub/grub.cfg
echo \"--------------------------------------------------------\"
echo \" Setting up desktop\"
echo \"--------------------------------------------------------\"
pacman -S --noconfirm plasma kde-applications sddm-kcm kcmsystemd xf86-input-synaptics firefox pulseaudio pulseaudio-alsa pavucontrol audacious gufw unzip ttf-ubuntu-font-family 
# Check available sessions
# 	ls /usr/share/xsessions/
# Edit /etc/lightdm/lightdm.conf
# If using lightdm add/edit lines
#	[SeatDefaults]
#	user-session=plasma
#	greeter-session=lightdm-kde-greeter
# Check ~/.dmrc as well
# For errors see /var/log/lightdm/lightdm.log or other
# Fix problem
mv /usr/share/xsessions/plasma.desktop /usr/share/xsessions/50-plasma.desktop
mv /usr/share/xsessions/plasma-mediacenter.desktop /usr/share/xsessions/60-plasma-mediacenter.desktop
" > "$Mount/setup_script.sh"
chmod +x "$Mount/setup_script.sh"
echo "#!/bin/bash
cd \"\$1\"
wget \"https://aur.archlinux.org/packages/pl/plymouth/plymouth.tar.gz\"
tar -xvf plymouth.tar.gz
cd \"./plymouth\"
makepkg -s
cd /
" > "$Mount/get_plymouth.sh"
arch-chroot "$Mount" "/setup_script.sh"
echo "--------------------------------------------------------"
echo " Unmounting partitions"
echo "--------------------------------------------------------"
rm "$Mount/setup_script.sh"
umount "$Mount/boot"
umount "$Mount"
reboot

Offline

Board footer

Powered by FluxBB