-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk.sh
executable file
·154 lines (128 loc) · 4.68 KB
/
disk.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
153
#!/bin/sh
[ "$DB" = '' ] && err '$DB variable not set. This script is not ment to be run by the user.' && exit 1
unmount() {
sync
swapoff -a > /dev/null 2>&1
umount -q "$BOOT_PART" > /dev/null 2>&1
umount -Rq "$INSTALL_DIR" > /dev/null 2>&1
swapoff "$LVM_DIR/swap" > /dev/null 2>&1
lvchange -an "$LVM_GROUP_NAME" > /dev/null 2>&1
cryptsetup close "$CRYPT_FILE" > /dev/null 2>&1
umount -q "$CRYPT_FILE" > /dev/null 2>&1
sync
}
fdisk -l "$DISK" > $OUTPUT
info_garr "Partitioning the disk..."
confirm 'N barr' "Start partitioning <path>$DISK</path>? $RED(DATA WARNING)" '' 'err "Said no to continuation prompt"; exit 1'
info_brr "Unmouting"
unmount
vgremove -f "$LVM_GROUP_NAME" > /dev/null 2>&1
unmount
(
echo g # set partitioning scheme to GPT
echo n # Create BOOT partition
echo 1 # partition number 1
echo # default - start at beginning of disk
echo +$BOOT_SIZE
echo t # set partition type
echo 1 # to EFI partition
echo n # Create LVM partition
echo 2 # partion number 2
echo " " # default, start immediately after preceding partition
if [ "$ENCRYPT" = '1' ]; then
if [ "$CRYPT_SIZE" = '' ]; then
echo
else
echo +$CRYPT_SIZE
fi
else
if [ "$LVM_SIZE" = '' ]; then
echo
else
echo +$LVM_SIZE
fi
fi
echo t # set partition type
echo 2
echo 43 # to LV
echo p # print the in-memory partition table
echo w # write changes
echo q # quit
) | fdisk $DISK > $OUTPUT
info "Partitioning finished."
mkdir -p "$INSTALL_DIR"
if [ "$ENCRYPT" = '1' ]; then
info_garr "Setting up encryption on <path>$CRYPT_PART</path>"
confirm 'N barr' "Setup luks on <path>$CRYPT_PART</path>? $RED(DATA WARNING)" '' 'err "Said no to continuation prompt"; exit 1'
if [ "$LUKS_PASSWORD" != '' ]; then
info_barr "Automaticly filling password..."
if ! echo "$LUKS_PASSWORD" | cryptsetup luksFormat $LUKSFORMAT_ARGUMENTS "$CRYPT_PART" > $OUTPUT; then
err "LUKS error"; exit 1
fi
info_barr "Opening <path>$CRYPT_PART</path> as <path>$CRYPT_NAME</path"
info_barr "Automaticly filling password..."
if ! echo "$LUKS_PASSWORD" | cryptsetup open "$CRYPT_PART" "$CRYPT_NAME" > $OUTPUT; then
err "LUKS error"; exit 1
fi
else
while true; do
if cryptsetup luksFormat $LUKSFORMAT_ARGUMENTS "$CRYPT_PART"; then
break
fi
confirm 'Y barr ignore' 'Do you wanna retry?' '' ''
done
while true; do
info_barr "Opening <path>$CRYPT_PART</path> as <path>$CRYPT_NAME</path"
if cryptsetup open "$CRYPT_PART" "$CRYPT_NAME"; then
break
fi
confirm 'Y barr ignore' 'Do you wanna retry?' '' ''
done
fi
LVM_TARGET_FILE="$CRYPT_FILE"
else
LVM_TARGET_FILE="$LVM_PART"
fi
info "Setting up LVM on <path>$LVM_PART</path>"
info "Creating LVM group <path>$LVM_GROUP_NAME</path>"
pvcreate --force $LVM_TARGET_FILE > $OUTPUT || err "LVM error" && exit
vgcreate $LVM_GROUP_NAME $LVM_TARGET_FILE > $OUTPUT || err "LVM error" && exit
info_garr "Creating volumes"
if [ "$ENABLE_SWAP" = '1' ]; then
info_barr "Creating SWAP"
lvcreate -C y -L $SWAP_SIZE $LVM_GROUP_NAME -n swap > $OUTPUT || err "LVM error" && exit
fi
info_barr "Creating ROOT of size $ROOT_SIZE"
lvcreate -C y -L $ROOT_SIZE $LVM_GROUP_NAME -n root > $OUTPUT || err "LVM error" && exit
info_barr "Creating HOME of size 100%FREE"
lvcreate -C y -l 100%FREE $LVM_GROUP_NAME -n home > $OUTPUT || err "LVM error" && exit
info_garr "Formatting volumes"
if [ "$ENABLE_SWAP" = '1' ]; then
info_barr "SWAP"
mkswap -L swap $LVM_DIR/swap > $OUTPUT || err "LVM error" && exit
fi
info_barr "ROOT"
$ROOT_FORMAT_COMMAND > $OUTPUT 2>&1 || err "LVM error" && exit
info_barr "HOME"
$HOME_FORMAT_COMMAND > $OUTPUT 2>&1 || err "LVM error" && exit
info_barr "BOOT"
$BOOT_FORMAT_COMMAND > $OUTPUT 2>&1 || err "LVM error" && exit
info_garr "Mounting volumes"
info_barr "<path>$LVM_DIR/root</path> to <path>$INSTALL_DIR</path>"
mount "$LVM_DIR/root" "$INSTALL_DIR" > $OUTPUT || err "LVM error" && exit
info "<path>$LVM_DIR/home</path> to <path>$INSTALL_DIR/home/$USER1</path>"
mkdir -p "$INSTALL_DIR/home/$USER1"
mount "$LVM_DIR/home" "$INSTALL_DIR/home/$USER1" > $OUTPUT || err "LVM error" && exit
info "<path>$BOOT_PART</path> to <path>$BOOT_DIR</path>"
mkdir -p "$BOOT_DIR"
mount "$BOOT_PART" "$BOOT_DIR" > $OUTPUT || err "LVM error" && exit
if [ "$ENABLE_SWAP" = '1' ]; then
info "Turning swap on"
swapon "$LVM_DIR/swap" > $OUTPUT || err "LVM error" && exit
fi
. "$DB"/chroot/prepare-chroot.sh
unmount
if [ "$AUTO_REBOOT" = '0' ]; then
confirm 'Y ignore' "Reboot?" '' 'exit 1;'
fi
reboot