SimplerCloud Pte Ltd

×
×

How to create a new partition over an unused upgraded disk space?

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 create another 20 GB partition over the newly upgraded disk space, in addition to the existing 20 GB partition.

Here are the steps:

1. 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

2. Run fdisk on the data-disk. Presuming that the data-disk is on /dev/vdb, here is the command:

fdisk /dev/vdb

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):

3. Type "p" to print the partition table.

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

You can see that based on the partition table, there's only one existing partition (/dev/vdb1) with 20 GB in size.

4. Type "n" to add a new partition, and then type "p" to select primary partition. We will be creating a second partition, therefore type "2" on the partition number. Key in the default start and end cylinder (the numbers may vary) to make use of the existing unused space. See below example.

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

5. Type "p" to print the partition table again.

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
/dev/vdb2           41611       83220    20971440   83  Linux

You can see that there are two partitions now. There is another /dev/vdb2 partition created.

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

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.

7. Reboot the servelet so that the kernel will be able to re-read the revised partition table.

root@cpanel2 [/]# reboot

Broadcast message from root@cpanel2.sg.or.id
        (/dev/pts/0) at 12:19 ...

The system is going down for reboot NOW!

8. Once the servelet is up and running, SSH into the servelet again and verify if the new partition is being recognized.

root@cpanel2 [~]# 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
/dev/vdb2           41611       83220    20971440   83  Linux

9. Format the new partition (/dev/vdb2) using "mkfs". Please ensure that you don't format the wrong partition.

root@cpanel2 [/]# mkfs -t ext4 /dev/vdb2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242860 blocks
262143 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

10. Check the UUID of the new partition using "blkid".

root@cpanel2 [/]# blkid | grep vdb2
/dev/vdb2: UUID="8e50628e-47a5-4fcc-8701-696a48c69c78" TYPE="ext4"

11. Use your favourite text editor (nano or vi) to modify /etc/fstab to add the new entry:

nano /etc/fstab

or

vi /etc/fstab

=====
/dev/mapper/vg_centos6564bit-lv_root    /       ext4    usrjquota=quota.user,jqfmt=vfsv0        1       1
UUID=35f10ea1-3af2-4848-bad5-2b92c269c290 /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos6564bit-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID=13088d31-6441-4e12-91b5-f4fb05782d1a       /home   ext4    usrjquota=quota.user,jqfmt=vfsv0        1       2
=====

Make a copy of the last line, but then change the UUID and the mount-point for the new partition. In below example, the new partition is mounted as /home2.

=====
/dev/mapper/vg_centos6564bit-lv_root    /       ext4    usrjquota=quota.user,jqfmt=vfsv0        1       1
UUID=35f10ea1-3af2-4848-bad5-2b92c269c290 /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos6564bit-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID=13088d31-6441-4e12-91b5-f4fb05782d1a       /home   ext4    usrjquota=quota.user,jqfmt=vfsv0        1       2
UUID=8e50628e-47a5-4fcc-8701-696a48c69c78       /home2  ext4    usrjquota=quota.user,jqfmt=vfsv0        1       2
=====

Save the file.

12. Create the directory for the mount-point. In this case, we will create the /home2 directory.

root@cpanel2 [/]# mkdir /home2

13. Type "mount -a" to mount all partitions. This will mount the new partition into /home2.

root@cpanel2 [/]# mount -a

14. Verify using "df" that the new partition is already mounted.

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

That's it. :)

Was this article helpful?
Dislike0 Like0
Views: 3748