Extending partition and file system sizes

If you clone a virtual image and increase the size of one or more disks in the image, you need to run a set of operating system commands to extend the size of the partition and file system to use the additional disk space.

About this task

This task describes the procedure to extend the partition and file system size to use the additional disk space that you specified in your cloned image. This procedure is designed with the following assumptions:
  • The partition that is being manipulated is the only partition on that disk.
  • The partition is not the root partition.

Use this procedure if you previously cloned a copy of the image and configured the disk sizes to be larger than in the original image.

Note: Every time you deploy the cloned image, you must perform this procedure. However, to avoid having to run these commands each time, extend the cloned image, run this procedure, and then capture the image. You can then use this captured image repeatedly without having to run the commands every time.

By way of example, the following procedure describes the steps for extending the size of /opt/IBM/AppServer/profiles on a WebSphere Application Server Hypervisor Edition virtual image.

Procedure

  1. Log on to the deployed virtual machine and stop the running instance of WebSphere Application Server Hypervisor Edition.
    -bash-4.1# cd /opt/IBM/WebSphere/AppServer/bin
    -bash-4.1# ./stopServer.sh server1
    ADMU0116I: Tool information is being logged in file
               /opt/IBM/WebSphere/Profiles/DefaultAppSrv01/logs/server1/stopServer.log
    ADMU0128I: Starting tool with the DefaultAppSrv01 profile
    ADMU3100I: Reading configuration for server: server1
    ADMU3301I: Server stop request issued. Waiting for stop status.
    ADMU4000I: Server server1 stop completed.
  2. Use the df -h command to list the file systems and identify which file system is associated with /opt/IBM/WebSphere/Profiles.
    -bash-4.1# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda1             9.9G  4.2G  5.3G  45% /
    tmpfs                 937M  176K  937M   1% /dev/shm
    /dev/sdb1             7.9G  3.9G  3.7G  52% /opt/IBM/WebSphere/AppServer
    /dev/sdc1             2.0G  610M  1.3G  32% /opt/IBM/WebSphere/Profiles
    /dev/sdd1             2.0G  507M  1.4G  27% /opt/IBM/HTTPServer
    

    From this list, note that the /opt/IBM/WebSphere/Profiles directory is associated with the /dev/sdc1 file system.

  3. Use the fdisk -1 command to list the disks and partitions, and identify the partition associated with the selected file system.
    -bash-4.1# fdisk -1
    
    Disk /dev/sda: 12.9 GB, 12884901888 bytes
    255 heads, 63 sectors/track, 1566 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: 0x00005a0f
    
       Device Boot      Start         End      Blocks   Id   System
    /dev/sda1   *           1        1306    10484736   83   Linux
    /dev/sda2            1306        1567     2097152   82   Linux swap / Solaris
    
    Disk /dev/sdb: 8589 MB, 8589934592 bytes
    255 heads, 63 sectors/track, 1044 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: 0xe5886cba
    
       Device Boot      Start         End      Blocks   Id   System
    /dev/sdb1               1        1044     8385898+  83   Linux
    
    Disk /dev/sdc: 12.9 GB, 12884901888 bytes
    255 heads, 63 sectors/track, 1566 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: 0x47c0b2bc
    
       Device Boot      Start         End      Blocks   Id   System
    /dev/sdc1               1         261     2096451   83   Linux
    
    Disk /dev/sdd: 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: 0xdc97d4d3
    
       Device Boot      Start         End      Blocks   Id   System
    /dev/sdd1               1         261     2096451   83   Linux
    
    From this output, note the following partition information:
       Device Boot      Start         End      Blocks   Id   System
    /dev/sdc1               1         261     2096451   83   Linux
    
  4. Use the umount command to unmount the partition.
    -bash-4.1# umount /dev/sdc1
    
  5. Use the fdisk command to extend the partition.
    1. Run the fdisk -u command to open the partition table for the disk in sector mode.
      -bash-4.1# fdisk -u /dev/sdc
      
    2. Type p at the prompt to list the partitions on the disk.
      Command (m for help): p
      
      Disk /dev/sdc: 12.9 GB, 12884901888 bytes
      255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk identifier: 0x47c0b2bc
      
         Device Boot      Start         End      Blocks   Id   System
      /dev/sdc1              63     4192964     2096451   83   Linux
      

      Note the value of the starting sector (63). You will need this value later when you re-create the partition.

    3. Type d to delete this partition.
      Command (m for help): d
      Selected partition 1
    4. Type n to re-create the partition.
      Command (m for help): n
      
    5. Type p to select the primary partition type.
      Command action
         e   extended
         p   primary partition (1-4)
      p
    6. Type 1 to select partition number 1.
      Partition number (1-4): 1
    7. Specify the first sector using the same value (63) previously noted for the starting sector.
      Note: You must specify the same value for the starting point as before. Otherwise, you can no longer mount or use the file system.
      First sector (63-25165823, default 63): 63
    8. Specify the last sector for the partition end point to extend the partition to the full space available on the disk.
      Last sector, +sectors or _size{K,M,G} (63-25165823, default 25165823): 25165823
    9. Type p to list the updated partitions and verify the changes.
      Command (m for help): p
      
      Disk /dev/sdc: 12.9 GB, 12884901888 bytes
      255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk identifier: 0x47c0b2bc
      
         Device Boot      Start         End      Blocks   Id   System
      /dev/sdc1              63    25165823    12582880+  83   Linux
      
      

      This output shows that the End value changed from 4192964 to 25165823, and the number of blocks increased from 2096451 to 12582880+.

    10. Type w to save the changes.
      Command (m for help): w
      The partition table has been altered!
      
      Calling ioctl() to re-read partition table.
      Syncing disks.
      -bash-4.1#
      
  6. Use the e2fsck command to check the partition and verify that there are no errors.
    -bash-4.1# e2fsck -f /dev/sdc1
    e2fsck 1.41.12 (17-May-2010)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/sdc1: 2997/131072 files (0.5% non-contiguos), 164355/524112 blocks
  7. Use the resize2fs command to extend the file system to consume all additional space on the partition.
    -bash-4.1# resize2fs /dev/sdc1
    resize2fs 1.41.12 (17-May-2010)
    Resizing the file system on /dev/sdc1 to 3145720 (4k) blocks.
    The file system on /dev/sdc1 is now 3145720 blocks long.
    
  8. Use the mount command to mount the partition.
    -bash-4.1# mount /dev/sdc1 /opt/IBM/WebSphere/Profiles
    
  9. Use the df -h command to list the file systems again.
    -bash-4.1# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda1             9.9G  4.2G  5.3G  45% /
    tmpfs                 937M  176K  937M   1% /dev/shm
    /dev/sdb1             7.9G  3.9G  3.7G  52% /opt/IBM/WebSphere/AppServer
    /dev/sdd1             2.0G  507M  1.4G  27% /opt/IBM/HTTPServer
    /dev/sdc1              12G  612M   11G   6% /opt/IBM/WebSphere/Profiles
    

    From this list, note that the size of /dev/sdc1 increased from 2.0G to 12G, and the available space has increased from 1.3G to 11G.

  10. Start the server.
    -bash-4.1# ./startServer.sh server1
    ADMU0116I: Tool information is being logged in file
               /opt/IBM/WebSphere/Profiles/DefaultAppSrv01/logs/server1/startServer.log
    ADMU0128I: Starting tool with the DefaultAppSrv01 profile
    ADMU3100I: Reading configuration for server: server1
    ADMU3201I: Server launched. Waiting for initialization status.
    ADMU3000I: Server server1 open for e-business; process id is 7743

Results

The deployed image can take advantage of the larger disk space.

What to do next

If you performed this procedure after you extended the clone image, capture the image with these changes so that you can use the image repeatedly without having to complete these steps again.