- How to Resize a Partition using fdisk
- Procedure
- Resizing a Partition + Filesystem on Linux from the CLI
- Looking to buy a Virtual or Dedicated server? Do you like privacy and low prices? Try Privex!
- Order a server TODAY! Privacy is affordable™
- 1. Installing GNU parted
- 2. Check fdisk to find the right disk / partition + disk/partition info
- 3. Resize the disk partition («physical» partition) on your partition table using parted
- 4. Resize the actual filesystem to fit the grown partition
- Looking to buy a Virtual or Dedicated server? Do you like privacy and low prices? Try Privex!
How to Resize a Partition using fdisk
Disclaimer: The following information has been provided by Red Hat, but is outside the scope of our posted service level agreement and support procedures. The information has been tested however is provided as-is and any configuration settings or installed applications made from the information in this article could make your Operating System unsupported by Red Hat Support Services and non-recoverable. The intent of this article is to provide you with information to accomplish your system needs. Use the information in this article at your own risk.
On disks with a GUID Partition Table (GPT), using the parted utility is recommended, as fdisk GPT support is in an experimental phase.
Procedure
1. Unmount the partition:
2. Run fdisk disk_name.
~]# fdisk /dev/vdb 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):
3. Check the partition number you wish to delete with the p. The partitions are listed under the heading “Device”.
Command (m for help): p Disk /dev/vda: 407.6 GiB, 437629485056 bytes, 854745088 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: dos Disk identifier: 0x5c873cba Partition 2 does not start on physical sector boundary. Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 1640447 307200 8e Linux LVM
4. Use the option d to delete a partition. If there is more than one, fdisk prompts for which one to delete.
Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 has been deleted.
5. Use the option n to create a new partition. Follow the prompts and ensure you allow enough space for any future resizing that is needed. It is possible to specify a set, human-readable size instead of using sectors if this is preferred.
Note: It is recommended to follow fdisk’s defaults as the default values (for example, the first partition sectors) and partition sizes specified are always aligned according to the device properties.
Warning: If you are recreating a partition in order to allow for more room on a mounted file system, ensure you create it with the same starting disk sector as before. Otherwise the resize operation will not work and the entire file system may be lost.
Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): *Enter* Using default response p. Partition number (2-4, default 2): *Enter* First sector (1026048-854745087, default 1026048): *Enter* Last sector, +sectors or +size (1026048-854745087, default 854745087): +500M Created a new partition 2 of type 'Linux' and of size 500 MiB.
6. Check the partition table to ensure that the partitions are created as required using the p option.
Command (m for help): p Disk /dev/vda: 407.6 GiB, 437629485056 bytes, 854745088 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: dos Disk identifier: 0xf6e2b6cb Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 2050047 512000 8e Linux LVM
7. Write the changes with the w option when you are sure they are correct.
Important: Errors in this process that are written could cause instability with the selected file system.
8. Run fsck on the partition.
~]# e2fsck /dev/vdb1 e2fsck 1.41.12 (17-May-2010) 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 ext4-1:11/131072 files (0.0% non-contiguous),27050/524128 blocks
9. Finally, if you need to increase or decrease the file system, refer to the How to Shrink an ext2/3/4 File System with resize2fs, or the How to Grow an ext2/3/4 File System with resize2fs.
If you don’t need to increase or decrease the file system, mount the partition.
Resizing a Partition + Filesystem on Linux from the CLI
Note that we’ll only be covering EXPANSION / GROWING, and not shrinking, since it’s much more difficult to shrink a partition than to grow it.
- A system running Linux (Ubuntu, Debian, Linux Mint, Fedora, CentOS, RedHat or anything else)
- Free space in your partition table — AFTER the partition you want to resize — to extend the partition into.
- The third-party program parted (available in most package managers)
Looking to buy a Virtual or Dedicated server? Do you like privacy and low prices? Try Privex!
We have virtual servers starting from just US$0.99/mo, and dedicated servers starting from as low as US$50/mo
Unlike other hosts, we don’t ask for any personal details — only a name (can be an alias / username), and an e-mail address so we can send you your server details and renewal invoices.
We also accept several different cryptocurrencies with our own in-house payment processor — no third parties involved in processing your payments.
At the time of writing, we currently accept: Bitcoin (BTC), Litecoin (LTC), Monero (XMR), Dogecoin (DOGE), HIVE, and HBD
Order a server TODAY! Privacy is affordable™
1. Installing GNU parted
For Debian-based distros such as Ubuntu, Debian, Linux Mint, etc. — you can install parted from apt:
sudo apt update sudo apt install -y parted
For Redhat-based distros (Fedora, Redhat, CentOS, Oracle, Amazon Linux, etc.), you can use either dnf (for modern distros) or yum (for older distros):
# for modern distros sudo dnf install -y parted # for older distros, or if you get an error saying dnf isn't installed sudo yum install -y parted
For Arch Linux, you can use pacman :
2. Check fdisk to find the right disk / partition + disk/partition info
Run the following command to get information about all disks and partitions on your system:
Look through the output to find the disk (e.g. /dev/sda ) that you want to resize, as well as the partition you want to resize.
You might also be able to find the disk /dev/ path by running df -h / (if you want to resize a different partition instead of the rootfs / — then replace / with the mountpoint of the partition you want to resize)
3. Resize the disk partition («physical» partition) on your partition table using parted
Once you’ve located the disk you want to resize a partition on (e.g. /dev/sda ), open it using parted:
Now use the print command within parted, which will print information about that disk, and the partitions on the disk, so you can figure out how much space you have available to expand the partition into, and the partition number of the partition you want to resize:
Finally, use resizepart [partition_number] with the number of the partition you want to resize, to actually resize the partition:
You may be warned that the disk is in use, this is generally okay, so enter yes
When asked to enter the End: — if the partition is at the end of the disk, you can enter the size of the disk outputted by print , but take off 0.2GB for safety, e.g. if it was 48.5GB — you’d enter 48.3G.
If the partition is between two partitions, then you’ll want to enter an end location at least 100mb before the «Start» of the following partition. For example, if you’re resizing partition 1 (start: 1020MB, end: 20GB), and partition 2 starts at 41.2GB — then you could set the End of part 1 to 41GB (~200mb before part 2).
4. Resize the actual filesystem to fit the grown partition
The command you’d run to grow a filesystem, depends on what filesystem the partition is actually formatted with.
Most Linux systems use the filesystem ext4 (or an older version such as ext3 — which uses the same command to resize anyway), though either yourself or the installer for your distro may have formatted some/all of the partitions with an alternative filesystem such as XFS, or Btrfs.
To discover the filesystem used by each partition on your system, use the following command:
To grow an ext2 , ext3 or ext4 filesystem, use the command (where /dev/sda1 is the partition device to resize):
To grow an xfs filesystem, use the command (where / is the MOUNTPOINT of the XFS formatted device):
To grow a btrfs filesystem, use the command (where / is the MOUNTPOINT of the Btrfs formatted device):
sudo btrfs filesystem resize max /
Finally, check the filesystem was resized by running df -h to list the size, used space, and avail space on all mounts:
Looking to buy a Virtual or Dedicated server? Do you like privacy and low prices? Try Privex!
We have virtual servers starting from just US$0.99/mo, and dedicated servers starting from as low as US$50/mo
Unlike other hosts, we don’t ask for any personal details — only a name (can be an alias / username), and an e-mail address so we can send you your server details and renewal invoices.
We also accept several different cryptocurrencies with our own in-house payment processor — no third parties involved in processing your payments.
At the time of writing, we currently accept: Bitcoin (BTC), Litecoin (LTC), Monero (XMR), Dogecoin (DOGE), HIVE, and HBD