• Contact
  • About Me
  • Privacy Policy
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Solutions

How to Extend Partition on Ubuntu with fdisk

neo by neo
May 27, 2025
in Solutions
0
How to Extend Partition on Ubuntu with fdisk

How to Extend Partition on Ubuntu with fdisk

0
SHARES
57
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

Extend Partition with fdisk on Ubuntu

Extend Partition on Ubuntu with fdisk is very important to avoid running out of disk space on your system which can lead to performance issues and prevent you from installing new software or saving files. In this guide, we’ll show you how to extend disk space (extend parition) on Ubuntu by resizing partitions, expanding filesystems. These step-by-step instructions will help you increase your available storage space without losing data.

Prerequisites for Extending Disk Partition on Ubuntu

  • Backup Important Data
  • Increase Virtual Disk Size (if applicable)
    • If using a virtual machine, use your virtualization platform (e.g., VirtualBox, VMware) to increase the virtual disk size. This step should be done while the VM is powered off.
  • Free Up Disk Space
    • Before resizing, try to free up some space by removing unnecessary files using commands like sudo apt autoremove and sudo apt clean.
  • Sufficient Permissions
    • Ensure you have root or sudo access to perform disk management and resizing operations.

Steps to be Done to Extend Disk Partition

1: Identify hard drive use on your Ubuntu server

root@ubuntucore:/# df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                               96M   11M   86M  12% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.8G  9.8G     0 100% /
tmpfs                              479M     0  479M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          1.8G  129M  1.5G   8% /boot
tmpfs                               96M  4.0K   96M   1% /run/user/1000
root@ubuntucore:/# lshw -C disk
  *-disk
       description: ATA Disk
       product: VBOX HARDDISK
       vendor: VirtualBox
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sda
       version: 1.0
       serial: VB3f1a0754-d18ee5b0
       size: 20GiB (21GB)
       capabilities: gpt-1.00 partitioned partitioned:gpt
       configuration: ansiversion=5 guid=defac7ee-e74c-4159-a912-41f07f74bb1d logicalsectorsize=512 sectorsize=512

2: Increase the Virtual Disk Size

  • In your virtualization software (such as VirtualBox, VMware, or Hyper-V), increase the size of the virtual disk to the desired capacity. For example, increase it from 10 GB to 20 GB or your required size.

3: Extend the Partition

After increasing the virtual disk size, you need to extend the partition within Ubuntu.

Use cfdisk or fdisk to Resize the Partition.

List and modify partitions:

sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Command (m for help): p

Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DEFAC7EE-E74C-4159-A912-41F07F74BB1D

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3719167  3715072  1.8G Linux filesystem
/dev/sda3  3719168 41940991 38221824 18.2G Linux filesystem

Command (m for help): d
Partition number (1-3, default 3): 3

Partition 3 has been deleted.

Command (m for help): n
Partition number (3-128, default 3):
First sector (3719168-41943006, default 3719168):3719168
Last sector, +/-sectors or +/-size{K,M,G,T,P} (3719168-41943006, default 41943006):41943006

Created a new partition 3 of type 'Linux filesystem' and of size 18.2 GiB.
Partition #3 contains a LVM2_member signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): w

The partition table has been altered.
Syncing disks.

Modify Partitions:

  • Within fdisk, perform the following:
    • Type p to list the partition table.
    • Note the partition number of the root partition (/dev/sdaX).
    • Type d and the partition number to delete it (don’t worry, your data will be preserved as long as you recreate the partition with the same start sector).
    • Type n to create a new partition.
    • Select the same start sector as the deleted partition (fdisk will suggest the correct value).
    • Use the new size for the partition.
    • Type w to write the changes and exit.

Step 4: Reboot the System

Reboot your VM to ensure the changes take effect:

ADVERTISEMENT
ADVERTISEMENT
sudo reboot

Step 5: Extend Partition

root@ubuntucore:# sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 10.00 GiB (2560 extents) to 18.22 GiB (4665 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

or type the following:

ADVERTISEMENT
sudo pvresize /dev/sda3

or type the following:

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

You can check also the article related to the adding new hard drive to Ubuntu server at the link.

Extend Partition Troubleshooting

  • Check partitions with lsblk
lsblk output
lsblk output, Disk Size 300 GB but parition is using just 248 GB
  • Resize the Physical Volume (PV): Run this command to extend the physical volume to the new partition size:
sudo pvresize /dev/sda3
  • Extend the Logical Volume (LV): Now, use lvextend to add the remaining space to the logical volume:
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  • Resize the Filesystem: Finally, resize the filesystem to use the new space. For ext4:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

About The Author

neo

See author's posts

Tags: linux
ADVERTISEMENT
Previous Post

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Next Post

Fortinet FortiGate: Change Default Administration HTTPS and HTTP Port

neo

neo

Next Post
FortiGate Administration Settings

Fortinet FortiGate: Change Default Administration HTTPS and HTTP Port

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

Install SoftEther VPN Server on Ubuntu 24.04

Install SoftEther VPN Server on Ubuntu 24.04

Recent News

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

Install SoftEther VPN Server on Ubuntu 24.04

Install SoftEther VPN Server on Ubuntu 24.04

Timeshift on Linux: How to Create and Restore System Snapshots

Timeshift on Linux: How to Create and Restore System Snapshots

ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Browse by Category

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos

Recent News

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.