-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot-from-uuid-fix
52 lines (42 loc) · 1.49 KB
/
boot-from-uuid-fix
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
#!/bin/bash
# Check if /boot is already using UUID
existing_boot_uuid=$(grep '/boot' /etc/fstab | grep '^UUID')
if [ -n "$existing_boot_uuid" ]; then
echo "The /boot partition is already using a UUID:"
echo "$existing_boot_uuid"
echo "Everything is fine, no changes are needed."
exit 0
fi
# Function to select a /boot device
choose_boot_partition() {
echo "Available devices mounted as /boot (excluding UUIDs):"
boot_partitions=$(grep '/boot' /etc/fstab | grep -v '^UUID' | awk '{print $1}')
if [ -z "$boot_partitions" ]; then
echo "No devices mounted as /boot that require modification were found."
exit 1
fi
echo "$boot_partitions" | nl -w2 -s'. '
echo
read -p "Select the number of the device you want to modify: " choice
DEVICE=$(echo "$boot_partitions" | sed -n "${choice}p")
if [ -z "$DEVICE" ]; then
echo "Invalid selection. Exiting."
exit 1
fi
}
# Select the device for /boot
choose_boot_partition
# Get the UUID for the selected device
UUID=$(blkid -s UUID -o value $DEVICE)
# Check if the UUID was found
if [ -z "$UUID" ]; then
echo "Error: UUID for $DEVICE not found."
exit 1
fi
# Create a backup of fstab with a timestamp
timestamp=$(date +"%Y%m%d_%H%M%S")
cp /etc/fstab /etc/fstab.bak_$timestamp
echo "A backup of /etc/fstab has been created as /etc/fstab.bak_$timestamp"
# Replace the device in /etc/fstab with the UUID
sed -i "s|^$DEVICE|UUID=$UUID|g" /etc/fstab
echo "The entry in /etc/fstab for $DEVICE has been successfully changed to use UUID=$UUID"