Hopp til hovedinnhold

How to resize an existing filesystem

Jørn Fauske
- 10 Sep 2015
fdisk screenshot

Resize a filesystem using fdisk, e2fsck and resize2fs 

First we need to make the partition holding the filesystem bigger.

We can use fdisk to help us with that (exchange <xvdb> below to match your device):

root@host: /# fdisk /dev/xvdb

print the partitiontable and make a note of the start, end and type of the partition you want to resize (if you have multiple partitions note the number too):

Command (m for help): p

Disk /dev/xvdb: 8589 MB, 8589934592 bytes
86 heads, 1 sectors/track, 195083 cylinders, total 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 identifier: 0x2511ce8c

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

Command (m for help):

Delete the partition with 'd':

Command (m for help): d
Selected partition 1

Command (m for help):

Create a new partition with the same number (1 here) and make sure you make it start at the same location as the deleted one (2048).
Set the last sector to a higher number. I'm using the proposed default here:

Command (m for help): n

Partition type:
   p primary (0 primary, 0 extended, 4 free)
   e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215):
Using default value 16777215

Command (m for help):

Then have fdisk write the new partition table using 'w' and quuit using 'q':

Command (m for help): w

Command (m for help): q

If the partitions were in use make the kernel aware of the new layout using partx:

root@host: /# partx /dev/xvdb

Run e2fsck to check the filesystem before resizing it to the newly available space:

root@host: /# e2fsck -f /dev/xvdb1 (the -f switch force a check even if the filesystem is marked as clean)

Run resize2fs to resize the filesystem:

root@host: /# resize2fs /dev/xvdb1 (adding an -f switch will force resize2fs to proceed with the resizing - see the man-page)

This process will not make any changes to existing data on the filesystem being resized.


til toppen