LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 06-03-2016, 01:49 PM   #1
kenw232
Member
 
Registered: May 2006
Posts: 125

Rep: Reputation: 12
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.
 
Old 06-03-2016, 03:02 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,749

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
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
 
Old 06-04-2016, 03:11 PM   #3
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
I can't resize an existing swap space partition? I didn't think I had to delete and add new.

Last edited by kenw232; 06-04-2016 at 03:17 PM.
 
Old 06-04-2016, 03:59 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,749

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
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.
 
Old 06-29-2016, 07:34 AM   #5
Tasslehoff
LQ Newbie
 
Registered: Jun 2016
Posts: 4

Rep: Reputation: Disabled
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to expand the disk of ubuntu mounted at root ansonc Linux - Desktop 2 07-22-2015 11:24 AM
[SOLVED] LVM expand swap logical volume Z038 Linux - General 6 06-15-2013 03:00 PM
how to safely expand swap Winanjaya Linux - General 1 02-18-2010 02:00 AM
how to expand linux partition & how much swap do i I need? AGazzaz Linux - Software 5 05-03-2006 05:20 PM
Creating partitions at install vs root+swap Thaidog Linux - General 3 07-02-2004 07:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 02:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration