This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchroot.sh
executable file
·123 lines (90 loc) · 3.02 KB
/
chroot.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
#!/bin/bash
# Script run on the new root as the root user.
### SETUP
# Set variables from args.
if [ $# -ne 6 ]; then
echo "USAGE: ./chroot.sh BOOT_MNT SWAP_DIR SWAP_SIZE HOSTNAME ENC_DEV ENC_NAME"
exit 1
fi
BOOT_MNT="$1"
SWAP_DIR="$2"
SWAP_SIZE="$3"
HOSTNAME="$4"
ENC_DEV="$5"
ENC_NAME="$6"
# Exit on errors.
set -e
### SET TIMEZONE
echo "Setting timezone"
ln -sf /usr/share/zoneinfo/America/Denver /etc/localtime
hwclock --systohc
### SET LOCALE
echo "Setting locale"
sed -i 's/#en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
### SET KEYBOARD LAYOUT
echo "Saving keyboard layout"
echo "KEYMAP=colemak" > /etc/vconsole.conf
### SETUP NETWORK
# Set hostname.
echo "Configuring network"
echo "$HOSTNAME" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "::1 localhost" >> /etc/hosts
echo "127.0.1.1 $HOSTNAME.localdomain" >> /etc/hosts
# Install NetworkManager to connect to Internet after reboot.
echo "Installing NetworkManager"
pacman -S --noconfirm networkmanager
systemctl enable NetworkManager.service
### SETUP BOOT
# Install boot-related packages.
echo "Installing boot-related packages"
# grub - boot loader
# efibootmgr - needed for grub-install to add grub to boot loader
# intel-ucode - microcode for Intel processor
pacman -S --noconfirm \
grub \
efibootmgr \
intel-ucode
# Configure mkinitcpio.
echo "Configuring mkinitcpio"
# Most of these are the hooks that were already there by default, except...
# - encrypt - add support for encrypted root
# - btrfs - add support for btrfs root
# - keymap - support using alternate keyboard layout when entering encryption password
sed -i 's/^HOOKS=.*$/HOOKS=(base udev autodetect keyboard keymap modconf block encrypt btrfs filesystems fsck)/' /etc/mkinitcpio.conf
# Add the btrfs binary in order to do maintenence on system without mounting it.
sed -i 's#^BINARIES=.*$#BINARIES=(/usr/bin/btrfs)#' /etc/mkinitcpio.conf
# Regenerate initcpio.
mkinitcpio -P
# Set up bootloader.
echo "Installing bootloader"
# Install grub to EFI.
grub-install --target=x86_64-efi --efi-directory="$BOOT_MNT" --bootloader-id=GRUB
# Enable grub to boot into encrypted partition.
sed -i "s/^GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX=\"cryptdevice=UUID=$(lsblk -dno UUID $ENC_DEV):$ENC_NAME\"/" /etc/default/grub
# Generate grub config.
grub-mkconfig -o /boot/grub/grub.cfg
### SETUP SWAPFILE
echo "Setting up swapfile"
cd $SWAP_DIR
# Create a zero-length file.
truncate -s 0 main
# Turn off copy-on-write on the file.
chattr +C main
# Turn off compression on the file.
btrfs property set main compression none
# Grow the file to the desired swap size.
fallocate -l ${SWAP_SIZE}G main
# Only let root write/read the swap file.
chmod 600 main
# Make the file be used as swap.
mkswap main
# Update fstab to automatically mount and use the swapfile.
echo "$SWAP_DIR/main none swap sw 0 0" >> /etc/fstab
# TODO: get hibernate working
### SET ROOT PASSWORD
echo "Please set the root password"
passwd
echo "Exiting chroot"