diff --git a/README.rst b/README.rst index de84c43..ebb1440 100644 --- a/README.rst +++ b/README.rst @@ -21,6 +21,18 @@ This software is currently written in PHP. The PHP commandline program is requir Here's how. +Easy-mode +^^^^^^^^^ + +:: + + # ./lvm2defrag.sh YOURVOLUMEGROUPNAME + # ./commands.sh + +Execute the following commands, Your favorite editor should open, move around your partitions between disks into the order you wish they to be in. Save and exit. +You should now have commands.sh which contain all commands you need to process. +If something goes wrong, you should probably prefer the manual methode. + Step 1. Dump existing layout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/lvm2defrag.sh b/lvm2defrag.sh new file mode 100755 index 0000000..3f09a33 --- /dev/null +++ b/lvm2defrag.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +if [ $# -ne 1 ] +then + echo "Usage: $0 vgname" + exit +fi + +if [ $UID -ne 0 ] +then + echo "This program need to be run as root." + exit +fi + +type php &>/dev/null +if [ $? -ne 0 ] +then + echo "This script need php." + exit +fi + +function fail () +{ + echo "An error occurs, fix it and try again." + exit +} +vgname=$1 +vgcfgbackup $vgname || fail +cp -f /etc/lvm/backup/$vgname data.txt || fail +php -q dump.php > dump.txt || fail +cp -f dump.txt rearrange.txt || fail +editor rearrange.txt +php -q rearrange.php > commands.sh || fail +warnline=$(grep -cvE '^(echo|pvmove|#)' commands.sh) +if [ $warnline -ne 0 ] ; then + echo "Warning or error present in commands.sh, fix them." + grep -cvE '^(echo|pvmove|#)' commands.sh + exit +fi +chmod +x commands.sh + +echo "All good, now you just have to execute ./commands.sh" + +