How to extend an EXT4 partition using parted and resize2fs
Please do not forget to take backups before the process.
root@host:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [275GB]? -0
(parted) quit
Information: You may need to update /etc/fstab.root@host:~#
Hint:
- resizepart 1 to resize /dev/sda1
- -0 resizes it to the end of the disk. - Indicates that it should count from the end of the disk, not the start. This makes -0 the last sector of the disk - which is suitable when you want to make it as big as possible.
If we type df -H it will still showing the old size:
root@host:~# df -H Filesystem Size Used Avail Use% Mounted on /dev/sda1 271G 240G 18G 94% / udev 11M 0 11M 0% /dev tmpfs 1.3G 8.8M 1.3G 1% /run tmpfs 3.2G 25k 3.2G 1% /dev/shm tmpfs 5.3M 0 5.3M 0% /run/lock tmpfs 3.2G 0 3.2G 0% /sys/fs/cgroup root@host:~#
Secondly, we need to use resize2fs to extend the volume:
(The file system meta information needs to indicate the size of the disk, and resize2fs updates this.)
root@host:~# resize2fs /dev/sda1 resize2fs 1.42.12 (29-Aug-2014) Filesystem at /dev/sda1 is mounted on /; on-line resizing required old_desc_blocks = 16, new_desc_blocks = 29 The filesystem on /dev/sda1 is now 117964544 (4k) blocks long. root@host:~#