Skip to content

Instantly share code, notes, and snippets.

@pda
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pda/e6070ef2e7de4a16c113 to your computer and use it in GitHub Desktop.
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
#!/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
@porty
Copy link

porty commented Oct 22, 2014

Could mke2fs -q -i 8192 /dev/ephemeral/ephemeral be mke2fs -q -i 8192 $DEVICE_LV ?

@pda
Copy link
Author

pda commented Oct 22, 2014

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