diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-10-14 02:27:27 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-10-14 02:27:27 -0300 |
commit | 5077ee7d9a9f80ac400ce509124352300e7f8e43 (patch) | |
tree | 9b3cb27c6884e73645aa9b1225146df34f86f90a | |
parent | fb748d619cb32a75fed2040a31258074f87f4934 (diff) | |
download | hydra-5077ee7d9a9f80ac400ce509124352300e7f8e43.tar.gz hydra-5077ee7d9a9f80ac400ce509124352300e7f8e43.tar.bz2 |
Adds LVM support into mount-media
-rw-r--r-- | doc/todo.rst | 1 | ||||
-rwxr-xr-x | share/hydractl/mount-media | 37 |
2 files changed, 28 insertions, 10 deletions
diff --git a/doc/todo.rst b/doc/todo.rst index d263db9..62256b4 100644 --- a/doc/todo.rst +++ b/doc/todo.rst @@ -1,7 +1,6 @@ TODO ==== -* mount-media: lvm support. * import-keys: do not use ssh if host is localhost. * import-certs: concat.pem; cert.pem and cert.crt symlinks; restart services. * compile: automatic definitions for per-node backup::users. diff --git a/share/hydractl/mount-media b/share/hydractl/mount-media index d6adf70..6916439 100755 --- a/share/hydractl/mount-media +++ b/share/hydractl/mount-media @@ -7,6 +7,7 @@ MEDIA="$1" VOLUME="$2" BASENAME="`basename $0`" +MAPPING="$MEDIA" MOUNTPOINT="/media/$MEDIA" # Check media config @@ -21,8 +22,16 @@ if [ -z "$VOLUME" ]; then VOLUME="sdb1" fi -# Disk config +# Disk and device config DISK="`echo ${VOLUME} | sed -e s/[0-9]\$//g`" +DEVICE="/dev/$DISK" + +# Check if LVM +if $sudo lvdisplay /dev/$MEDIA/root &> /dev/null; then + LVM="yes" + DEVICE="/dev/$MEDIA/root" + MAPPING="$MAPPING-root" +fi # Set sudo config if [ "`whoami`" != 'root' ]; then @@ -30,22 +39,32 @@ if [ "`whoami`" != 'root' ]; then fi if [ "$BASENAME" == "mount-media" ]; then - echo "Checking drive health status..." - $sudo smartctl -H /dev/$DISK + if [ -e "$DEVICE" ]; then + echo "Checking drive health status..." + $sudo smartctl -H /dev/$DISK - echo "Disabling STANDBY on drive..." - $sudo sdparm --clear STANDBY -6 /dev/$DISK + echo "Disabling STANDBY on drive..." + $sudo sdparm --clear STANDBY -6 /dev/$DISK + fi + + if [ "$LVM" == "yes" ]; then + $sudo vgchange -a y $VOLUME + fi echo "Initializing crypto layer..." - $sudo cryptsetup luksOpen /dev/$VOLUME $MEDIA && \ + $sudo cryptsetup luksOpen $DEVICE $MAPPING && \ echo "Checking filesystem..." - $sudo fsck -v -y /dev/mapper/$MEDIA && \ + $sudo fsck -v -y /dev/mapper/$MAPPING && \ echo "Mounting volume at $MOUNTPOINT..." $sudo mkdir -p $MOUNTPOINT - $sudo mount /dev/mapper/$MEDIA $MOUNTPOINT + $sudo mount /dev/mapper/$MAPPING $MOUNTPOINT elif [ "$BASENAME" == "umount-media" ]; then $sudo umount $MOUNTPOINT && \ - $sudo cryptsetup luksClose $MEDIA + $sudo cryptsetup luksClose $MAPPING + + if [ "$LVM" == "yes" ]; then + $sudo vgchange -a n $VOLUME + fi fi |