-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluks-encrypted-persistence.sh
98 lines (79 loc) · 2.83 KB
/
luks-encrypted-persistence.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
#!/bin/bash
# Color variables
WHITE='\033[1;37m'
PINK='\033[38;5;213m'
BRIGHT_GREEN='\e[1;92m'
RESET='\033[0m'
# Warning Banner
echo ""
echo -e "${BRIGHT_GREEN}+--------------------------------------------------------------+${RESET}"
echo -e "${BRIGHT_GREEN}| WARNING: The selected partition will be COMPLETELY ERASED! |${RESET}"
echo -e "${BRIGHT_GREEN}| BACKUP your data before proceeding! ALL data still present |${RESET}"
echo -e "${BRIGHT_GREEN}| on partitions that gets encrypted will be PERMANENTLY LOST |${RESET}"
echo -e "${BRIGHT_GREEN}+--------------------------------------------------------------+${RESET}"
# Prompt for the partition
echo ""
echo -e "${WHITE}Please enter partition to be encrypted (e.g. /dev/sdxx):${RESET}"
echo ""
read PARTITION
# Check if the partition is empty
if [ -z "$PARTITION" ]; then
echo -e "${WHITE}No partition entered. Exiting.${RESET}"
exit 1
fi
# Check if the partition exists
if ! sudo fdisk -l | grep -q "$PARTITION"; then
echo -e "${WHITE}Partition $PARTITION does not exist. Exiting.${RESET}"
exit 1
fi
# Perform disk operations
echo ""
echo -e "${WHITE}Starting disk operations on $PARTITION...${RESET}"
echo ""
sudo fdisk -l
echo ""
echo -e "${WHITE}Formatting $PARTITION with LUKS encryption${RESET}"
echo ""
sudo cryptsetup luksFormat "$PARTITION"
echo ""
echo -e "${BRIGHT_GREEN}Please enter passphrase to open the new LUKS encryption:${RESET}"
echo ""
sudo cryptsetup luksOpen "$PARTITION" encData
echo ""
echo -e "${BRIGHT_GREEN}Creating ext4 filesystem on encrypted partition${RESET}"
echo ""
sudo mkfs.ext4 /dev/mapper/encData
echo ""
echo -e "${WHITE}Labeling filesystem as persistence${RESET}"
sudo e2label /dev/mapper/encData persistence
echo ""
echo -e "${BRIGHT_GREEN}Creating mount point at /mnt/persistence${RESET}"
sudo mkdir -p /mnt/persistence
echo ""
echo -e "${WHITE}Mounting encrypted partition.${RESET}"
sudo mount /dev/mapper/encData /mnt/persistence
echo ""
echo -e "${BRIGHT_GREEN}Creating persistence.conf file.${RESET}"
sudo touch /mnt/persistence/persistence.conf
echo ""
echo -e "${WHITE}Editing persistence.conf${RESET}"
echo "/ union" | sudo tee /mnt/persistence/persistence.conf > /dev/null
echo ""
echo -e "${BRIGHT_GREEN}Returning to home directory...${RESET}"
cd ~
echo ""
echo -e "${WHITE}Unmounting encrypted partition...${RESET}"
echo ""
sudo umount /mnt/persistence
echo ""
echo -e "${WHITE}Closing LUKS partition.${RESET}"
echo ""
sudo cryptsetup luksClose encData
# Completion message
echo -e "${BRIGHT_GREEN}+-----------------------------------------------------+${RESET}"
echo -e "${BRIGHT_GREEN}| THE ENCRYPTED PERSISTENT PARTITION HAS BEEN CREATED |${RESET}"
echo -e "${BRIGHT_GREEN}+-----------------------------------------------------+${RESET}"
# Final prompt to exit the script
echo -e "\n${PINK}Press Enter to exit the script.${RESET}"
echo ""
read -r