-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize-disk-ubuntu.sh
72 lines (55 loc) · 1.51 KB
/
resize-disk-ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# on Proxmox node:
# resize disk of vm (VM - Hardware - Hard Disk - Resize Disk)
# note: guest vm may be started (resizing while running is possible)
# on guest vm:
echo "- Check lvm config before"
sudo pvs
echo __
sudo vgs
echo __
sudo lvs
echo ___
echo "- Check disk space before"
df -h | grep -E 'Size|vg'
echo ___
device=$(sudo pvs -o pv_name --noheadings | sed -e "s/^ *\/dev\///" -e "s/[0-9]* *$//")
echo "device=$device"
partition=$(sudo pvs -o pv_name --noheadings | sed -e "s/^ *\/dev\///" -e "s/^[a-z]*//")
echo "partition=$partition"
fsmountsource=$(findmnt / -o SOURCE --noheadings)
echo "fsmountsource=$fsmountsource"
echo ___
echo "- Check if change of disk size is detected"
dmesg | grep $device
echo ___
echo "- Print partition table"
sudo fdisk -l /dev/$device | grep ^/dev
echo ___
read -p "Press [Enter] to resize partition"
if sudo gdisk -l /dev/$device | grep "GPT: present";
then
echo "- Move GPT second header to end of disk"
sudo sgdisk /dev/$device -e
fi
echo "- Resize partition"
sudo parted /dev/$device resizepart $partition 100%
echo ___
echo "- Check the new partition table"
sudo fdisk -l /dev/$device | grep ^/dev
echo ___
echo "- Resize lvm physical volume"
sudo pvresize /dev/$device$partition
echo ___
echo "- Resize the lvm logical volume and the filesystem"
sudo lvresize --extents +100%FREE --resizefs $fsmountsource
echo ___
echo "- Check lvm config afterwards"
sudo pvs
echo __
sudo vgs
echo __
sudo lvs
echo ___
echo "- Check disk space afterwards"
df -h | grep -E 'Size|vg'