Last active
August 29, 2015 14:07
-
-
Save pda/e6070ef2e7de4a16c113 to your computer and use it in GitHub Desktop.
For EC2 instances with two instance volumes, use LVM to combine them into a single /mnt
This file contains 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 | |
set -euo pipefail | |
IFS=$'\n\t' | |
set -x | |
DEVICE_B="/dev/xvdb" | |
DEVICE_C="/dev/xvdc" | |
VG_NAME="ephemeral" | |
LV_NAME="ephemeral" | |
DEVICE_LV="/dev/$VG_NAME/$LV_NAME" | |
install_lvm() { | |
apt-get -qq update | |
apt-get -qq --yes install lvm2 >/dev/null | |
} | |
unmount_mnt() { | |
umount /mnt | |
} | |
create_logical_volume() { | |
pvcreate $DEVICE_B $DEVICE_C | |
vgcreate ephemeral $DEVICE_B $DEVICE_C | |
lvcreate --extents "100%VG" --name $LV_NAME $VG_NAME | |
} | |
format_logical_volume() { | |
mke2fs -q -t ext4 -i 8192 "$DEVICE_LV" | |
} | |
mount_mnt() { | |
sed --in-place=lvmbackup -e "s#${DEVICE_B}#${DEVICE_LV}#" /etc/fstab | |
mount /mnt | |
} | |
main() { | |
install_lvm | |
unmount_mnt | |
create_logical_volume | |
format_logical_volume | |
mount_mnt | |
} | |
if [ -b "$DEVICE_B" -a -b $DEVICE_C ]; then | |
main | |
else | |
echo >&2 "Device $DEVICE_B or $DEVICE_C not present, skipping LVM setup" | |
fi |
Fixed, and a few other fixes including specifying ext4 instead of default ext2.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could
mke2fs -q -i 8192 /dev/ephemeral/ephemeral
bemke2fs -q -i 8192 $DEVICE_LV
?