SimplerCloud Pte Ltd

×
×

How to resize the data-disk partition?

Back

On an example below, a CentOS servelet with 20 GB of data-disk space was just upgraded to 40 GB. After the upgrade, the size of the data-disk is increased to 40 GB, but the existing partition is still 20 GB.

This article outlines the steps on how to resize the existing partition from the original 20 GB to 40 GB. In this example, the data-disk is mounted as /home.

Note: please take note that there is a risk of data loss or corruption during partitioning resize. We strongly advise you to make a backup copy of your files first before you perform these steps. We will not be responsible for any data loss or corruption as a result of performing these steps.

Another safer method to utilise the upgraded disk space is to create a new partition instead of resizing existing partition, as outlined on this article.

Here are the steps:

1. Backup your data first.

2. Firstly, check the actual size of your disk space and the existing partition. Based on example below, we can see that the existing partition is 20 GB but the disk space is already 40 GB.

====
root@cpanel2 [/home]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_centos6564bit-lv_root
                      13294328 7684880   4927464  61% /
tmpfs                   510172       0    510172   0% /dev/shm
/dev/vda1               487652  113719    348333  25% /boot
/dev/vdb1             20511244  434176  19028500   3% /home

root@cpanel2 [/home]# fdisk -l /dev/vdb

Disk /dev/vdb: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4e4013e1

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       41610    20971408+  83  Linux
====

3. Check the mount point of the data-disk by using "df" command.

====
root@cpanel2 [/]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_centos6564bit-lv_root
                      13294328 7686888   4925456  61% /
tmpfs                   510172       0    510172   0% /dev/shm
/dev/vda1               487652  113719    348333  25% /boot
/dev/vdb1             20511244  434176  19028500   3% /home
====

Based on the above result, we can see that the data-disk is mounted as /home.

4. Stop all services which are using the data-disk. For example, if you are running cPanel and configuring it to use data-disk, stop cPanel services.

====
root@cpanel2 [/]# /etc/init.d/cpanel stop
Stopping tailwatchd:  [1994] [2014-12-23 13:05:49 +0800] [main] Current process '1758' stopped
                                                           [  OK  ]
Stopping cPanel services:  Waiting for cpsrvd,whostmgrd,cpaneld,webmaild to shutdown ..... terminated.
                                                           [  OK  ]
Stopping cPanel dav services:  [Tue Dec 23 13:05:50 2014] Current process '1706' stopped
Waiting for cpdavd,cpdavd-ssl to shutdown ... not running.
                                                           [  OK  ]
Stopping cPanel queue services:  Graceful shutdown of cPanel TaskQueue Daemon requested. complete
                                                           [  OK  ]
Stopping cPanel brute force detector services:  Waiting for cphulkd.pl,cPhulkd,cphulkd to shutdown ... not running.
                                                           [  OK  ]
Stopping cPanel log services:
Stopping cPanel Chat services:                             [FAILED]

Stopping cPanel ssl services:  Waiting for (?^:^(?:stunnel$|stunnel-[0-9\.]+local)) to shutdown ... not running.
                                                           [  OK  ]
Stopping mailman services:  Shutting down Mailman's master qrunner
PID unreadable in: /usr/local/cpanel/3rdparty/mailman/data/master-qrunner.pid
[Errno 2] No such file or directory: '/usr/local/cpanel/3rdparty/mailman/data/master-qrunner.pid'
Is qrunner even running?
mailmanctl: no process killed
                                                           [FAILED]
====

5. Un-mount the /home partition using the "umount" command.

====
root@cpanel2 [/]# umount /home
====

Note: If you are bind-mounting /usr/local/cpanel to /home/local/cpanel as part of cPanel optimisation, you need to un-mount /usr/local/cpanel first before un-mounting /home .

6. Verify that the partition is no longer mounted.

====
root@cpanel2 [/]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_centos6564bit-lv_root
                      13294328 7686900   4925444  61% /
tmpfs                   510172       0    510172   0% /dev/shm
/dev/vda1               487652  113719    348333  25% /boot
====

7. Run "fdisk" on the data-disk, and print the existing partition.

====
root@cpanel2 [/]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/vdb: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4e4013e1

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       41610    20971408+  83  Linux

Command (m for help):
====

8. Delete the partition by typing "d". Don't worry, the data inside the partition will not be deleted. Use the "p" option to confirm the partition table after deletion. Type "w" to save the partitioning table configuration and exit.

====
Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/vdb: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4e4013e1

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@cpanel2 [/]#
====

9. Run the "fdisk" again, and create the larger partition. Type "n" to create a new partition, "p" to select primary partition, "1" for partition number, and use the default value for first and last cylinder, which will create the partition over the whole data-disk space.

====
root@cpanel2 [/]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-83220, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-83220, default 83220):
Using default value 83220

Command (m for help):
====

10. Type "p" to print the new partition table, and verify that the partition is now taking up the whole space.

====
Command (m for help): p

Disk /dev/vdb: 42.9 GB, 42949672960 bytes
16 heads, 63 sectors/track, 83220 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4e4013e1

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       83220    41942848+  83  Linux

Command (m for help):
====

11. Type "w" to write the new partition table into disk and exit.

====
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@cpanel2 [/]#
====

12. Run FSCK on the new partition.

====
root@cpanel2 [/]# e2fsck -f /dev/vdb1
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 29389/1310720 files (0.0% non-contiguous), 223585/5242852 blocks
root@cpanel2 [/]#
====

13. Run resize2fs to resize the filesystem on the partition.

====
root@cpanel2 [/]# resize2fs /dev/vdb1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vdb1 to 10485712 (4k) blocks.
The filesystem on /dev/vdb1 is now 10485712 blocks long.

root@cpanel2 [/]#
====

14. Mount the new partition.

====
root@cpanel2 [/]# mount -a
====

15. Run "df" to verify the size of the new partition and that it's mounted properly.

====
root@cpanel2 [/]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_centos6564bit-lv_root
                      13294328 7693532   4918812  62% /
tmpfs                   510172       0    510172   0% /dev/shm
/dev/vda1               487652  113719    348333  25% /boot
/dev/vdb1             41153664  438216  38618312   2% /home
====

16. Verify that the data inside is still intact.

====
root@cpanel2 [/]# cd /home
root@cpanel2 [/home]# ls -la
total 84
drwxr-xr-x   9 root root  4096 Dec 23 11:39 ./
dr-xr-xr-x. 28 root root  4096 Dec 23 13:01 ../
-rw-r--r--   1 root root   529 Apr  8  2014 0_README_BEFORE_DELETING_VIRTFS
drwxr-xr-x   2 root root  4096 Apr  8  2014 .cpan/
drwxr-xr-x   2 root root  4096 Apr  8  2014 cPanelInstall/
drwxr-xr-x   3 root root  4096 Dec 17 01:56 .cpanm/
drwx------   3 root root  4096 Dec 17 01:56 .cpcpan/
drwx------   3 root root  4096 Apr  8  2014 cpeasyapache/
-rw-r--r--   1 root root 21572 Feb 12  2014 latest
drwx------   2 root root 16384 Dec  5 18:37 lost+found/
-rw-------   1 root root  7168 Dec 23 11:40 quota.user
drwx--x--x   3 root root  4096 Apr  8  2014 virtfs/
====

That's it! :)

Was this article helpful?
Dislike0 Like0
Views: 3592