Skip to content

Instantly share code, notes, and snippets.

@shichao-an
Created August 26, 2014 05:21
Show Gist options
  • Save shichao-an/2b55949f30fdefb25e36 to your computer and use it in GitHub Desktop.
Save shichao-an/2b55949f30fdefb25e36 to your computer and use it in GitHub Desktop.
Create LVM on EBS
#!/bin/bash
ebs_disk="/dev/xvdf"
ebs_partition="/dev/xvdf1"
vg_name="vg"
pv_name="pv1"
mount_point="/mnt"
# Create a primary partition on $ebs_disk using all space
echo -e "n\np\n1\n\n\nw" | fdisk "$ebs_disk"
# Create Volume Group
vgcreate "$vg_name" "$ebs_partition"
# Create Logical Volume using all space
lvcreate -l 100%FREE -n "$pv_name" "$vg_name"
# Format the LV
mkfs.ext4 "/dev/$vg_name/$pv_name"
# Get UUID of the formatted LV
blkid | grep "/dev/mapper/$vg_name-$pv_name"
uuid=$(blkid | grep '/dev/mapper' | awk '{ print $2 }' | sed \
's/.*UUID="\(.*\)"/\1/g')
# Update /etc/fstab
s="UUID=$uuid $mount_point ext4 defaults,nofail,nobootwait 0 2"
echo "$s" >> /etc/fstab
# Mount
mount -a
mount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment