Updated: 10 October 2026 · Applies to: GNU parted 3.6 on Debian 13, Ubuntu 24.04 and 26.04 and AlmaLinux 10.2; e2fsprogs 1.47, xfsprogs 6, growpart 0.33
To resize a Linux partition from the command line, use parted DISK resizepart NUMBER END, then resize the file system inside it. To extend partition 1 to the end of the disk: parted /dev/sdb resizepart 1 100%, then resize2fs /dev/sdb1 (ext4) or xfs_growfs /mount/point (XFS). To shrink an ext4 partition without losing data, do it the other way round on the unmounted partition: e2fsck -f, shrink the file system with resize2fs, then make the partition smaller with resizepart. XFS cannot be shrunk.
resizepart only moves the end of a partition; the start and the data stay where they are. Install parted with apt install parted or dnf install parted if it is missing. We tested every command below on a 4 GiB disk image file, so the output shows disk.img where your server shows a device such as /dev/sdb, /dev/vdb or /dev/nvme1n1.
Before you start
- Back up the data. Partition changes are written immediately and there is no undo.
- Check disk and partition sizes with
lsblk, the file system type and usage withdf -hT, and all partition tables withparted -l. - Be careful with
parted -s(script mode): it answers no questions. In our test,parted -s disk.img mklabel gptreplaced an existing partition table without any warning.
1. Show partitions and free space
$ parted disk.img unit MiB print free
Model: (file)
Disk /work/disk.img: 4096MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
0.02MiB 1.00MiB 0.98MiB Free Space
1 1.00MiB 2049MiB 2048MiB ext4 data
2049MiB 4096MiB 2047MiB Free Space
A partition can only grow into free space directly after it. unit MiB (or GiB) makes the numbers easier to work with than the default MB and GB.
2. Extend a partition and its file system
- Grow the partition to the end of the disk (or give an exact end such as
3GiB):$ parted disk.img resizepart 1 100% $ parted disk.img unit MiB print (header lines left out) Number Start End Size File system Name Flags 1 1.00MiB 4096MiB 4095MiB ext4 data
According to the parted 3.2 release notes,resizepartworks even on mounted partitions; parted then asks you to confirm. - Grow the file system to fill the partition:
resize2fs /dev/sdb1 # ext4, mounted or not xfs_growfs /mount/point # XFS, must be mounted
- Check the new size with
df -h.
Root partition or a cloud VPS disk that was enlarged: growpart grows a partition to all available space in one step and works on the mounted root disk. It is in cloud-guest-utils on Ubuntu and Debian and cloud-utils-growpart on AlmaLinux, Rocky Linux and RHEL. Note the space between disk and partition number:
$ growpart disk.img 1 CHANGED: partition=1 start=2048 old: size=4194304 end=4196351 new: size=8386527 end=8388574
Then run resize2fs /dev/sda1 or xfs_growfs /. If the root file system sits on LVM (common on Ubuntu Server), grow the partition, then the physical volume and the logical volume: see how to resize LVM volumes. If lsblk still shows the old disk size after a disk upgrade, reboot first. More root-disk cases are in expanding the root partition without LVM.
3. Shrink a partition without losing data (ext4)
Shrink the file system first, then the partition. Doing it the other way round cuts off the end of the file system. An ext4 file system cannot be shrunk while it is mounted (resize2fs stops with On-line shrinking not supported), so unmount it first. To shrink the root partition, boot the server from a live or rescue system, for example through its remote console.
- Unmount and check the file system (
resize2fsotherwise asks you to rune2fsck -ffirst):umount /dev/sdb1 e2fsck -f /dev/sdb1
- See how small it can get, then shrink the file system to the target size (1 GiB here):
$ resize2fs -P part.img Estimated minimum size of the filesystem: 26073 $ resize2fs part.img 1024M resize2fs 1.47.2 (1-Jan-2025) Resizing the filesystem on part.img to 262144 (4k) blocks. The filesystem on part.img is now 262144 (4k) blocks long.
-Pgives the minimum in file system blocks (4 KiB each). Leave generous room above it. - Shrink the partition. Give an end that is a little larger than the file system: it starts at 1 MiB and is 1024 MiB long, so the end is 1025 MiB. parted asks for confirmation:
$ parted disk.img resizepart 1 1025MiB Warning: Shrinking a partition can cause data loss, are you sure you want to continue? Yes/No? Yes
In script mode (parted -s) parted prints the same warning and stops with exit code 1, so run this step interactively. - Let the file system fill the partition exactly, check it again and mount it:
resize2fs /dev/sdb1 e2fsck -f /dev/sdb1 mount /dev/sdb1 /mount/point
In our test, a file's SHA-256 checksum was the same before and after the shrink. The freed space now shows as Free Space after partition 1 in print free, ready for a new partition.
XFS: the default on AlmaLinux, Rocky Linux and RHEL cannot be shrunk in practice. According to the xfs_growfs manual, only a limited shrink inside the last allocation group is implemented. To make an XFS partition smaller, back up, recreate it smaller and restore.
Moving the start of a partition (for example to give space to the partition in front) is not possible with parted. According to the parted release notes, version 3.0 removed the old resize, move, check and mkpartfs commands. On a desktop, the GParted live system can move partitions; on a server, back up and recreate.
4. Create a partition
parted /dev/sdb mklabel gpt parted /dev/sdb mkpart data ext4 1MiB 100% mkfs.ext4 /dev/sdb1
mklabel erases the partition list, so use it on new disks only; interactively it warns The existing disk label on ... will be destroyed and all data on this disk will be lost. Use GPT for disks over 2 TB and UEFI systems. On GPT the first word after mkpart is a name; on an msdos disk it is primary, extended or logical. The file system type in mkpart only sets the partition type, so run mkfs afterwards. Full steps including mounting: partition and mount a new disk with parted.
5. Name, flags and alignment
$ parted disk.img name 1 backups $ parted disk.img set 1 lvm on $ parted disk.img align-check optimal 1 1 aligned
Other common flags are esp (UEFI system partition), boot and raid. Starting partitions at 1MiB keeps them aligned.
6. Delete a partition and rescue a deleted one
Unmount the partition, remove it from /etc/fstab, then run parted /dev/sdb rm 2. If you deleted the wrong one and nothing has been written to the disk since, rescue searches for the file system and offers to add it back:
$ parted disk.img rescue 0% 100% Information: A ext4 primary partition was found at 1049kB -> 1075MB. Do you want to add it to the partition table? Yes/No/Cancel? Yes
The start and end you give must be near the lost partition's real start and end. In our test, rescue 1MiB 10MiB found nothing, while rescue 1MiB 1025MiB and rescue 0% 100% found it.
7. The Linux equivalent of chkdsk
Windows chkdsk does two jobs; on Linux they are separate tools:
- File system errors:
fsck, which runse2fsckfor ext4. Run it on an unmounted file system:$ e2fsck -fn part.img e2fsck 1.47.2 (1-Jan-2025) 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 data: 13/131072 files (0.0% non-contiguous), 28332/524288 blocks
-fforces a full check,-nonly reports, and-yrepairs everything it finds without asking. For XFS usexfs_repair -nto check andxfs_repairto repair. Details, including checking the root file system at boot: how to use fsck. - Bad sectors and disk health:
smartctlandbadblocks; see check a disk for bad blocks and errors.
Common problems
- "Partition /dev/sdb1 is being used. Are you sure you want to continue?": parted warns when the partition is mounted. Growing is safe to confirm; for shrinking, unmount first.
- "unable to inform the kernel of the change": the table was written but the kernel still uses the old one. Run
partprobe /dev/sdbor reboot before further changes. dfshows the old size: the file system was not grown. Runresize2fsorxfs_growfs.
Official documentation: GNU parted manual.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
