Resize ext4 partition without losing data in virtual server
Solution 1
Yes, looks like you can use lvresize, assuming you have space in the volume group.
See if you have some free space:-
sudo vgs -v vg_d0011prf01
If you do, then you can resize the volume using. the following will increase the size by 2Gig.
sudo lvextend -L+2G /dev/mapper/vg_d0011prf01-lv_home
Then resize the volume using resize2fs like:-
sudo resize2fs /dev/mapper/vg_d0011prf01-lv_home
Solution 2
There are several tools for re-sizing partitions, parted
(or gparted
for a graphical interface) is probably the best bet. There are two steps here. First you have to grow the partition into the new space, then you have to grow the file system to use the whole partition.
I do recommend switching to using LVM. The flexibility to manage this sort of change down the road is well worth the effort to set it up. You could even add a new partition in the new blank space, configure LVM inside it, start a volume group and a file system in it, copy your data over to the new space, then hose the current partition, add it to the volume group, and expand onto it.
Whatever you do, don't do anything unless you have your system backed up!
Related videos on Youtube
Andrey Adamovich
A software craftsman with many years of experience in different lifecycle phases of software creation. He is passionate about defining good development practices, documenting and presenting architecture, reuse of code and design patterns, profiling and analysis of application performance as well as extreme automation of development and operations activities. At the moment, Andrey is working as a free-lance DevOps consultant offering his expertise in implementing DevOps initiatives, selecting automation tooling, switching to infrastructure-as-code and immutable infrastructure and constructing software delivery pipelines. Another Andrey's passion is teaching software automation practices and tooling. His DevOps MasterClass (eXtreme Automation) course has been delivered more than 20 times in various locations in Europe: Austria, Sweden, Denmark, UK, Romania, Estonia, Latvia. Andrey is also a co-founder of DevChampions training center. Andrey is a frequent speaker at international conferences and local communities. He is one of the leaders of LatCraft - Latvian Software Craftsmanship Community as well as co-founder and organizer of DevTernity conference.
Updated on September 18, 2022Comments
-
Andrey Adamovich over 1 year
We have a virtual Linux server (Fedora Core 2.6.35.6-45.fc14.x86_64) running on VMWare vSphere. Initially it had 3 SCSCI drives 32Gb each. Now we have extended a disk that was mounted under "/home" to 256GB. But Linux server, obviously, does not see that change after restart. Is there a safe way to extend that ext4 partition from 32GB to 256GB withou losing any data?
I've made a search on Google before asking this question and many advice to use GParted. But it seems not the option for me now as I only have shell access to that server at the moment.
EDIT: This is an output from df:
[root@d0001-prf01 dmr]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_d0011prf01-lv_root ext4 31705024 3385376 27997620 11% / tmpfs tmpfs 4098300 88 4098212 1% /dev/shm /dev/sda1 ext4 495844 31317 438927 7% /boot /dev/mapper/vg_d0011prf01-lv_home ext4 23674012 11840672 10630756 53% /home
I can provide more partition information if needed.
EDIT: I can see that LVM is set up on that Linux server:
lvm> lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_home vg_d0011prf01 -wi-ao 22.94g lv_root vg_d0011prf01 -wi-ao 30.72g lv_swap vg_d0011prf01 -wi-ao 9.81g
Does it mean I can use lvresize command?
-
Chopper3 almost 13 yearsVMWare is a company by the way, not a product, any chance you might let us know which of them you're talking about?
-
Andrey Adamovich almost 13 years@Chopper3, it's vSphere. I'll update the qeustion.
-
Chopper3 almost 13 yearsAgain, that's a product range not a product...
-
Andrey Adamovich almost 13 years@Chopper3, let me know what information you need more about it. I'm not VMWare product expert and to me it seems that problem is more Linux related, but not underlying virtualization software. In vSphere client I can see that SCSCI disk that is used for /home partition has 256GB and I see that linux uses only 24GB of that.
-
-
Andrey Adamovich almost 13 yearshow do I set up LVM? any good pointers are really appreciated.
-
Andrey Adamovich almost 13 yearshow do I check if it is already setup?
-
Andrey Adamovich almost 13 yearsI updated the question with details from LVM.
-
Andrey Adamovich almost 13 yearsthanks a lot for your answer, but what if vgs command shows that I have 0 free space?
-
Decado almost 13 yearsOkay, then you need to re-size the partition to the full 256G, using Caleb's parted answer, then run pvresize <partion name>. Then vgs should report some free space available to resize the volumes.
-
Decado almost 13 yearsrelevent parted document page is here
-
Andrey Adamovich almost 13 yearshmm, parted returns Error: The location 200GB is outside of the device /dev/sda.
-
Andrey Adamovich almost 13 yearsour Linux adiministrator got back from vaction and managed to create a new partition in separate location. Thanks for you answers.