CentOS Partition Resizing

General support questions
Post Reply
allan777
Posts: 2
Joined: 2023/12/07 12:53:29

CentOS Partition Resizing

Post by allan777 » 2023/12/07 14:05:50

Hello everyone,

I'm facing a challenge on my CentOS server, running version "Linux linux-centos 3.10.0-1160.102.1.el7.x86_64 #1 SMP Tue Oct 17 15:42:21 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux". The server has disk encryption in place, as indicated in the excerpt below:

Code: Select all

df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 4.8G     0  4.8G   0% /dev
tmpfs                    4.8G  316K  4.8G   1% /dev/shm
tmpfs                    4.8G  9.9M  4.8G   1% /run
tmpfs                    4.8G     0  4.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G   46G  4.4G  92% /
/dev/mapper/centos-home  341G  259M  341G   1% /home
/dev/sda1               1014M  281M  734M  28% /boot
tmpfs                    979M   32K  979M   1% /run/user/1001
/dev/sr0   

Code: Select all

fdisk -l

Disk /dev/sda: 751.6 GB, 751619276800 bytes, 1468006400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0000c1dc

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1468006399   732953600   8e  Linux LVM

Disk /dev/mapper/luks-0175a7cd-9cd6-4315-bee5-b9015b6aca08: 750.5 GB, 750542389248 bytes, 1465903104 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 366.3 GB, 366271791104 bytes, 715374592 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Code: Select all

vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <699.00 GiB
  PE Size               4.00 MiB
  Total PE              178943
  Alloc PE / Size       102142 / 398.99 GiB
  Free  PE / Size       76801 / 300.00 GiB
  VG UUID               deTrjF-TC5T-cmZB-BOsb-uidA-UXLE-Wo85Kg

Code: Select all

  lsblk 
NAME                   MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                      8:0    0   700G  0 disk  
├─sda1                   8:1    0     1G  0 part  /boot
└─sda2                   8:2    0   699G  0 part  
  └─luks-0175a7cd-9cd6-4315-bee5-b9015b6aca08
                       253:0    0   699G  0 crypt 
    ├─centos-root      253:1    0    50G  0 lvm   /
    ├─centos-swap      253:2    0   7.9G  0 lvm   [SWAP]
    └─centos-home      253:3    0 341.1G  0 lvm   /home
sr0  
Currently, I am seeking guidance on how to resize and allocate the available space from "centos-home" to the "centos-root" partition. If anyone has experience with this process or can provide insights, I would greatly appreciate your assistance.

Please share suggestions or steps that can be followed to safely accomplish this task.

Thank you in advance for your collaboration.

User avatar
TrevorH
Site Admin
Posts: 33281
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: CentOS Partition Resizing

Post by TrevorH » 2023/12/07 14:39:32

Start by running df -hT /home and if it says it is xfs (the default) tehn know that the only way to shrink that is to backup its contents, blow away the filesystem, resize the device smaller, make a new filesystem on it, and then restore the data.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
TrevorH
Site Admin
Posts: 33281
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: CentOS Partition Resizing

Post by TrevorH » 2023/12/07 14:45:49

Hmm, actually you may not need to do that at all. The vgdisplay output you posted says

Alloc PE / Size 102142 / 398.99 GiB
Free PE / Size 76801 / 300.00 GiB

So the current volume group has 300GB free in it already that you can use to add to the centos-root LV. You would need to run something like

lvresize -L+100G -r centos/root

That says add 100G (-L+100G) to the existing LV (the + is very important, without + it takes the size as an absolute value so if you say -L1G it will make it 1G rather than adding 1G to the existing size) and resize the filesystem on it for me (-r). I recommend reading the fine man page for lvresize before you run it so that you understand what it willdo _before_ you do it!

I personally would not add ALL the freespace to it but keep some in reserve in case you need it at some later date for something else.

Another thing you could do is create a completely new LV and make a filesystem on it and then mount that new filesystem on the directory where you need all that space. For example if this was a mysql server and you had lots of data under /var/lib/mysql you could creat a new LV, format it and mount it on /var/lib/mysql and then that would be a selfcontained filesystem only used by mysql. The process of doing that is slightly more complicated but has advantages like you won't fill up your root filesystem if mysql uses too much space.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

allan777
Posts: 2
Joined: 2023/12/07 12:53:29

Re: CentOS Partition Resizing

Post by allan777 » 2023/12/07 18:29:07

Hi TrevorH, :)

My friend, you solved the space problem I was having. Thank you very much, your help saved my life.

I will be forever grateful to you and this incredible community. Thanks!! :P

User avatar
jlehtone
Posts: 4553
Joined: 2007/12/11 08:17:33
Location: Finland

Re: CentOS Partition Resizing

Post by jlehtone » 2023/12/08 07:22:09

TrevorH wrote:
2023/12/07 14:45:49
I personally would not add ALL the freespace to it but keep some in reserve in case you need it at some later date for something else.
"Me too". One example of "something else" is a different distro. The CentOS 7 will definitely die by next Summer, so one does not only want to but needs to get something else by then. As long as one has free, unallocated space, one can add root volume of new distro there. The data volumes, like /home, one can mount to the new system. One can even mount the root volume of CentOS 7 in order to read config from it.

If there is no free space, then something has to be removed before install of new distro.

TrevorH wrote:
2023/12/07 14:45:49
Another thing you could do is create a completely new LV and make a filesystem on it and then mount that new filesystem on the directory where you need all that space. For example if this was a mysql server and you had lots of data under /var/lib/mysql you could creat a new LV, format it and mount it on /var/lib/mysql and then that would be a selfcontained filesystem only used by mysql. The process of doing that is slightly more complicated but has advantages like you won't fill up your root filesystem if mysql uses too much space.
Continuing with the "other distro" example, one can mount a separate volume to /var/lib/mysql of different OS, so in that regard switch of distro does not require touching the MySQL data. (There are some mysql config that is not within /var/lib/mysql, so those would need other means to transfer, and change in MySQL version probably requires "SQL migration procedure" to adapt the database structures.)

Post Reply