Sunday, August 6, 2023

How to increase disk size in Zimbra on virtual machine

If you face the issue with free space on our disk in Zimbra and decide to increase the size, I propose you to consider two scenarios: 

First - You have less than 4 partitions in your virtual disk, like below and you need to extend the disk.

Disk /dev/sda:

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

/dev/sda3       419430400   629145599   104857600   8e  Linux LVM


Second - You have 4 partitions in your virtual disk,

Disk /dev/sda:  

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

/dev/sda3       419430400   629145599   104857600   8e  Linux LVM

/dev/sda4       629145600   671088639    20971520   8e  Linux LVM


At first, please make sure you have a full backup of your system before proceeding.


So, in the first scenario is simple and you need to turn off your virtual machine, extend the disk and use this manual - How to Increase the size of a Linux LVM by expanding the virtual machine disk (rootusers.com)


In the second scenario you need to do more changes and I will describe it below detail. I will show how I added 100GB on my server:


Because you have 4 partitions, due to this you can't create more 4 partitions and you need to extend you current last forth partition.


  • We will be using fdisk to resize the partition. Open the disk and make a note of the current partition layout. We will need this information later. 

[root@mail ~]#  fdisk /dev/sda

 

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

  

Command (m for help): p

 

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk label type: dos

Disk identifier: 0x000c10a7

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

/dev/sda3       419430400   629145599   104857600   8e  Linux LVM

/dev/sda4       629145600   838860799   104857600   8e  Linux LVM

  • In order to resize the partition, we need to delete and recreate it. When you recreate the partition, you must create it with the same exact starting unit and you must create it with an ending point the same or greater unit. Delete the partition and print the partition table to verify it’s gone.

Command (m for help): d

Partition number (1-4, default 4): 4

Partition 4 is deleted

 

Command (m for help): p

 

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk label type: dos

Disk identifier: 0x000c10a7

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

/dev/sda3       419430400   629145599   104857600   8e  Linux LVM

  • Recreate the partition using the same starting unit. In our example, the starting unit is 629145600 . For the ending unit, we want the maximum amount of free disk space, which is automatically populated by default, so we left the prompt blank. Print the partition table again to verify.

Command (m for help): n

Partition type:

   p   primary (3 primary, 0 extended, 1 free)

   e   extended

Select (default e): p

Selected partition 4

First sector (629145600-1048575999, default 629145600): 629145600

Last sector, +sectors or +size{K,M,G} (629145600-1048575999, default 1048575999):

Using default value 1048575999

Partition 4 of type Linux and of size 200 GiB is set

 

Command (m for help): p

 

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk label type: dos

Disk identifier: 0x000c10a7

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

/dev/sda3       419430400   629145599   104857600   8e  Linux LVM

/dev/sda4       629145600  1048575999   209715200   83  Linux

  • Now you’ll notice the new partition type is “83 Linux” where it was “8e Linux LVM” before. Use the type of command to change the type of the new partition back to what it was to begin with. Again, print the partition table to verify. It never hurts to verify each step to ensure the commands you’re entering are being executed correctly.

Command (m for help): t

Partition number (1-4, default 4): 4

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): p

 

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk label type: dos

Disk identifier: 0x000c10a7

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2099199     1048576   83  Linux

/dev/sda2         2099200   419430399   208665600   8e  Linux LVM

/dev/sda3       419430400   629145599   104857600   8e  Linux LVM

/dev/sda4       629145600  1048575999   209715200   8e  Linux LVM

  •  Compare the new partition table to the old one. The start unit should be exactly the same after as before. The end unit should be greater than or equal to what it was before. The Id/System partition types should match exactly. If everything looks okay, write the changes and reboot the system.

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@mail ~]# reboot

  • We’re not done, but getting close. Once the guest reboots, log back in. We resized the partition, but still need to resize the LVM physical volume. This is done with the pvresize command. The additional disk space should now be reflected in pvdisplay.
[root@mail ~]# pvdisplay

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               centos

  PV Size               <199.00 GiB / not usable 3.00 MiB

  Allocatable           yes (but full)

  PE Size               4.00 MiB

  Total PE              50943

  Free PE               0

  Allocated PE          50943

  PV UUID               RJ0Zwb-APTO-1pE2-u6i2-UMY5-eZGV-42Gbij

 

  --- Physical volume ---

  PV Name               /dev/sda3

  VG Name               centos

  PV Size               100.00 GiB / not usable 4.00 MiB

  Allocatable           yes (but full)

  PE Size               4.00 MiB

  Total PE              25599

  Free PE               0

  Allocated PE          25599

  PV UUID               V1u35B-0APN-zMyR-ZQRL-1fj9-tZYT-1ekBDw

 

  --- Physical volume ---

  PV Name               /dev/sda4

  VG Name               centos

  PV Size               <100.00 GiB / not usable 3.00 MiB

  Allocatable           yes (but full)

  PE Size               4.00 MiB

  Total PE              25599

  Free PE               0

  Allocated PE          25599

  PV UUID               PhC17d-u9q2-mi7R-Cz3x-D6v6-FFBq-Ct2Bn1

 

[root@mail ~]# pvresize  /dev/sda4

  Physical volume "/dev/sda4" changed

  1 physical volume(s) resized or updated / 0 physical volume(s) not resized


  • Check that PV Size  was changed.

[root@mail ~]# pvdisplay

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               centos

  PV Size               <199.00 GiB / not usable 3.00 MiB

  Allocatable           yes (but full)

  PE Size               4.00 MiB

  Total PE              50943

  Free PE               0

  Allocated PE          50943

  PV UUID               RJ0Zwb-APTO-1pE2-u6i2-UMY5-eZGV-42Gbij

 

  --- Physical volume ---

  PV Name               /dev/sda3

  VG Name               centos

  PV Size               100.00 GiB / not usable 4.00 MiB

  Allocatable           yes (but full)

  PE Size               4.00 MiB

  Total PE              25599

  Free PE               0

  Allocated PE          25599

  PV UUID               V1u35B-0APN-zMyR-ZQRL-1fj9-tZYT-1ekBDw

 

  --- Physical volume ---

  PV Name               /dev/sda4

  VG Name               centos

  PV Size               <200.00 GiB / not usable 3.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              51199

  Free PE               25600

  Allocated PE          25599

  PV UUID               PhC17d-u9q2-mi7R-Cz3x-D6v6-FFBq-Ct2Bn1

  •  Assign all free space to the lv of your choice, in our case, this is /dev/centos/root

[root@mail ~]# lvextend -l +100%FREE /dev/centos/root

  Size of logical volume centos/root changed from <381.24 GiB (97597 extents) to <481.24 GiB (123197 extents).

  Logical volume centos/root successfully resized.

  • Lastly, we resize the filesystem to make the additional space available. We’re using xfs, this will be done with xfs_growfs. If you are using ext4, so this is done with resize2fs - resize2fs /dev/mapper/centos-root

[root@mail ~]# xfs_growfs /dev/mapper/centos-root

meta-data=/dev/mapper/centos-root isize=512    agcount=31, agsize=3276800 blks

         =                       sectsz=4096  attr=2, projid32bit=1

         =                       crc=1        finobt=0 spinodes=0

data     =                       bsize=4096   blocks=99939328, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=1

log      =internal               bsize=4096   blocks=6400, version=2

         =                       sectsz=4096  sunit=1 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 99939328 to 126153728

  • Finish, check our result 

[root@mail ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

devtmpfs                 3.8G     0  3.8G   0% /dev

tmpfs                    3.8G     0  3.8G   0% /dev/shm

tmpfs                    3.8G  8.8M  3.8G   1% /run

tmpfs                    3.8G     0  3.8G   0% /sys/fs/cgroup

/dev/mapper/centos-root  482G  345G  137G  72% /

/dev/sda1               1014M  316M  699M  32% /boot

/dev/mapper/centos-home   10G   33M   10G   1% /home

tmpfs                    772M     0  772M   0% /run/user/997

tmpfs                    772M     0  772M   0% /run/user/0


 P.S. I used the material from this link with my data - nacko.net, but now it's not available, I think it will be useful again for someone like me.


No comments:

Post a Comment