VCD VMware

Add new partition Ubuntu linux VM – Part (2), How to?

This article is part 2 for the series of add new disk to Linux Ubuntu machine. you can access the first port from here
In the previous post we add a new disk from VCD and I explained how to use fdisk to create a new disk and mount it to the new partition. I called that the short path, because it’s straight forward however it’s not as flexible as using LVM.

In this post, I will go through how to create a new LVM with the new disk. This option will give you the flexibility later to extend or shrink this logical volume which is much more recommended in my opinion.

1- Format Disk to LVM format

fdisk /dev/sdb
Command (m for help): p
Command (m for help): n
p primary partition (1-4)
p

t
8e
Partition number (1-4): 1
First cylinder (1-22400, default 1): <RETURN>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-22800, default 22800): 22400
Command (m for help): w
The partition table has been altered !

/dev/sdb1 Disk is formatted successfully

2- Create Physical Volume on the new formatted Disk

sudo pvcreate /dev/sdb1

Physical volume created successfully

3- Create Volume Group

sudo vgcreate vgu01 /dev/sdb1

Volume Group created successfully

4- Create Logical Volume

sudo lvcreate -L 499G -n lvu01 vgu01

Logical Volume created successfully

5- Format and Mount the Logical Volume

sudo mkfs -t ext3 /dev/vgu01/lvu01

This might take couple of seconds\minutes depends on the size of the disk

disk formatted successfully

Create a new directory

sudo mkdir /u01

Mount the new directory to the new logical volume created by adding a new line in the fstab file to make the change permanent

sudo vi /etc/fstab
/dev/vgu01/lvu01 /u01 ext3 defaults 0 3

6- Verify your work is good

sudo mount -all
df -ha

Reboot the VM to make sure it will boot up successfully and the disk will remain mounted.

Written by,
Mohamed Basha

Leave a Reply

Your email address will not be published. Required fields are marked *