LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   Expand root and swap partitions? (https://www.linuxquestions.org/questions/centos-111/expand-root-and-swap-partitions-4175581378/)

kenw232 06-03-2016 01:49 PM

Expand root and swap partitions?
 
I just installed CentOS 7.2 minimal. I now need to expand my swap (1.6GB now) and root (13.9GB) partitions.

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 16G 0 disk
+-sda1 8:1 0 500M 0 part /boot
+-sda2 8:2 0 15.5G 0 part
+-centos-root 253:0 0 13.9G 0 lvm /
+-centos-swap 253:1 0 1.6G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom

is this a straight forward process? How do I go about doing this? Its a Vmware virtual machine. So I start by expanding the VM disk size. But then what? I've only ever done this for slackware.

michaelk 06-03-2016 03:02 PM

You can expand the existing disk or create a new VDI. I would probably create a new virtual disk.

You could use system storage manager or use the traditional LVM tools i.e. pvcreate, vgextend, lvextend and finally the filesystem i.e. resize2fs or xfs_growfs. For swap you need to turn it off, add space, mkswap then turn it back on.

http://xmodulo.com/manage-lvm-volume...e-manager.html

kenw232 06-04-2016 03:11 PM

I can't resize an existing swap space partition? I didn't think I had to delete and add new.

michaelk 06-04-2016 03:59 PM

Swap is not a filesystem in the traditional sense and therefore no tools to resize. Actually you do not really have to delete i.e. you can add separate swap partitions and/or swap files and the operating will add the space together.

Tasslehoff 06-29-2016 07:34 AM

You can choose to expand the existing vmdk or to add a new one.
Adding a new vmdk is the most easy path:
  • detect the new storage device (LINK)
  • create a new partition on the new device with fdisk
  • create a new physical volume (PV) on the new partition (pvcreate /dev/sdXN)
  • add the new PV to the volume group ("vgextend /dev/sdXN vgname" where vgname in you case is centos)
  • extend the logical volumes with lvextend (lvextend -L SIZE /dev/centos/lvname)
  • resize filesystem (resize2fs /dev/centos/lvname for ext filesystem, xfs_growfs /dev/centos/lvname for xfs for example)

You can also extend the actual vmdk, detect the new device size (the easiest way is to reboot) and create a new partition, then follow the previous commands using a new partition on the same device (for example /dev/sda3 instead of /dev/sda2).
Or you can extend the actual vmdk and extend the existing pv /dev/sda2, but in this case you must
  • delete the /dev/sda2 partition and create it again starting from the very same starting block (that's very important!)
  • extend the pv with pvresize command (pvresize /dev/sda2)
  • extend the LV

For swap logical volume you must deactivate the actual swap (swapoff /dev/centos/swap), extend the lv (lvextend), create the new swap space (mkswap /dev/centos/swap) and enable the swap (swapon /dev/centos/swap)

I hope this will helpful :)


All times are GMT -5. The time now is 01:46 AM.