Showing posts with label LVM. Show all posts
Showing posts with label LVM. Show all posts

Saturday, 10 May 2014

Create LVM volume from multiple disks

Recently I had to crate an Amazon EC2 Instance with a storage capacity of 5Tb, unfortunately, Amazon only allows us to create 1Tb volumes so I had to create 5 volumes, attach them to the instance and create a 5Tb LVM device.

My instance was running Ubuntu and I hat to install the lvm2 package:
apt-get install lvm2 
The volumes attached to my instance where named from /dev/xvdg to /dev/xvdk

to find the names you can use the command:
fdisk -l
First we have to prepare our volumes for LVM with:
pvcreate /dev/xvdg /dev/xvdh /dev/xvdi /dev/xvdj /dev/xvdk
You can run the following command to check the result:
pvdisplay
The next step is to create a volume group, I used the command:
vgcreate storage /dev/xvdg /dev/xvdh /dev/xvdi /dev/xvdj /dev/xvdk 
And used the command:
vgdisplay
to check the result, you can also use:
vgscan 
Now we need to create the logical volume, in this case I wanted to use the entire available space so, I used the command:
lvcreate -n data -l 100%free storage
And
lvdisplay 
to check the new volume if every thing goes well it should be on /dev/storage/data 

you can also use the command 
lvscan
Now you just have to format the new device, you can use:
mkft -t ext4 /dev/storage/data
When ready you can mount it with:
mout /dev/storage/data /mnt

Possibly Related Posts

Thursday, 1 March 2012

Increase LVM Volume

This is how I did it on a VMWare Machine but the procedure should be the same for a phisical machine:

First off, VMWare, like many other hypervisors, allows to create a second HDD on the fly while the vm is running.

Once that was done, login into the server and:
# echo “- – -” > /sys/class/scsi_host/host#/scan
partprobe should also do the trick

Just to see that the new disk is available use:
# fdisk -l
In this case it was /dev/sdb

create a new partition with
# fdisk /dev/sdb
press n and then w

Format the new partition:
# mkfs.ext3 /dev/sdb1
list the volume groups:
# vgs
add new physical volume
# pvcreate /dev/sdb1
extend the default volume group from the vgs command
# vgextend VolGroup /dev/sdb1
check to see pv and vg has another volume with:
# vgs
And list logical volumes
# lvdisplay
extend my / volume by the entire size of /dev/sdb1
# lvextend /dev/VolGroup/lv_root/dev/sdb1
resize filesystem to match vol size increase
# resize2fs /dev/VolGroup/lv_root
(requires a 2.6 kernel to resize while fs running)

Possibly Related Posts