forked from gjpin/arch-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_arch_install.sh
152 lines (117 loc) · 4.12 KB
/
1_arch_install.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
150
151
152
#!/bin/bash
set -e
encryption_passphrase=""
root_password=""
user_password=""
hostname="ics"
user_name="leo"
mirror_country="RO"
continent_city="Europe/Bucharest"
swap_size="16"
echo "Setting up pacman mirrors"
curl --silent "https://www.archlinux.org/mirrorlist/?country=$mirror_country&protocol=http&protocol=https&ip_version=4" > /etc/pacman.d/mirrorlist.backup
sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist.backup
cp -Rv /etc/pacman.d/mirrorlist.backup /etc/pacman.d/mirrorlist
pacman -Sy --noconfirm
pacman -S --noconfirm pacman-contrib
rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist
echo "Updating system clock"
timedatectl set-ntp true
timedatectl set-timezone $continent_city
echo "Clearing disk"
printf "x\nz\ny\ny\n" | gdisk /dev/sda
echo "Creating partition tables"
printf "n\n1\n4096\n+512M\nef00\nw\ny\n" | gdisk /dev/sda
printf "n\n2\n\n\n8e00\nw\ny\n" | gdisk /dev/sda
echo "Zeroing partitions"
dd if=/dev/zero of=/dev/sda1 bs=512 count=$(blockdev --getsz /dev/sda1)
dd if=/dev/zero of=/dev/sda2 bs=512 count=$(blockdev --getsz /dev/sda2)
echo "Setting up cryptographic volume"
printf "%s" "$encryption_passphrase" | cryptsetup -h sha512 -s 512 --use-random --type luks2 luksFormat /dev/sda2
printf "%s" "$encryption_passphrase" | cryptsetup luksOpen /dev/sda2 cryptlvm
echo "Creating physical volume"
pvcreate /dev/mapper/cryptlvm
echo "Creating volume volume"
vgcreate vg0 /dev/mapper/cryptlvm
echo "Creating logical volumes"
lvcreate -L +"$swap_size"GB vg0 -n swap
lvcreate -l +100%FREE vg0 -n root
echo "Setting up / partition"
yes | mkfs.ext4 /dev/vg0/root
mount /dev/vg0/root /mnt
echo "Setting up /boot partition"
yes | mkfs.fat -F32 /dev/sda1
mkdir /mnt/boot
mount /dev/sda1 /mnt/boot
echo "Setting up swap"
yes | mkswap /dev/vg0/swap
swapon /dev/vg0/swap
echo "Installing Arch Linux"
yes '' | pacstrap /mnt base base-devel linux-lts lvm2 device-mapper e2fsprogs intel-ucode cryptsetup mesa networkmanager wget
echo "Generating fstab"
genfstab -U /mnt >> /mnt/etc/fstab
echo "Configuring new system"
arch-chroot /mnt /bin/bash <<EOF
set -e
echo "Setting system clock"
ln -fs /usr/share/zoneinfo/$continent_city /etc/localtime
hwclock --systohc --localtime
echo "Setting locales"
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
locale-gen
echo "Adding persistent keymap"
echo "KEYMAP=us" > /etc/vconsole.conf
echo "Setting hostname"
echo $hostname > /etc/hostname
echo "Setting root password"
echo -en "$root_password\n$root_password" | passwd
echo "Creating new user"
useradd -m -G wheel -s /bin/bash $user_name
usermod -a -G video $user_name
echo -en "$user_password\n$user_password" | passwd $user_name
echo "Generating initramfs"
sed -i 's/^HOOKS.*/HOOKS=(base systemd autodetect keyboard sd-vconsole modconf block sd-encrypt sd-lvm2 filesystems fsck)/' /etc/mkinitcpio.conf
sed -i 's/^MODULES.*/MODULES=(ext4 intel_agp i915)/' /etc/mkinitcpio.conf
mkinitcpio -p linux-lts
echo "Setting up systemd-boot"
bootctl --path=/boot install
mkdir -p /boot/loader/
touch /boot/loader/loader.conf
tee -a /boot/loader/loader.conf << END
default archlts
timeout 1
editor 0
END
mkdir -p /boot/loader/entries/
touch /boot/loader/entries/archlts.conf
tee -a /boot/loader/entries/archlts.conf << END
title ArchLinux
linux /vmlinuz-linux-lts
initrd /intel-ucode.img
initrd /initramfs-linux-lts.img
options rd.luks.name=$(blkid -s UUID -o value /dev/sda2)=cryptlvm root=/dev/vg0/root resume=/dev/vg0/swap rd.luks.options=discard i915.fastboot=1 quiet rw
END
echo "Setting up Pacman hook for automatic systemd-boot updates"
mkdir -p /etc/pacman.d/hooks/
touch /etc/pacman.d/hooks/systemd-boot.hook
tee -a /etc/pacman.d/hooks/systemd-boot.hook << END
[Trigger]
Type = Package
Operation = Upgrade
Target = systemd
[Action]
Description = Updating systemd-boot
When = PostTransaction
Exec = /usr/bin/bootctl update
END
echo "Enabling periodic TRIM"
systemctl enable fstrim.timer
echo "Enabling NetworkManager"
systemctl enable NetworkManager
echo "Adding user as a sudoer"
echo '%wheel ALL=(ALL) ALL' | EDITOR='tee -a' visudo
EOF
umount -R /mnt
swapoff -a
echo "ArchLinux is ready. You can reboot now!"