Increasing disk space of a Red Hat virtual image with PureApplication

Originally posted on IBM Developer blog “Exploring PureApplication System, Software Service and more”  by Jonathan Deberdt on 31 May 2016 (10073 visits)

Virtual images are the base component of every virtual machine. On IBM PureApplication System (Intel-based) and Service, IBM provides some virtual images called “IBM OS Image for Red Hat Linux Systems”. In your catalog, you can also have virtual images coming from Hypervisor Editions of IBM products or some other virtual images that you have imported, cloned or customized. These virtual images have a defined disk space available but sometimes you need more. To get a larger disk space you can use add-ons in your patterns or increase the disk space within the virtual image.

Unfortunately, increasing the disk space of a virtual image is not straightforward and we will explain here how to do this.

Note: The method described here creates a new partition. Another method is to resize an existing partition, this method is described in my first comment on this article.

1. Creating a new image with a larger disk

First step is to create a new image with a larger disk. The easiest way to do this is to clone an existing image from the catalog.

Once logged in the PureApplication administrative console, go to Catalog -> Virtual Images.

Select the image you want to start with and click the Clone button.

Tip: this virtual image will be a temporary one. We will create the final one later. That’s why I set the version number to 0.9 in this step and the final is tagged as v1.0 in the next step. Choose carefully the name and version number of the virtual images you’ll create. Using an existing name for the virtual image but a different version number can be useful if you already have patterns that use this image : you then can change the image in your pattern by selecting the right version number instead of having to rebuild your pattern.

This will open a popup window. Fill the General information section and click on the Hardware configuration link to change the size of the virtual disk. Here we will increase from 12GB to 40GB.

Click OK. It takes a few minutes to create the new image.

2. Enlarging the file system

Unfortunately, changing the hardware configuration is not sufficient… You need a few steps to make this larger disk available for files. In order to make these steps persistent, we will use the “extend and capture” feature of PureApplication.

We need to:

  1. extend the image
  2. connect to the deployed image and choose where we want to add space
  3. create a new partition
  4. create a new physical volume
  5. extend the volume group
  6. extend the logical volume
  7. resize the file system
  8. capture the modified image

2.1 Extend the image

Select the new image you have created in previous step and click the Extend button.

This will create a Classic Virtual System pattern with your virtual image and deploy it once.

Fill the General information section and Deployment configuration section. The requested password is for root user.

After a few minutes, the status of the extended image is set to Draft and the image is deployed as you can see in line In the cloud now. Click on this link to view the deployed instance.

On the instance page, expand the Virtual machines section to get the IP address or hostname of your VM (line Network interface 1 in the Hardware and network sub-section).

2.2 Connect to the deployed image and choose where we want to add space

Connect through SSH to the virtual machine. You can use the Log In link provided by the PureApplication console (see screenshot above) or a tool such as PuTTY on Windows or a Terminal on Linux or MacOS. Log as root with the password you have provided in the deployment configuration.

Type fdisk -l to list the current disk partitions.

 -bash-4.1# fdisk -l

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x000738bb

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          32      256000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              32        1567    12325888   8e  Linux LVM

 Disk /dev/mapper/vg_root-LogVol01: 2147 MB, 2147483648 bytes
 255 heads, 63 sectors/track, 261 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/mapper/vg_root-LogVol00: 10.5 GB, 10473177088 bytes
 255 heads, 63 sectors/track, 1273 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 

As you can see on first line, the disk /dev/sda is 42.9 GB large but only 2147 MB and 10.5 GB are used by /dev/mapper/vg_root-LogVol01 and /dev/mapper/vg_root-LogVol00 respectively.

The only physical disk is called /dev/sda and contains 2 partitions: /dev/sda1 and /dev/sda2.

Type df -h

 -bash-4.1# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg_root-LogVol00
                       9.5G  2.4G  6.7G  26% /
 tmpfs                1000M     0 1000M   0% /dev/shm
 /dev/sda1             239M   55M  172M  24% /boot 

This gives you the available file system space. As you can see, /dev/mapper/vg_root-LogVol00 is mounted on /. We will extend /dev/mapper/vg_root-LogVol00 as much as possible to get more space on /.

2.3 Create a new partition

We will create a new partition on device /dev/sda.

Type fdisk /dev/sda.

 -bash-4.1# fdisk /dev/sda

 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').


 Command (m for help):  

Type p to list the partitions.

 Command (m for help): p

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x000738bb

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          32      256000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              32        1567    12325888   8e  Linux LVM

 Command (m for help):  

Type n to create a new partition. As there are only 2 existing primary partitions, we will create a third primary partition. By default, fdisk proposes to use all the available space (first and last available cylinders). In this example, we will use the default values.

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

 Command (m for help):  

Type p to list the partitions.

 Command (m for help): p

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x000738bb

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          32      256000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              32        1567    12325888   8e  Linux LVM
 /dev/sda3            1567        5221    29354770+  83  Linux

 Command (m for help):

 The new partition, /dev/sda3, is from “Linux” type. Its type ID is 83. We will change it to “Linux LVM”, type ID 8e.

Type t to change the type of our 3rd partition. Then list the partitions once again to check the configuration.

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

 Command (m for help): p

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x000738bb

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          32      256000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              32        1567    12325888   8e  Linux LVM
 /dev/sda3            1567        5221    29354770+  8e  Linux LVM

 Command (m for help):

 Type w to write the changes in the partition table.

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

 Calling ioctl() to re-read partition table.

 WARNING: Re-reading the partition table failed with error 16: Device or resource 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)
 Syncing disks. 

To be taken into account, the system needs to be restarted. You can use the reboot command.

2.4 Create a new physical volume

Once the virtual machine is rebooted, connect to it through SSH. You can check the current partition table using fdisk -l.

 -bash-4.1# fdisk -l

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x000738bb

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          32      256000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              32        1567    12325888   8e  Linux LVM
 /dev/sda3            1567        5221    29354770+  8e  Linux LVM

 Disk /dev/mapper/vg_root-LogVol01: 2147 MB, 2147483648 bytes
 255 heads, 63 sectors/track, 261 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/mapper/vg_root-LogVol00: 10.5 GB, 10473177088 bytes
 255 heads, 63 sectors/track, 1273 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 

Create the physical volume on the new partition using pvcreate:

 -bash-4.1# pvcreate /dev/sda3
   Physical volume "/dev/sda3" successfully created 

2.5 Extend the volume group

We will now get the name of the volume group using the vgdisplay command:

 -bash-4.1# vgdisplay
   --- Volume group ---
   VG Name               vg_root
   System ID             
   Format                lvm2
   Metadata Areas        1
   Metadata Sequence No  3
   VG Access             read/write
   VG Status             resizable
   MAX LV                0
   Cur LV                2
   Open LV               2
   Max PV                0
   Cur PV                1
   Act PV                1
   VG Size               11.75 GiB
   PE Size               4.00 MiB
   Total PE              3009
   Alloc PE / Size       3009 / 11.75 GiB
   Free  PE / Size       0 / 0   
   VG UUID               Vwenuf-OdXe-Ojtm-XWMo-XVQQ-o0L7-2q3jzA 

Extend the volume group (here vg_root) to the new partition with vgextend:

-bash-4.1# vgextend vg_root /dev/sda3
   Volume group "vg_root" successfully extended

You can check the new detailed volume group information using vgdisplay -v:

  -bash-4.1# vgdisplay -v
     Using volume group(s) on command line.
     Finding all volume groups.
   --- Volume group ---
   VG Name               vg_root
   System ID             
   Format                lvm2
   Metadata Areas        2
   Metadata Sequence No  4
   VG Access             read/write
   VG Status             resizable
   MAX LV                0
   Cur LV                2
   Open LV               2
   Max PV                0
   Cur PV                2
   Act PV                2
   VG Size               39.75 GiB
   PE Size               4.00 MiB
   Total PE              10175
   Alloc PE / Size       3009 / 11.75 GiB
   Free  PE / Size       7166 / 27.99 GiB
   VG UUID               Vwenuf-OdXe-Ojtm-XWMo-XVQQ-o0L7-2q3jzA

   --- Logical volume ---
   LV Path                /dev/vg_root/LogVol01
   LV Name                LogVol01
   VG Name                vg_root
   LV UUID                scPXkX-K6ue-jhyn-sbll-LzZj-C1fb-R8ejTG
   LV Write Access        read/write
   LV Creation host, time icon-vm-068-230.rtp.raleigh.ibm.com, 2014-02-07 15:55:35 +0000
   LV Status              available
   # open                 1
   LV Size                2.00 GiB
   Current LE             512
   Segments               1
   Allocation             inherit
   Read ahead sectors     auto
   - currently set to     256
   Block device           253:0

   --- Logical volume ---
   LV Path                /dev/vg_root/LogVol00
   LV Name                LogVol00
   VG Name                vg_root
   LV UUID                8bl26C-VZOh-elAN-X4RN-DDz1-3znH-ibaieB
   LV Write Access        read/write
   LV Creation host, time icon-vm-068-230.rtp.raleigh.ibm.com, 2014-02-07 15:55:35 +0000
   LV Status              available
   # open                 1
   LV Size                9.75 GiB
   Current LE             2497
   Segments               1
   Allocation             inherit
   Read ahead sectors     auto
   - currently set to     256
   Block device           253:1

   --- Physical volumes ---
   PV Name               /dev/sda2     
   PV UUID               WwgsZI-MmOt-IDVn-iJgr-Pevc-mNIL-eb4SZI
   PV Status             allocatable
   Total PE / Free PE    3009 / 0

   PV Name               /dev/sda3     
   PV UUID               I8OMac-EooX-kW9B-Y3Zq-XRVG-FIbz-gTIRI9
   PV Status             allocatable
   Total PE / Free PE    7166 / 7166

As you can see in the last lines, the physical volume /dev/sda3 is now part of the volume group and is free (Free PE : 7166).

2.6 Extend the logical volume

The tool to extend the mapped logical volume /dev/mapper/vg_root-LogVol00 is lvextend.

Type lvextend -l +100%FREE /dev/mapper/vg_root-LogVol00. This will extend the /dev/mapper/vg_root-LogVol00 with all available space.

 -bash-4.1# lvextend -l +100%FREE /dev/vg_root/LogVol00
   Size of logical volume vg_root/LogVol00 changed from 9.75 GiB (2497 extents) to 37.75 GiB (9663 extents).
   Logical volume LogVol00 successfully resized 

2.7 Resize the file system

Next step is to resize the file system to use the newly available space.  Use the resize2fs command on the logical volume.

 -bash-4.1# resize2fs  /dev/vg_root/LogVol00
 resize2fs 1.41.12 (17-May-2010)
 Filesystem at /dev/vg_root/LogVol00 is mounted on /; on-line resizing required
 old desc_blocks = 1, new_desc_blocks = 3
 Performing an on-line resize of /dev/vg_root/LogVol00 to 9894912 (4k) blocks.
 The filesystem on /dev/vg_root/LogVol00 is now 9894912 blocks long.

Check the partitions with fdisk -l.

 -bash-4.1# fdisk -l

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x000738bb

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          32      256000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              32        1567    12325888   8e  Linux LVM
 /dev/sda3            1567        5221    29354770+  8e  Linux LVM

 Disk /dev/mapper/vg_root-LogVol01: 2147 MB, 2147483648 bytes
 255 heads, 63 sectors/track, 261 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/mapper/vg_root-LogVol00: 40.5 GB, 40529559552 bytes
 255 heads, 63 sectors/track, 4927 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

As you can see, /dev/mapper/vg_root-LogVol00 is now 40.5 GB large.

You can also use df -h to see available space:

 -bash-4.1# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg_root-LogVol00
                        38G  2.4G   33G   7% /
 tmpfs                1000M     0 1000M   0% /dev/shm
 /dev/sda1             239M   55M  172M  24% /boot 

2.8 Capture the modified image

Now that the deployed virtual image has been modified, we will use PureApplication capability to record these changes using the Capture function. Go back to the PureApplication administrative console and the virtual image you have extended. Click the Capture button then OK to confirm.

Now that the image has been captured, you can test it by creating a simple pattern with this image and check if this new image meets your requirements for disk space using for example the df -h command.

3. Final steps

If you need more customisation of your virtual image, you can make additional changes and recapture it.

Otherwise, it is advised to lock it so that the image will be in read-only mode. New changes to this image will require to clone or extend it.

Your virtual image is now ready to be used in your patterns.

The last steps are just cleanup. You can delete:

  • The classic virtual system instance and pattern that PureApplication has created for extend and capture. It has the name of your virtual image (see links “In the cloud now” and “Included in patterns” in your virtual image). 
  • The temporary virtual image created at first step (cloned image).

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started