-2

I'm struggling with resizing a CentOs Partition on a Server. I found some steps, but I'm not sure which circumstances I face and whats the correct approach and i definitely cannot mess that up. The space should already be available, but the partition is not resized as far as I can tell. The goal is to extend the partition /dev/sdb1 from 197GB to 1TB

Below are the "lsblk", "df -h" and "fdisk -l" results which should show my current situation.

[ ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   50G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  3.7G  0 part [SWAP]
└─sda3   8:3    0 45.3G  0 part /
sdb      8:16   0    1T  0 disk 
└─sdb1   8:17   0 1024G  0 part /var/www/vhosts
sdc      8:32   0   50G  0 disk 
└─sdc1   8:33   0   50G  0 part /var/lib/psa
sr0     11:0    1  680M  0 rom  


[ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.8G     0  7.8G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           7.8G   12M  7.8G   1% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda3        45G  7.0G   36G  17% /
/dev/sda1       976M  135M  775M  15% /boot
/dev/sdc1        50G   53M   47G   1% /var/lib/psa
/dev/sdb1       197G  126G   62G  68% /var/www/vhosts
tmpfs           1.6G     0  1.6G   0% /run/user/0


[ ~]# fdisk -l

Disk /dev/sda: 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 label type: dos
Disk identifier: 0x0009c4b4

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     9910271     3905536   82  Linux swap / Solaris
/dev/sda3         9910272   104855551    47472640   83  Linux

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0x8e948ef1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  2147483647  1073740800   83  Linux

Disk /dev/sdc: 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 label type: dos
Disk identifier: 0x7677284e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   104857599    52427776   83  Linux

I found this answer here on an external page, but I'm not familiar with the commands and cannot tell, if thats the right way to go (if allowed I can paste the url). Partition Paths have not beed update to mine.

There are three steps to make:

  1. alter your partition table so sda2 ends at end of disk
  2. reread the partition table (will require a reboot)
  3. resize your LVM pv using pvresize

Step 1 - Partition table Run fdisk /dev/sda. Issue p to print your current partition table and copy that output to some safe place. Now issue d followed by 2 to remove the second partition. Issue n to create a new second partition. Make sure the start equals the start of the partition table you printed earlier. Make sure the end is at the end of the disk (usually the default).

Issue t followed by 2 followed by 8e to toggle the partition type of your new second partition to 8e (Linux LVM).

Issue p to review your new partition layout and make sure the start of the new second partition is exactly where the old second partition was.

If everything looks right, issue w to write the partition table to disk. You will get an error message from partprobe that the partition table couldn't be reread (because the disk is in use).

Step 2 Reboot your system This step is neccessary so the partition table gets re-read.

Step 3 Resize the LVM PV After your system rebooted invoke pvresize /dev/sda2. Your Physical LVM volume will now span the rest of the drive and you can create or extend logical volumes into that space.

The question is, is that the right way to increase the partition size without loosing any data on it for a CentOs System?

Thank you

Vario
  • 490
  • 4
  • 13

1 Answers1

1

As you can see the partition

sdb      8:16   0    1T  0 disk 
└─sdb1   8:17   0 1024G  0 part /var/www/vhosts

is already 1TB. So you need to extend the filesystem. If your filesystem is ext4 you can use command:

resize2fs /var/www/vhosts

if your filesystem is xfs you can use command:

xfs_growfs /var/www/vhosts
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31