User Rating: 4 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Inactive
 

This article will show how to increase disk partition with fdisk then increase the related filesystem.

In this example, the partition is not used with lvm but the resize partition should also work for lvm.

In this article, you'll need :
- Oracle Linux 7 installed (see oel7 installation here)
- root access is needed
- the concerned filesystem declared in /etc/fstab (see here)

Careful ...
Please do a system and data backup before performing the steps on this article.

Recreate partition

We will delete and recreate th partition with fstab.
This will just modify table partition, so this will not delete any of your data if you do not overlap or shrink partitions.

# Make sure, it is in /etc/fstab
[root]$ cat /etc/fstab | grep u02
    UUID=c739f00f-434f-478a-b80e-d761cbacac81       /u02    xfs     defaults        1 2

# Unmount filesystem
[root]$ umount /u02

# Check disk before growing disk
[root]$ fdisk -l /dev/vdc

    Disk /dev/vdc: 8589 MB, 8589934592 bytes, 16777216 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: 0xef23ac51

       Device Boot      Start         End      Blocks   Id  System
    /dev/vdc1            2048    16777215     8387584   83  Linux

# Check disk after adding 8GB to disk
[root]$ fdisk -l /dev/vdc

    Disk /dev/vdc: 17.2 GB, 17179869184 bytes, 33554432 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: 0xef23ac51

       Device Boot      Start         End      Blocks   Id  System
    /dev/vdc1            2048    16777215     8387584   83  Linux

# Resize partition
[root]$ fdisk /dev/vdc
    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): d
    Selected partition 1
    Partition 1 is deleted

Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
Select (default p):
    Using default response p
Partition number (1-4, default 1):
First sector (2048-33554431, default 2048):
    Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431):
    Using default value 33554431
    Partition 1 of type Linux and of size 16 GiB is set

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

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

# Check partition after resizing
[root]$  fdisk -l /dev/vdc

    Disk /dev/vdc: 17.2 GB, 17179869184 bytes, 33554432 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: 0xef23ac51

       Device Boot      Start         End      Blocks   Id  System
    /dev/vdc1            2048    33554431    16776192   83  Linux

Resize filesystem

After resizing disk partition, we can now resize the related filesystem.

# Mount filesystem first, if not
[root]$ mount /u02               

# Check filesystem size before resizing
[root]$ df -h /u02
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/vdc1       8,0G  1,1G  7,0G  14% /u02

# Resize filesystem (error)
[root]$ resize2fs /dev/vdc1
    resize2fs 1.42.9 (28-Dec-2013)
    resize2fs: Bad magic number in super-block while trying to open /dev/vdc1
    Couldn't find valid filesystem superblock.
# We got this error because this is a xfs filesystem
# But the command above should work with extX filesystem

# Resize for xfs filesystem
[root]$ xfs_growfs -d /u02
    meta-data=/dev/vdc1              isize=256    agcount=4, agsize=524224 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=0        finobt=0
    data     =                       bsize=4096   blocks=2096896, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
    log      =internal               bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 2096896 to 4194048

# Check filesystem size after resizing
[root]$ df -h /u02
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/vdc1        16G  1,1G   15G   7% /u02

 

HTH.
Please leave comments and suggestions,
Michel.

Reference
How to Resize a Partition using fdisk (redhat.com)

Enjoyed this article? Please like it or share it.

Add comment

Please connect with one of social login below (or fill up name and email)

     


Security code
Refresh