-
-
Save tjuberg/a0fd8d783307d63432b45a0ffa066239 to your computer and use it in GitHub Desktop.
Resize LVM disk and partitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Program: Resize LVM disk and partition <resize_disk.sh> | |
| # | |
| # Author: Mikhail Grigorev <sleuthhound at gmail dot com> | |
| # | |
| # Current Version: 1.0.1 | |
| # | |
| # License: | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| # | |
| DISK=sdb | |
| PART=1 | |
| PV=${DISK}${PART} | |
| VG=vmstorage | |
| LV=vmstorage | |
| MPOINT=/var/lib/vmstorage | |
| echo "== BEFORE ==================================================================" | |
| if [ -d "${MPOINT}" ]; then | |
| df -h ${MPOINT} | |
| echo | |
| else | |
| echo "ERROR: Mount point '${MPOINT}' not found." | |
| exit 1 | |
| fi | |
| if [ -b "/dev/${DISK}" ]; then | |
| echo 1 > /sys/block/${DISK}/device/rescan | |
| lsblk /dev/${DISK} | |
| echo | |
| else | |
| echo "ERROR: Disk '${DISK}' not found." | |
| exit 1 | |
| fi | |
| echo "== RESIZE ==================================================================" | |
| if [ -b "/dev/${DISK}${PART}" ]; then | |
| echo "Resize partition '${PART}' on disk '${DISK}'..." | |
| growpart /dev/${DISK} ${PART} | |
| echo "Resize physical volume '${PV}'..." | |
| pvresize /dev/${PV} | |
| else | |
| echo "Resize physical volume '${DISK}'..." | |
| pvresize /dev/${DISK} | |
| fi | |
| if [ -b "/dev/${VG}/${LV}" ]; then | |
| echo "Resize logical volume '/dev/${VG}/${LV}'..." | |
| lvextend -r -l +100%FREE /dev/${VG}/${LV} | |
| else | |
| echo "ERROR: Logical volume '/dev/${VG}/${LV}' not found." | |
| exit 1 | |
| fi | |
| echo "== AFTER ===================================================================" | |
| df -h ${MPOINT} | |
| echo | |
| lsblk /dev/${DISK} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment