Skip to content

Instantly share code, notes, and snippets.

@mikemccracken
Last active August 29, 2015 14:21
Show Gist options
  • Save mikemccracken/a28381db3820a2000f23 to your computer and use it in GitHub Desktop.
Save mikemccracken/a28381db3820a2000f23 to your computer and use it in GitHub Desktop.
cleaning up loop mounted volume groups
create_vg() {
# loopback file for PV:
pvfile=$LXD_DIR/lvm-pv.img
fallocate -l 1GB $pvfile
pvloopdev=$(losetup -f)
losetup $pvloopdev $pvfile
#vgcreate will create a PV for us
vgcreate lxd_test_vg $pvloopdev
trap cleanup_vg EXIT
}
cleanup_vg() {
# -f removes any LVs in the VG
vgremove -f lxd_test_vg
losetup -d $pvloopdev
rm $pvfile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment