Posted in
Linux Server |
No Comment | 3,926 views | 01/04/2013 17:15
If you need to extend your logical volume, do following first:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| distro=$(cat /etc/issue | head -n 2 | tr -d "\n" | tr "[:upper:]" "[:lower:]")
device=$(fdisk -l | grep -w 8e | head -n 1 | cut -c-8)
partcount=$(fdisk -l | grep $device | sed 1d | grep -c $device)
newpartnum=$(($partcount+1))
startsector=$(fdisk -l | grep -w 8e | tail -1 | tr " " "\n" | sed "/^$/d" | head -n 3 | tail -1)
newstartsector=$(($startsector+1))
endsector=$(fdisk -l | grep sectors | head -n 1 | tr " " "\n" | tail -2 | head -n 1)
newendsector=$(($endsector-1))
fdisk $device <<EOF
n
p
$newpartnum
$newstartsector
$newendsector
t
$newpartnum
8e
w
EOF |
distro=$(cat /etc/issue | head -n 2 | tr -d "\n" | tr "[:upper:]" "[:lower:]")
device=$(fdisk -l | grep -w 8e | head -n 1 | cut -c-8)
partcount=$(fdisk -l | grep $device | sed 1d | grep -c $device)
newpartnum=$(($partcount+1))
startsector=$(fdisk -l | grep -w 8e | tail -1 | tr " " "\n" | sed "/^$/d" | head -n 3 | tail -1)
newstartsector=$(($startsector+1))
endsector=$(fdisk -l | grep sectors | head -n 1 | tr " " "\n" | tail -2 | head -n 1)
newendsector=$(($endsector-1))
fdisk $device <<EOF
n
p
$newpartnum
$newstartsector
$newendsector
t
$newpartnum
8e
w
EOF
Then reboot your server!
After that, you should do following to extend LVM:
1
2
3
4
5
6
7
8
9
10
11
12
| device=$(fdisk -l | grep -w 8e | head -n 1 | cut -c-8)
partnumber=$(fdisk -l | grep $device | sed 1d | grep -c $device)
pvcreate $device$partnumber
volgroupname=$(vgdisplay | grep -w "VG Name" | cut -b10- | tr -d " ")
vgextend $volgroupname $device$partnumber
volgroupchars=$(echo $volgroupname | wc --chars)
totalchars=$(($volgroupchars+13))
lvmname=$(df -h | grep -w $volgroupname | head -n 1 | cut -b$totalchars-)
set $lvmname
lvmname=$1
lvextend -l +100%FREE /dev/$volgroupname/$lvmname
resize2fs /dev/$volgroupname/$lvmname |
device=$(fdisk -l | grep -w 8e | head -n 1 | cut -c-8)
partnumber=$(fdisk -l | grep $device | sed 1d | grep -c $device)
pvcreate $device$partnumber
volgroupname=$(vgdisplay | grep -w "VG Name" | cut -b10- | tr -d " ")
vgextend $volgroupname $device$partnumber
volgroupchars=$(echo $volgroupname | wc --chars)
totalchars=$(($volgroupchars+13))
lvmname=$(df -h | grep -w $volgroupname | head -n 1 | cut -b$totalchars-)
set $lvmname
lvmname=$1
lvextend -l +100%FREE /dev/$volgroupname/$lvmname
resize2fs /dev/$volgroupname/$lvmname
You can control final size with this command:
You should see new disk size after this process.