I would to extend my logical volume via script.
Before i had vm with 10 GB hdd, i incerease hdd 5 GB more, then its toatal 15 GB. What manually i run command to extend hard disk as follows:
sudo parted /dev/sda
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 8388608 blocks) or continue with the current setting?
Fix/Ignore? fix
Partition number? 3
End? [17.2GB]? 100%FREE
Information: You may need to update /etc/fstab.
sudo pvresize /dev/sda3
sudo lvresize --extents +100%FREE --resizefs /dev/mapper/ubuntu--vg-ubuntu--lv
test-vm:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 447M 0 447M 0% /dev
tmpfs 99M 1.1M 98M 2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 8.8G 4.6G 3.8G 55% /
tmpfs 491M 0 491M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 491M 0 491M 0% /sys/fs/cgroup
/dev/sda2 976M 106M 804M 12% /boot
/dev/loop1 72M 72M 0 100% /snap/lxd/16099
/dev/loop2 68M 68M 0 100% /snap/lxd/21835
/dev/loop3 44M 44M 0 100% /snap/snapd/14295
/dev/loop4 56M 56M 0 100% /snap/core18/2253
/dev/loop5 62M 62M 0 100% /snap/core20/1270
tmpfs 99M 0 99M 0% /run/user/1000
/dev/loop7 56M 56M 0 100% /snap/core18/2284
/dev/loop8 44M 44M 0 100% /snap/snapd/14549
Add extra 5 GB to /dev/mapper/ubuntu--vg-ubuntu--lv
The above things i would like to run in a script which is as follows:
#!/bin/bash
sudo parted -s /dev/sda 'resizepart 3 100%'
sudo pvresize /dev/sda3
sudo lvresize --extents +100%FREE --resizefs /dev/mapper/ubuntu--vg-ubuntu--lv
while running above script called hdd.sh i am getting below output:
test-vm:~ ./hdd.sh
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 10485760 blocks) or continue with the current setting?
Error: Unable to satisfy all constraints on the partition.
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Size of logical volume ubuntu-vg/ubuntu-lv unchanged from <9.00 GiB (2303 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.45.5 (07-Jan-2020)
The filesystem is already 2358272 (4k) blocks long. Nothing to do!
So the very first parted command unable to execute, because i can't provide input 'fix'in the script, tried this sudo parted -s /dev/sda resizepart 3 Fix '100%'
My goal to extend logical volume via script. Any input highly appreciated!
Thanks!