forked from inclavare-containers/deterministic-builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
turn_off_vdso.sh
executable file
·86 lines (69 loc) · 2.08 KB
/
turn_off_vdso.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
#!/bin/bash
if [[ `whoami` != "root" ]]; then
echo "Should run in root"
exit 1
fi
if ldd `which date` | grep -q "vdso"; then
echo "vDSO is on"
else
echo "vDSO is already off"
exit 0
fi
echo -n "It will automatically modify Grub config file, do you want to proceed? [y/N]:"
read ans
if [[ ! (($ans == "y" || $ans == "Y")) ]]; then
echo "You should modify the file manually later to enable vDSO"
exit 0
fi
GRUB_CONFIG_FILE_PATH="/etc/default/grub"
GRUB_CONFIG_BACKUP_FILE_NAME="grub.backup"
if [[ ! -e $GRUB_CONFIG_FILE_PATH ]]; then
echo "GRUB config file $GRUB_CONFIG_FILE_PATH not exists."
exit 1
fi
CONFIG_LINE=`cat $GRUB_CONFIG_FILE_PATH | grep "GRUB_CMDLINE_LINUX_DEFAULT"`
if [[ -z "$CONFIG_LINE" ]]; then
echo "Grub config GRUB_CMDLINE_LINUX_DEFAULT is not found in file $GRUB_CONFIG_FILE_PATH."
exit 1
fi
if echo "$CONFIG_LINE" | grep -q "vdso"; then
echo "vDSO has been already set in $CONFIG_LINE in file $GRUB_CONFIG_FILE_PATH"
exit 1
fi
NEW_CONFIG_LINE=`echo "$CONFIG_LINE" | sed "s/GRUB_CMDLINE_LINUX_DEFAULT=\"/&vdso=0 /"`
echo "Will modify config in $GRUB_CONFIG_FILE_PATH to this:"
echo $NEW_CONFIG_LINE
echo -n ", do you want to proceed? [y/N]:"
read ans
if [[ ! (($ans == "y" || $ans == "Y")) ]]; then
echo "You should modify the file manually later to enable vDSO"
exit 0
fi
counter=0
while true
do
if [[ $counter -ne 0 ]]; then
target="$GRUB_CONFIG_BACKUP_FILE_NAME.$counter"
else
target=$GRUB_CONFIG_BACKUP_FILE_NAME
fi
if [[ ! -e $target ]]; then
echo "Copying $GRUB_CONFIG_FILE_PATH to $target"
cp $GRUB_CONFIG_FILE_PATH $target
break
fi
((counter++))
done
sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=\"/&vdso=0 /" $GRUB_CONFIG_FILE_PATH
echo "Running grub-mkconfig"
grub-mkconfig -o /boot/grub/grub.cfg
echo "Finished grub-mkconfig"
echo -n "Need reboot to disable vDSO, do you want to reboot now? [y/N]:"
read ans
if [[ $ans == "y" || $ans == "Y" ]]; then
echo "Reboot now"
# reboot
else
echo "You should reboot manually later to enable vDSO"
exit 0
fi