Created
January 15, 2019 21:18
-
-
Save jugglinmike/7b62df79e6e94b57594da6b75cf34747 to your computer and use it in GitHub Desktop.
Experimenting with mounting EBS volumes in Amazon EC2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Mount a volume to the system's `/var` directory. This limits the impact of | |
# unbounded disk usage for log and database files typically stored there. | |
set -x | |
# Redirect the output of all commands in this script to a file in `/root` | |
exec 1<&- | |
exec 2<&- | |
exec 1<>/root/var-mount-log.txt | |
exec 2>&1 | |
mkfs --type ext4 /dev/xvdg | |
# Stop services which may have open files in `/var` | |
systemctl isolate rescue.target | |
systemctl stop systemd-journald* | |
# Move the current contents to a temporary directory | |
mkdir /mnt/var | |
mv /var/* /mnt/var | |
mount /dev/xvdg /var | |
mv /mnt/var/* /var | |
# Ensure the partition is mounted at startup | |
echo /dev/xvdg /var ext4 defaults,nofail 0 2 >> /etc/fstab | |
# Remove the temporary directory | |
rmdir /mnt/var | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment