Skip to content

Instantly share code, notes, and snippets.

@seanorama
Created November 19, 2018 17:46
Show Gist options
  • Save seanorama/6f1a352aa6b5766b2d4c288568fc24e8 to your computer and use it in GitHub Desktop.
Save seanorama/6f1a352aa6b5766b2d4c288568fc24e8 to your computer and use it in GitHub Desktop.
## No longer using this but keeping for posterity
## Functions so we don't repeat ourselves (DRY)
function lv_name(){
[[ "$1" ]] || { echo "Error: Missing query" >&2; return 1; }
export lv_name="lv_$(echo ${path} | sed -r -e 's,^/,,' -e 's,/$,,' -e 's,/,_,g')"
}
function my_mount_lvm(){
[[ "$1" ]] || { echo "Error: Missing path" >&2; return 1; }
[[ "$2" ]] || { echo "Error: Missing size" >&2; return 1; }
path="${1}"
size="${2}"
lv_name "${path}"
sudo lvcreate -n ${lv_name} -L ${size} ${vg}
sudo mkdir -p ${path}
## chmod and chattr protect us from filling the parent partition if the children are unmounted
sudo chmod 0000 "${path}"
sudo chattr +i "${path}"
sudo mkfs -t xfs /dev/${vg}/${lv_name}
echo "/dev/${vg}/${lv_name} ${path} xfs defaults,noatime 0 0" | sudo tee -a /etc/fstab >/dev/null
sudo mount "${path}"
}
my_mount_lvm /var/log 45%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment