Adding a Volume to an existing VM running Linux BT Cloud Compute The power to build your own cloud solutions to serve your specific business needs Issue 3
Introduction This guide has been designed to walk you through the processes necessary to attach a volume to a virtual machine (VM) running a Linux operating system. A second guide has been produced to show how the same process is achieved on a VM running a Microsoft Windows Linux operating system. For the purpose of this guide it is assumed you have a VM already built and you have Root privileges on this VM. Creating a volume in the Cloud Compute Portal From the Home screen select [Manage Resources], [Cloud] Select the [Volume] tab Select [Add New] This will bring up a new window. Provide a friendly name for your volume. Select the Availability Zone you wish the volume to be created (remember it needs to be in the same as the VM you wish to attach it to), then select the size you wish the volume to be. The maximum size per volume is 2000Gb. The maximum number of additional volumes per VM is 6 with a maximum of 500 volumes per User within an Account. Once complete, agree to the Terms and Conditions, then select [OK]. British Telecommunications plc. Page 2 of 6 Issue 3
The Volume will now be created. Once a volume is created a conformation message will be displayed. Attaching the volume to a VM in the Cloud Compute Portal On the portal Click on the edit button in the top right hand corner and select [Attach Volume], this will open a new window. The Edit button can be identified as a cog wheel On the Attach Volume window using the drop down menu select the VM you wish to attach the volume followed by [OK]. The portal will now attach the volume to your chosen VM. Followed by a affirmative message of completion. Your volume is now attached to your VM however it is currently not recognised by your operating system therefore you are now required to access the VM to mount the attached volume into the operating system. British Telecommunications plc. Page 3 of 6 Issue 3
Mounting the new volume in the operating system Using the Console or SSH, access the VM. For the purposes of this guide we will use the console provided within the Portal. Select the VM followed by [View Console]. A new windows will popup, using your Root credentials login to the VM. For the purpose of this example we are using a Linux VM running the CentOS operating system. The VM already has a disk attached with two volumes therefore the new volume we have attached will show up as a second disk. Enter ls /dev/sd* this will display all the disks and volumes that are currently attached to your VM. We see the following output. As we already knew the VM has a disk with two volumes theses are visible as sda (the disk) with sda1 and sda2 as the volumes. That means that sdb is our new disk we have just attached. To enable the new disk, there are different ways to do this. The classical way is to partition the disk, format the disk and then mount the disk. For CentOS the following commands are used. These may vary depending upon the Linux OS you are using. Partition the disk Format the disk # fdisk /dev/sdb Mount the disk # mkfs.ext3 /dev/sdb1 Note we have given the volume a name - sbd1 # mkdir /disk1 # mount /dev/sdb1 /disk1 # df H British Telecommunications plc. Page 4 of 6 Issue 3
Logical Volume Manager More and more Linux distributions are using LVM (Logical Volume Manager) these days to manage the underlying disk storage. With LVM you get more flexibility in extending your disk storage plus some other benefits e.g. built-in snapshots or thin provisioning. The downside is, you have to learn a new concept and some new tools to manage LVM. Before we start with extending or adding storage, here is a little explanation and some terms used with LVM: PVs (physical volumes) - A PV is a disk partition, that is already prepared for use with LVM. VGs (volume groups) - A VG is built-up of one or more PVs. The VG acts as a container where you will find the LVs, that can be formatted with any standard Linux file system. LVs (logical volumes) The first step will be to create a partition from our newly provisioned disk and prepare it for LVM, so it can be used as a PV. Partition the disk # fdisk /dev/sdb Initialise the disk for LVM # pvcreate /dev/sdb1 To list all PVs on the system, you can simply type pvs on the console. Next step is to add this PV to a VG. You can list your VGs with the command vgs. The output should look similar to the following: # vgs VG #PV #LV #SN Attr VSize VFree vg_centos64x64v10 1 2 0 wz--n- 19.51g 0 In this example, our VG is named vg_centos64x64v10. To extend it with our new PV at /dev/sdb1, we will be using the vgextend command: # vgextend vg_centos64x64v10 /dev/sdb1 Using the vgs command again, you should see, that #PV, VSize and VFree have changed. After extending our VG, we can now extend any LV inside this VG. To list all available LVs in the system, you can use the lvs command: # lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_root vg_centos64x64v10 -wi-ao---- 18.54g lv_swap vg_centos64x64v10 -wi-ao---- 992.00m To extend the lv_root LV by 5GB, you have to use the lvextend command with the full path of the LV. All LVs are located under /dev/mapper/ : # lvextend L +5G /dev/mapper/lv_root IMPORTANT: Without the + in front of the size, you would set the absolute size of the LV. British Telecommunications plc. Page 5 of 6 Issue 3
The last step is now resizing the file system to the new volume size. For ext3/4-filesystems this can be done online by issuing the resize2fs command: # resize2fs p /dev/mapper/lv_root For other file systems e.g. XFS oder ReiserFS you should consult the appropriate man-pages. You can also create new LVs in the extended VG by using the lvcreate command. British Telecommunications plc. Page 6 of 6 Issue 3