Alexander / Aebian

Who am I?

Musician, Programmer, Linux Geek and what not.  more...


The Categories



Stuff

Arma CodeList
GitHub Projects
Media (Gallery)
Privacy Policy
My Hardware
My Wishlist


April 25th at 5:51pm
Report a website issue
For best viewing experience use a 4k screen.

nethavn Logo

❬ Back to Blog


Extend swap size on Linux / Extend VMware Hard Disk


This post will cover the plain details on how to extend a swap partition aswell how to extend a VMware hard disk. No stories, just facts!

The steps in the first chapter are done on a RedHat 6.6. But since LVM is available on all major distros that shouldn't be a problem.
The second chapter is done on debian but also works on any other linux distro.

How to extend a swap size

First you wanna make sure your disk drive has enough space available for resizing, otherwise you may lose data.
So open up your terminal and type df -h the output will be something like this:


Make sure your mount point on / has enough space free.
Otherwise free some space up or attach another disk and extend the mount point.
The next thing you want to do is to display the volume group for the device.

In most cases /dev/sda/ with sda1 and sda2 is the default "system drive". So just enter this command: vgdisplay.
After that your output should look like this:


The VG Name section is our thing we need.
First we need to resize our normal disk and remove some Gigabytes we later on need for adding them to the swap partition.
Enter in the terminal: lvresize /dev/vg_redhat66tp/lv_root -L -2G You get something like:


Accept that and you now have 2 extra Gigabytes free for usage with the swap partition. So lets extend it!
lvresize /dev/vg_redhat66tp/lv_swap -L +2G The output will likely be:

Thats it, you're done!

How to extend a VMware hard disk

First run the command dmesg | grep -i 'Disk' to get the disk unit number. The output will look like this:

In my case I want to extend /dev/sdb since that drive just went full and some programs need to access it. So lets took a closer look at the output above:
That disk refers to adapter 2:0:1:0 which means it is unit number 1!

So the next thing I need to do is to add some storage on the VMware side. I selected the unit 1 and added 10GB extra (from 30 GB to 40 GB).
If resize2fs will not extend to the new size, we need to restart the server. Simply use the command shutdown -r now to do this. After that everything should be working.

Then run the command resize2fs /dev/sdb. The output will looks like this:

If done you can now restart the apllication that used the drive or do a full system restart if needed.

Regards,

Alex