How to Safely Expand Disk Partitions in Ubuntu: Step-by-Step Guide for Servers, Desktops, and Virtual Environments

1. Introduction

When using Ubuntu, you may sometimes encounter situations such as “not enough disk space” or “no free space available to install new applications.” In such cases, the process known as “partition expansion” can be extremely useful. Partition expansion means increasing the size of an existing disk partition to make more efficient use of your storage capacity.

Ubuntu is widely used for both server and desktop environments, and partition management becomes essential in various scenarios like virtual machines, VPS (Virtual Private Servers), and dual-boot setups. However, many users feel uncertain about “which method to use” or “whether data will be lost if a mistake is made during the process.”

This article provides clear, step-by-step instructions for expanding partitions in Ubuntu, from simple procedures to advanced examples involving LVM environments and virtual setups. We’ll also cover important precautions and safety tips to ensure your data remains secure during partition operations.

Whether you’re new to Linux commands or an intermediate user who has managed partitions on other distributions before, this guide is designed to be helpful for a wide audience.
While partition expansion requires careful handling, knowing the right steps will help you protect your important data and make the most out of your storage space.

2. Basic Knowledge Before Expanding Partitions

Before expanding partitions on Ubuntu, having a basic understanding will help you avoid mistakes and troubles. Here, we explain partition and file system fundamentals, whether or not LVM is used, and recent trends in Ubuntu’s partitioning setup.

2.1 What is a Partition?

A partition is a way to divide a physical storage device, such as a hard disk or SSD, into multiple logical sections for management purposes. For example, you can split a single disk into separate areas for “system” and “data,” and treat them independently. System files, user data, and swap space on Ubuntu are often managed in different partitions.

2.2 Types of Partition Tables (GPT and MBR)

There are two main types of disk partition table formats: GPT (GUID Partition Table) and MBR (Master Boot Record).

  • MBR: An older format supporting up to 2TB disks and a maximum of 4 primary partitions.
  • GPT: A newer format supporting disks larger than 2TB and more than 128 partitions. GPT is now standard on most modern Ubuntu systems.

If you’re not sure which format your system uses, check with a command like sudo parted -l.

2.3 About LVM (Logical Volume Manager)

On Ubuntu, you might either expand a regular partition directly or use the more flexible LVM (Logical Volume Manager) system.

  • Without LVM (Standard Partition)
    This is the typical setup where a file system such as ext4 is created directly on the partition.
  • With LVM
    Here, physical disks are grouped into Physical Volumes (PV), then combined into a Volume Group (VG), which in turn contains Logical Volumes (LV). This makes expanding and shrinking disk space easier, which is why it’s common on servers and cloud setups.

The expansion steps differ depending on whether LVM is used or not.

2.4 Partitioning Trends in Ubuntu

When installing Ubuntu, you can choose whether or not to use LVM. Since Ubuntu 20.04, LVM has become the recommended and default option for servers.
For desktops or dual-boot setups, the traditional simple partition layout (plain ext4) is still common.

2.5 Key Points Before Expanding a Partition

Before expanding a partition, you must have “unallocated space” available on your disk. Depending on partition placement or disk structure, expansion may not be possible, so first check your current disk layout with lsblk or parted.

It’s also strongly recommended to back up your important data beforehand. Even if you make a mistake, a backup ensures you can safely proceed.

3. Methods for Expanding Partitions

The procedure for expanding a partition in Ubuntu differs depending on your environment and disk structure. Here, we explain the steps for four main scenarios: non-LVM environments, LVM environments, VPS/cloud servers, and dual-boot systems.

3.1 Expanding a Partition in a Non-LVM (ext4) Environment

The most common scenario is a direct ext4 file system on a standard partition without LVM.

  1. Increase disk size
  • On virtual machines or VPS, first add disk capacity via the provider’s control panel.
  • On a physical PC, make sure there is unallocated space available.
  1. Expand the partition
  • Use sudo parted or sudo fdisk to expand the partition.
  • For parted, use a command like:
    sudo parted /dev/sda (parted) resizepart 1 <new end position, e.g. 100%>
  1. Expand the file system
  • After expanding the partition, extend the file system itself. For ext4, use:
    sudo resize2fs /dev/sda1
  • This makes the new space available to the file system.
  1. Check the expansion
  • Verify the increased disk space using df -h.

3.2 Expanding a Partition in an LVM Environment

If you use LVM (Logical Volume Manager), expansion is even more flexible.

  1. Increase disk size
  • First, expand the size of the physical or virtual disk.
  • On physical hardware, ensure unallocated space is available.
  1. Expand the Physical Volume (PV)
  • Make the new space available to LVM:
    sudo pvresize /dev/sda2
  • (Device name may vary depending on your setup)
  1. Expand the Logical Volume (LV)
  • Expand the desired logical volume:
    sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  • -l +100%FREE allocates all available space.
  1. Expand the file system
  • If you use ext4, run:
    sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
  1. Check
  • Check the expansion using df -h or lsblk.

3.3 Online Expansion in VPS or Cloud Environments

In VPS or cloud setups, you may want to expand partitions without rebooting. The growpart command can be helpful in these cases.

  1. Expand disk size
  • Increase disk space via your provider’s control panel.
  1. Expand the partition (growpart)
  • If the cloud-utils package is installed, use:
    sudo growpart /dev/sda 1
  • This automatically expands the partition (e.g., /dev/sda1).
  1. Expand the file system
  • Then extend the file system:
    sudo resize2fs /dev/sda1
  1. Check
  • Confirm the expansion with df -h.

3.4 Adjustments in Dual-Boot (Windows/Ubuntu) Environments

If you have both Windows and Ubuntu on the same disk, you may not be able to expand a partition unless unallocated space is adjacent.

  • Move unallocated space
  • Use Windows tools (like MiniTool Partition Wizard) to move unallocated space next to the Ubuntu partition.
  • Expand from Ubuntu
  • Then follow the above steps to expand the partition in Ubuntu.
  • Backup required
  • Since dual-boot systems are prone to issues, backup is a must before making any changes.

4. Troubleshooting & FAQ

You may encounter questions or issues before, during, or after expanding partitions. This section covers frequently asked questions and common errors with solutions.

4.1 Frequently Asked Questions (FAQ)

Q1. I can’t find any free (unallocated) space. What should I do?
A. Unallocated space is required to expand a partition. Check the disk state with lsblk or sudo parted /dev/sda print free. If no space is available, delete unnecessary partitions or add more disk space (for virtual environments).

Q2. Do I need pvresize or lvextend even if I don’t use LVM?
A. No. If you don’t use LVM, just follow the “expand partition → expand file system” procedure for ext4 or similar file systems. Use lsblk or sudo pvs to check if you use LVM.

Q3. There is no unallocated space next to the partition I want to expand. What should I do?
A. The space must be adjacent. Use a tool like “MiniTool Partition Wizard” (on Windows) to move partitions. For physical machines, always back up data and proceed carefully.

Q4. Can I expand partitions while Ubuntu is running?
A. You may not be able to expand mounted system partitions (/) while running. It’s safer to boot from a live USB (Ubuntu installer media) and perform operations there. On cloud or VPS servers, online expansion is often possible, but you may need to unmount or reboot if errors occur.

Q5. Swap space is preventing expansion. What can I do?
A. If swap is next to your Ubuntu partition, temporarily disable it with swapoff and delete it. After expansion, recreate swap and update /etc/fstab as needed.

Q6. I expanded the disk in a virtual environment, but the OS doesn’t recognize the new size. Why?
A. After expanding the disk in the hypervisor (VMware, VirtualBox, etc.), rescan the device in the OS using:
echo 1 > /sys/class/block/sdX/device/rescan, or reboot, or use partprobe.

Q7. What’s the difference between GPT and MBR? Which should I use?
A. GPT is recommended for disks over 2TB or with many partitions. MBR is only necessary for legacy system compatibility.

4.2 Common Errors and Solutions

  • “no free space available”
    → You need adjacent unallocated space. Adjust the partition and try again.
  • “device is busy” or “resource busy”
    → The partition is mounted or in use. Unmount it or use a live USB.
  • “The partition is currently in use”
    → The target partition is active. Stop related services or the OS, then retry.
  • “resize2fs: Bad magic number in super-block”
    → Check the file system type and use the correct command. For xfs, use xfs_growfs instead.

Knowing these potential issues beforehand helps you handle them calmly. Review these steps as needed, and check official documentation or reputable sites for additional guidance.

5. Post-Operation Checks & Summary

After completing partition expansion, always verify the results to ensure your data and system stability are intact.

5.1 How to Verify the Results

(1) Check disk space
Use the df -h command to list usage and free space for each mounted partition. Ensure that the expanded partition has increased as expected.

df -h

Pay particular attention to “/” and “/home” or other expanded areas.

(2) Check partition layout
The lsblk command shows storage devices and partitions in a tree format. Confirm that partition sizes and layout are correct.

lsblk

(3) Detailed check with parted
Use sudo parted /dev/sda print free to see partition tables and free space in detail.

(4) Additional checks for LVM
If you use LVM, run sudo lvs or sudo vgs to verify volume group and logical volume sizes.

5.2 Post-Operation Precautions

  • Backup management
    Once you confirm successful partition expansion and stable system operation, you may clean up any temporary backup data. If unsure, keep backups for a while longer.
  • File system check
    To prepare for potential issues, it’s recommended to run a file system check with fsck.
  sudo fsck /dev/sda1

(Run this after unmounting the partition.)

  • Reboot
    Generally, a reboot is not needed after expansion, but in some virtual or physical environments, rebooting ensures the new size is recognized.

5.3 Summary

Expanding partitions on Ubuntu is straightforward if you prepare in advance and follow the correct steps. By taking backups and double-checking your actions, you can safely increase disk space and avoid issues.

Proper partition and storage management are crucial for both system administration and daily use. We hope this guide helps you manage your Ubuntu environment more effectively.

年収訴求