Resizing Existing Hard Drive Storage

You can upgrade the storage on your Server at any time by using the "Resize" function in My Account. When upgrading a disk there are a few important considerations. Sometimes customers are unable to view their new storage because the operating system does not automatically recognise the new space. There are different commands for each operation system Windows, Ubuntu, Redhat/Fedora and CentOS.

Unallocated Space

Please note that any unallocated space that is added to the primary partition can not be removed. All partitions (other than the primary) can be deleted and the unallocated space can be re-allocated. To get your new space allocated to your Cloud Server please see the following quick help notes.

Windows

Please use the Microsoft Windows Disk Manager to scan and engage the changed drive space.

Ubuntu

For a New Disk:

echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk /dev/sdb
press "n" then "p" then "1", then "1", then press enter, then press "t", then type in "8e" and press return, then press "w"
pvcreate /dev/sdb1
type "vgdisplay", note down the "VG Name"
vgextend  /dev/sdb1
lvdisplay, note down the logical volume you want to extend
lvextend  /dev/sdb1
resize2fs 

For an Extended Disk:

blockdev --rereadpt /dev/sda
fdisk
pvcreate /dev/sdaX
type "vgdisplay", note down the "VG Name"
vgextend  /dev/sdb1
lvdisplay, note down the logical volume you want to extend
lvextend  /dev/sdb1
resize2fs 


Fedora/Red Hat Linux

For a New Disk:
fdisk /dev/sdb
Enter "n"
Enter "p"
1 

Enter "w"
mkfs -t ext3 /dev/sdb mkdir /DIRECTORY
e2label /dev/sdb /DIRECTORY
echo "LABEL=/DIRECTORY /DIRECTORY ext3 defaults 1 2" >> /etc/fstab
mount LABEL=/DIRECTORY /DIRECTORY ;

Replace /DIRECTORY with whatever directory you want to mount /dev/sdb to.

For Centos

In this example, a Centos6 partition using LVM will be expanded from 20GB to 30GB. Note, a reboot of the VM may be required in order for the additional disk space to be made available to the operating system.

Check existing partitions

[root@centos6 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003468a

Run fdisk on the existing disk to create a new partition. Select option ?n? to create a new partition, followed by option p for a primary partition, select a partition number (3 in this example). Use default first and last cylinder values.

[root@centos6 ~]# fdisk /dev/sda
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): 3
First cylinder (2611-3916, default 2611):
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916):
Using default value 3916

Print partition table using ?p? to see the new partition.

Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003468a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 83 Linux

Change partition type to LVM.

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Save changes using ?w?.

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.

Reboot the host.

[root@centos6 ~]# shutdown -r now

Broadcast message from root@centos6
(/dev/pts/0) at 12:48 ...
The system is going down for reboot NOW!

Scan the volume

[root@centos6 ~]# pvscan
PV /dev/sda2 VG vg_centos6 lvm2 [19.51 GiB / 0 free]
Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0 ]

Extend volume group to include new partition,

[root@centos6 ~]# vgextend vg_centos6 /dev/sda3
No physical volume label read from /dev/sda3
Writing physical volume data to disk "/dev/sda3"
Physical volume "/dev/sda3" successfully created
Volume group "vg_centos6" successfully extended

Run pvscan again to see the new partition included as part of the volume group.

[root@centos6 ~]# pvscan
PV /dev/sda2 VG vg_centos6 lvm2 [19.51 GiB / 0 free]
PV /dev/sda3 VG vg_centos6 lvm2 [10.00 GiB / 10.00 GiB free]
Total: 2 [29.50 GiB] / in use: 2 [29.50 GiB] / in no VG: 0 [0 ]

Extend the logical volume to include the new disk space using lvextend command.

root@centos6 ~]# lvextend -L +9.99G /dev/vg_centos6/lv_root
Rounding size to boundary between physical extents: 9.99 GiB
Extending logical volume lv_root to 25.56 GiB
Logical volume lv_root successfully resized

Finally, extend the ext4 file system so it can use the extra space.

[root@centos6 ~]# resize2fs /dev/vg_centos6/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_centos6/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_centos6/lv_root to 6701056 (4k) blocks.
The filesystem on /dev/vg_centos6/lv_root is now 6701056 blocks long.

Verify the new space is available.

[root@centos6 ~]# df -h
 Filesystem Size Used Avail Use% Mounted on
 /dev/mapper/vg_centos6-lv_root
 26G 1.1G 23G 5% /
 tmpfs 939M 0 939M 0% /dev/shm
 /dev/sda1 485M 52M 408M 12% /boot

Original credit Increasing CentOS LVM under VMware by Red Branch