Skip to content

Commit 79091ef

Browse files
committed
SERVER-41393 Identify devices by their UUID in /etc/fstab.
This ensures they are automatically mounted following a machine reboot.
1 parent 5e527a2 commit 79091ef

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

buildscripts/mount_drives.sh

+12-3
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,24 @@ function mount_drive {
147147
/sbin/mdadm --detail --scan > /etc/mdadm.conf
148148
/sbin/blockdev --setra 32 $device_name
149149
else
150-
device_name=$devices
150+
device_name="/dev/$device_names"
151151
fi
152152

153153
# Mount the $root_dir drive(s)
154154
/sbin/mkfs.$fs_type $mount_options -f $device_name
155-
echo "$device_name /$root_dir auto noatime 0 0" | tee -a /etc/fstab
155+
# We add an entry for the device to /etc/fstab so it is automatically mounted following a
156+
# machine reboot. The device is not guaranteed to be assigned the same name across restarts so
157+
# we use its UUID in order to identify it.
158+
#
159+
# We also specify type=$fs_type in the /etc/fstab entry because specifying type=auto on
160+
# Amazon Linux AMI 2018.03 leads to the drive not being mounted automatically following a
161+
# machine reboot.
162+
device_uuid=$(blkid -o value -s UUID "$device_name")
163+
echo "Adding entry to /etc/fstab for device '$device_name' with UUID '$device_uuid'"
164+
echo "UUID=$device_uuid /$root_dir $fs_type noatime 0 0" | tee -a /etc/fstab
156165
mkdir /$root_dir || true
157166
chmod 777 /$root_dir
158-
mount -t $fs_type $device_name /$root_dir
167+
mount -t $fs_type "UUID=$device_uuid" /$root_dir
159168
for sub_dir in $sub_dirs
160169
do
161170
mkdir -p /$root_dir/$sub_dir

0 commit comments

Comments
 (0)