在我的服务器上,我不得不不时地扩展lvm卷以腾出更多空间。为此,我使用命令lvextend
和resize2fs
。我想要一个命令,该命令将向我显示LVM卷的列表以供选择并要求增加大小。
我最终编写并用于在线调整大小的脚本是:
#!/bin/bash
# 2020-04-11 Initial Version
function error()
{
echo "*** $*"
exit 1
}
if [ "$1" == "" ] ; then
echo "Please select the partition from the list"
i=1
for j in /dev/mapper/kalypso*
do
echo "$i.$j"
file[i]=$j
i=$(( i + 1 ))
done
echo "Enter number"
read input
partition=${file[$input]}
echo "You selected partition $partition"
df -h $partition
echo "Enter size to add, to $partition e.g. 50G:"
read size
echo "You choose to increase file $partition by $size"
sudo lvextend -L +$size $partition || error "lvextend $partition failed"
sudo resize2fs $partition || error "resize2fs $partition failed"
echo "lvextend/resize2fs completed"
df -h $partition | tail -n 1
fi