The post outlines the steps to extend the last partition of the disk and the filesystem residing on it. Remember, you can only resize the last partition on your device. If this is not the last partition, you will need to backup your data, rebuild the disk and partitions, then restore the data. This post assumes you are using either a GPT partition table or a msdos partition table using primary partition types.

 

Note :

Storage resize commands are dangerous and can cause a complete loss of data. Please run a backup before attempting to follow the steps in this post.

 

1. Check the size of your current file system using the df command:

# df -h /test
Filesystem   Size   Used   Avail   Use%   Mounted on
/dev/xvdc1   9.1G   84M    8.5G    1%     /test

 

2. Umount the file system

# umount /test

 

3. Check with parted the last partition size, we are going to see the start and end sectors:

# parted /dev/xvdc u s p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdc: 41943040s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start    End       Size         File system   Name     Flags
    1   2048s    19531775s 19529728s    ext4          primary

We can see that the ending sector is 19531775 and the full disk size 41943040s. This indicates that the partition has space to grow.

 

4. Now remove the existing partition with parted by specifying the partition number In this case the number is 1.

# parted /dev/xvdc rm 1
Information: You may need to update /etc/fstab.

 

5. Verify the partition was removed :

# parted /dev/xvdc p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags

 

6. Now recreate the partition with the new size. Specify the same starting sector as the previous partition, and use the percentage size that you need in this example I will extend by 80%

# parted -s /dev/xvdc mkpart primary 2048s 80%
Warning: The resulting partition is not properly aligned for best performance.

 

7. Verify the new size of the partition and the new last sector size, we can compare with our previous output.

# parted /dev/xvdc p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number   Start   End      Size     File system   Name     Flags
1        1049kB  17.2GB   17.2GB   ext4          primary          ### New size of 80 % will be 17 GB.

 

# parted /dev/xvdc u s p
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdc: 41943040s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number   Start    End     Size File   system Name  Flags
    1    2048s 33554431s  33552384s      ext4     primary

 

8. Run a file system check against the device

# e2fsck /dev/xvdc1
e2fsck 1.43-WIP (20-Jun-2013)
/dev/xvdc1: clean, 21/610800 files, 92508/2441216 blocks

 

9. Resize the files system using resize2fs (ext3 and ex4 filesystem)

# resize2fs -f /dev/xvdc1
resize2fs 1.43-WIP (20-Jun-2013)
Resizing the filesystem on /dev/xvdc1 to 4194048 (4k) blocks.
The filesystem on /dev/xvdc1 is now 4194048 blocks long.

 

10. Mount the file system and verify the new size, compare with the old output.

# mount /dev/xvdc1 /test

 

# df -h /test
Filesystem   Size   Used   Avail   Use%   Mounted on
/dev/xvdc1   16G    89M    15G     1%     /test

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)