12.4. Resizing a Partition with fdisk

The fdisk utility allows you to create and manipulate GPT, MBR, Sun, SGI, and BSD partition tables. On disks with a GUID Partition Table (GPT), using the parted utility is recommended, as fdisk GPT support is in an experimental phase.
Before resizing a partition, back up the data stored on the file system and test the procedure, as the only way to change a partition size using fdisk is by deleting and recreating the partition.

Important

The partition you are resizing must be the last partition on a particular disk.
Red Hat only supports extending and resizing LVM partitions.

Procedure 12.4. Resizing a partition

The following procedure is provided only for reference. To resize a partition using fdisk:
  1. Unmount the device:
    ~]# umount /dev/vda
  2. Run fdisk disk_name. For example:
    ~]# fdisk /dev/vda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
    
    Command (m for help):
    
  3. Use the p option to determine the line number of the partition to be deleted.
    Command (m for help): p
    Disk /dev/vda: 16.1 GB, 16106127360 bytes, 31457280 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 label type: dos
    Disk identifier: 0x0006d09a
    
    Device    Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048     1026047      512000   83  Linux
    /dev/vda2         1026048    31457279    15215616   8e  Linux LVM
    
  4. Use the d option to delete a partition. If there is more than one partition available, fdisk prompts you to provide a number of the partition to delete:
    Command (m for help): d
    Partition number (1,2, default 2): 2
    Partition 2 is deleted
    
  5. Use the n option to create a partition and follow the prompts. Allow enough space for any future resizing. The fdisk default behavior (press Enter) is to use all space on the device. You can specify the end of the partition by sectors, or specify a human-readable size by using +<size><suffix>, for example +500M, or +10G.
    Red Hat recommends using the human-readable size specification if you do not want to use all free space, as fdisk aligns the end of the partition with the physical sectors. If you specify the size by providing an exact number (in sectors), fdisk does not align the end of the partition.
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): *Enter*
    Using default response p
    Partition number (2-4, default 2): *Enter*
    First sector (1026048-31457279, default 1026048): *Enter*
    Using default value 1026048
    Last sector, +sectors or +size{K,M,G} (1026048-31457279, default 31457279): +500M
    Partition 2 of type Linux and of size 500 MiB is set
    
  6. Set the partition type to LVM:
    Command (m for help): t
    Partition number (1,2, default 2): *Enter*     
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
  7. Write the changes with the w option when you are sure the changes are correct, as errors can cause instability with the selected partition.
  8. Run e2fsck on the device to check for consistency:
    ~]# e2fsck /dev/vda
    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
    ext4-1:11/131072 files (0.0% non-contiguous),27050/524128 blocks
    
  9. Mount the device:
    ~]# mount /dev/vda
For more information, see the fdisk(8) manual page.