How to resize (make it bigger) partition on Ubuntu 14.04 in Command Line

Let’s assume you have new virtual Linux Server box running and you “suddenly” out of space. Shit.
Well, you stopped your VM and increased the size of you hard drive from 20Gb to 40Gb, started VM again and… nothing changed.
This is what I did:

Sttep1: First i run cfdisk and removed swap (yes, you have to do it) and wrote change to a disk.
Step 2: Run Fdisk

sudo fdisk /dev/sda

Command (m for help): p

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 9437183 4717568 83 Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759

Command (m for help): p

Device Boot Start End Blocks Id System
/dev/sda1 2048 10485759 5241856 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.


Step 3: Reboot and run this:

sudo resize2fs /dev/sda1

Step 4: Now we need to create swap – go on and add another 1 or 2 gb to you hard drive in VM settings (size depends on the size of your VM memory – I have 1Gb).
Step 5: reboot, create new partition using cfdisk (in our sample it’s going to be /dev/sda2) and now create new swap:

sudo mkswap /dev/sd2

find swap UUID: blkid /dev/sda2
/dev/sda2: UUID="d4b07f36-2c18-4880-b301-f4c3b4f48ee0" TYPE="swap"

and put swap online:
sudo swapon -U d4b07f36-2c18-4880-b301-f4c3b4f48ee0

And to make it permanent add UUID to /etc/fstab file

root@ubuntu-local:~# cat /etc/fstab
# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
# / was on /dev/sda1 during installation
UUID=a13088d1-b28d-4638-84f9-794780fe2a4b /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=d4b07f36-2c18-4880-b301-f4c3b4f48ee0 none            swap    sw              0       0


Have fun!

Posted on March 8, 2016 at 13:09 by arte · Permalink
In: English, Fighting the system, Linux

Leave a Reply