How-To: Extend Disk Space

How to extend disk space

This how-to focuses on UCS running as a virtual machine.
Note1: We assume a default LVM based partition layout.
Note2: As preparation extend the virtual disk on the hypervisor (ESXi, UVMM, Proxmoxx,…)

Step 1

To make the new size of the disk visible to UCS either re-scan the SCSI bus or simply reboot the machine:

root@ucs:~# fdisk -l | grep "sda:"
Disk /dev/sda: 16 GiB, 17179869184 bytes, 33554432 sectors
root@ucs:~# rescan-scsi-bus -s
root@ucs:~# fdisk -l | grep "sda:"
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors

Step 2

Re-size the partition.

Note1: Misconfiguring your partition table can lead to a complete loss of data. Make sure you follow these steps in detail. Make a backup before doing so!
Note2: If you abort fdisk with (“q”) before writing actually to disk (“w”) all changes will get lost and you have to start from Step 2a again.
Note3: You might use any other tool to re-configure your disk layout.

Step 2a

Start fdisk for your first system disk change the display unit with “u” and press “p” to show the current disk layout.

root@ucs:~# fdisk /dev/sda

Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): p
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Geometry: 64 heads, 32 sectors/track, 20480 cylinders
Units: cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1948a14d

Device     Boot Start   End Cylinders  Size Id Type
/dev/sda1  *        2   488       488  487M 83 Linux
/dev/sda2         489 16383     15895 15,5G  5 Extended
/dev/sda5         490 16383     15895 15,5G 8e Linux LVM

Command (m for help): 

Important: Write down the start cylinder for sda2 and sda5. In this example this is 489 for sda2 and 490 for sda5.

Step 2b

Delete the LVM partition sda5 by typing “d”

Command (m for help): d
Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.

Command (m for help):

Step 2c

Delete the extended partition sda2 by typing “d”

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help):

Step 2d

Re-create a new extended partition by typing “n” and select “e” as partition type.
Important: Make sure you use the above noted value for sda2 as “First cylinder”!

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 2
First cylinder (489-20480, default 489): 489
Last cylinder, +cylinders or +size{K,M,G,T,P} (489-20480, default 20480): 

Created a new partition 2 of type 'Extended' and of size 19,5 GiB.

Command (m for help): 

Step 2e

Re-create a new LVM partition by typing “n” with the above noted start value and just confirm the suggested size with “Enter”. Make sure you do NOT remove the LVM2_member signature!
Note: If you do not get the question about the removal of the LVM signature there is something wrong and you should abort without writing by pressing ‘q’.

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First cylinder (490-20480, default 490): 490
Last cylinder, +cylinders or +size{K,M,G,T,P} (490-20480, default 20480): 

Created a new partition 5 of type 'Linux' and of size 19,5 GiB.
Partition #5 contains a LVM2_member signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): 

Step 2f

Set the correct type for the new partition.

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

Command (m for help):

Step 2g

Write the new partition layout to the disk and leave fdisk with “w”. You will see some warnings which can be ignored here as they are expected.
Note If something did not work as expected do NOT write the new layout as you might loose your data! Just quit with ‘q’ instead of ‘w’.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: The device or the resource is 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).

Step 3

Reboot the server and re-size the physical volume of your LVM to the new size of the partition
pvresize /dev/sda5

Step 4

Resize your logical volume you want to extend:

lvresize -l +100%FREE /dev/vg_ucs/root

Step 5

Finally, resize the filesystem to match the new size:
resize2fs /dev/vg_ucs/root

Now your /-volume will display the new size. Verify with df -h.

see also: