Today I came across a customer account where they were using Rackspace Cloud Block Storage with the Linux Logical Volume Manager. They only had a single 75 gig disk, but they wanted to increase this to 200 gigs, by creating a new disk.

Customers Current CBS Setup

Since this customer is using LVM physical volume and volume groups, adding additional space is a lot easier than having to clone and copy disks, and redo the mount paths and /etc/fstab, and we're atually only a few steps away to increase the space. The customer says they need 200 gigs total space. The CBS disk is presently 75 gigs. So there is a shortfall of 125 Gigabytes of disk we need to add. Since the customer uses LVM, this can just be extended, by adding the additional 125gigs of space they require as an additional disk.

At this stage it's well worth noting there is a limitation for the maximum number of disks you have available. Your OS should be able to support at least 4 or 5 though.

Step 1: Add additional Disk with the free space required


Step 2: Confirm you are using LVM already

[root@nb1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vgcbs00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               75.00 GiB
  PE Size               4.00 MiB
  Total PE              19199
  Alloc PE / Size       19199 / 75.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               LtKrbh-LQ8C-rWgX-fVTN-7WUg-wGLJ-jtPt3j

Step 3: Attach the New CBS Volume you just created in step 1 to the server;

Step 4: Check where the new hard disk is attached. (it will say something like /dev/xvdb or /dev/xvdc , its v. highly important to get this right)


We can see the new 125GB CBS disk has been attached to /dev/xvdc this is the disk we will be using in the OS

Step 5: Partition New Disk


Lets just double check the number of attached disks to the server, anyway.

# fdisk -l

Disk /dev/xvdb: 80.5 GB, 80530636800 bytes
160 heads, 33 sectors/track, 29789 cylinders
Units = cylinders of 5280 * 512 = 2703360 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x563eba95

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1       29790    78642176   8e  Linux LVM

Disk /dev/xvda: 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: 0x00054178

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2611    20970496   83  Linux

Disk /dev/mapper/vgcbs00-data00: 80.5 GB, 80526442496 bytes
255 heads, 63 sectors/track, 9790 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: 0x00000000


Disk /dev/xvdc: 134.2 GB, 134217728000 bytes
255 heads, 63 sectors/track, 16317 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: 0x00000000

Not only can we see xvdc and it is the 125GB we expect.

fdisk /dev/xvdc

Type 'n' for new partition:

Type 'p' for primary partition.

Then Type the following:

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

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Naturally the automatically chosen last cylinder will be by default the last cylinder in the disk you have, so if you type enter, it will always choose the last cylinder for your disk, whatever its size.

Press 'w' and enter.

Step 6: Add the PV and LV, extend the volume group, and resize the file system

[root@nb1 ~]# pvcreate /dev/xvdc1
  Physical volume "/dev/xvdc1" successfully created
[root@nb1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vgcbs00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               75.00 GiB
  PE Size               4.00 MiB
  Total PE              19199
  Alloc PE / Size       19199 / 75.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               LtKrbh-LQ8C-rWgX-fVTN-7WUg-wGLJ-jtPt3j

[root@nb1 ~]# vgextend vgcbs00 /dev/xvdc1
  Volume group "vgcbs00" successfully extended
[root@nb1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vgcbs00
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               199.99 GiB
  PE Size               4.00 MiB
  Total PE              51197
  Alloc PE / Size       19199 / 75.00 GiB
  Free  PE / Size       31998 / 124.99 GiB
  VG UUID               LtKrbh-LQ8C-rWgX-fVTN-7WUg-wGLJ-jtPt3j

Check the Volume Group was added (check the new capacity was added)

root@nb1 ~]# pvscan
  PV /dev/xvdb1   VG vgcbs00         lvm2 [75.00 GiB / 0    free]
  PV /dev/xvdc1   VG vgcbs00         lvm2 [124.99 GiB / 124.99 GiB free]
  Total: 2 [199.99 GiB] / in use: 2 [199.99 GiB] / in no VG: 0 [0   ]

Extend the logical volume

[root@nb1 ~]# lvextend -l +31998 /dev/vgcbs00/data00
  Size of logical volume vgcbs00/data00 changed from 75.00 GiB (19199 extents) to 199.99 GiB (51197 extents).
  Logical volume data00 successfully resized.

You might be wondering why I chose +31998 , thats actually the number of 'extents', and is shown by vgdisplay as 'PE SIZE' .

I.e. Free PE / Size 31998 / 124.99 GiB. so that's how I knew it should be 31998. Your disk may be different so use it's correct PE.

Note that the filesystem hasn't yet been resized to reflect the extra disk capacity

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             20G   12G  7.5G  60% /
tmpfs                 496M  4.0K  496M   1% /dev/shm
/dev/mapper/vgcbs00-data00
                       74G   70G  939M  99% /var/www

Lets resize the filesystem, whilst it is on-line, without any disruption:

[root@nb1 ~]# resize2fs /dev/vgcbs00/data00
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vgcbs00/data00 is mounted on /var/www; on-line resizing required
old desc_blocks = 5, new_desc_blocks = 13
Performing an on-line resize of /dev/vgcbs00/data00 to 52425728 (4k) blocks.
The filesystem on /dev/vgcbs00/data00 is now 52425728 blocks long.


That's why LVM is cool, and flexible, and neat. However, there are many reasons why you might not want to use LVM. For instance, one weak point here is that if just one of the CBS disks fail, all of the data on the filesystem is lost as well. That said, LVM does support RAID, so there is no reason why you couldn't build some redundancy into your LVM. Naturally this goes beyond the scope of this tutorial, however I hope that it is of use!

Cheers &
Best wishes,
Adam