117

I installed Ubuntu Server 18.04 with the LVM option and left the default partition setup. Now my main drive only has 4GB in a 1TB hard drive. How can I fix this without starting from scratch?

Results of df -h :

Filesystem                         Size    Used Available Use% Mounted on
udev                                16G       0       16G   0% /dev
tmpfs                               32G    1.7M       32G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  3.9G    3.6G       92M  98% /    
tmpfs                               16G       0       16G   0% /dev/shm
tmpfs                              5.0M       0      5.0M   0% /run/lock
tmpfs                               16G       0       16G   0% /sys/fs/cgroup
/dev/loop0                          87M     87M         0 100% /snap/core/4917
/dev/loop1                         3.2M    3.2M         0 100% /snap/stress-ng/471
/dev/loop2                          90M     90M         0 100% /snap/core/6130
/dev/sda2                          976M    143M      766M  16% /boot
tmpfs                              3.2G       0      3.2G   0% /run/user/1000
karel
  • 114,770
CyborgDroid
  • 1,283
  • 2
  • 8
  • 6

4 Answers4

279

Had the exact same problem with a fresh install of Ubuntu Server 18.04.1.

What I had to do was:

# We need to resize the logical volume to use all the existing and free space of the volume group
$ lvm
lvm> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
lvm> exit

# And then, we need to resize the file system to use the new available space in the logical volume
$ resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 58
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 120784896 (4k) blocks long.

# Finally, you can check that you now have available space:
$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              786M  1.2M  785M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  454G  3.8G  432G   1% /

If you didn't customize the LVM settings, the names for the volume group and logical volume should be the same as mine (ubuntu-vg and ubuntu-lv respectively).

If your partition is completely full, you could get a no space left error when trying to resize the logical volume like:

lvm> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  /etc/lvm/archive/.lvm_computer: write error failed: No space left on device

The easiest way to fix this is by removing apt cache (it will get regenerated next time you do apt update), which should give you more than enough space to complete the operation:

$ rm -rf /var/cache/apt/*
yorch
  • 3,300
  • 1
    perfect.. any idea why this happens? what should we have done on loggin in? – Andy Mar 11 '19 at 19:27
  • 37
    I would count this as major bug - but apparently the folks at Canonical don't since a fresh installation of an Ubuntu Server 18.04.2 installation has exactly the same "behavior". – Jey DWork Jul 09 '19 at 16:19
  • 14
    Are you serious? How is this expected behavior? I landed here after just installing a fresh 18.04.2 and wondering why / is only 4Gigs. – Plazgoth Jul 10 '19 at 04:47
  • 10
    I continue to visit this answer and will continue to do so as long as LVM doesn't allocate all of available disk space on a disk – jspinella Sep 08 '19 at 02:56
  • @Plazgoth youp, you are right, I assume it's a bug. IMHO, expected behavior should be: take entire vm disk, then I increase disk size from hypervisor or add more drives to physical machine, then I use LVM to acquire additional space.... – Aleksandar Pavić Oct 16 '19 at 08:14
  • Thank a million. It's the first step: lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv that I was missing... – nurchi Feb 06 '20 at 15:58
  • 2
    Worked as a charm in 2020! Thanks!! – adamsfamily Mar 21 '20 at 09:26
  • 1
    Thank you so much! You´re a lifesaver! – Mauricio Lazo Mar 31 '20 at 08:08
  • 6
    I've been coming back to this answer for years now. Still an issue with 18.04.4 server. Thank you! – jspinella Apr 04 '20 at 20:07
  • I'm getting: Multiple VGs found with the same name: skipping ubuntu-vg Use --select vg_uuid=<uuid> in place of the VG name. after the lvm command. Any thoughts? – jfa May 07 '20 at 17:23
  • When I use the select command, it says lvextend: unrecognized option '--select' – jfa May 07 '20 at 17:51
  • Ok, I sorted it. Apparently, if you have multiple volumes plugged in, ubuntu will name them all the same VG. I had to unplug my other hard disks to resize the volume. I'm leaving my other comments up because they describe the issue I was having. Mods, remove if inappropriate. – jfa May 07 '20 at 18:19
  • Thank you for this, my sandbox is no longer throwing insidious disk space errors – Jason Bristol May 23 '20 at 22:54
  • 14
    Well, it is still a bug in Ubuntu Server 20.04 and I keep still coming back to this answer. Thank you for this info. – Mauricio Lazo May 26 '20 at 21:12
  • Thanks for sharing. All my VMs created with Ubuntu 20.04 still have 4GB disks in 2020 after install, sadly. – miho Jul 11 '20 at 08:30
  • This worked beautifully. I didn't even need the backups I saved, no data loss. You sir are a gentleman and a scholar. – Brendan Aug 19 '20 at 03:21
  • 1
    Thanks. I rarely use Ubuntu Server and usually go with Debian, but some hardware was giving me trouble with Debian and I couldn't for the life me figure out why my 1TB RAID was showing up as ~200GB in a df -h. This sorted the problem out swimmingly. – user1119648 Oct 15 '20 at 12:57
  • Thanks for this, it's still an issue with Ubuntu 18.04.5 – JC23 Nov 10 '20 at 20:10
  • If I perform the steps given in answer, will there be any data loss? – Mukesh Dec 05 '20 at 15:03
  • 2
    @Mukesh no, no data loss at all – yorch Dec 05 '20 at 21:01
  • I ran into this issue while cloning my hard drive and this worked like a charm! Thanks. – devaent Sep 15 '21 at 00:11
  • 1
    Worked for ubuntu server 22. Thanks. – S2L Aug 20 '22 at 11:50
  • 2
    Still an issue with Ubuntu 22.04 and this answer still works. – Dan Nissenbaum Jan 22 '23 at 21:12
  • I can confirm this works on Ubuntu Server 22.04.2 "LTS" – errorprone Mar 07 '23 at 17:31
  • It indeed works under Ubuntu 22.04. But strange it's still not solved by default when using LVM – Melroy van den Berg Mar 29 '23 at 21:58
  • thanks for this answer, but i want to increase almost like 200 gb my total disk size is 426G but my /dev/mapper/ubuntu--vg-ubuntu--lv size is 61g. – nihal malik Jul 13 '23 at 07:24
6

This is still relevant today. Ubuntu 22.04.

Example of fix:

example of fix

It's absolutely ridiculous that this isn't the default behavior. Of course I want my 2TB drive

Commands below for copying and pasting without the failed commands. :)

ssh user@ipaddress
cd ~
df 

(Note the drive: /dev/mapper/ubuntu--vg-ubuntu--lv)

Escalate privilages into lvm:

sudo lvm

Run LV Extend:

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Now exit:

exit

Then resize:

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

New found free space visualized:

df -h
defcon
  • 61
5

Expected behavior on an LVM install is indeed the smaller partitions. The system creates minimal space waste on physical partition creation expecting you to customize and expand the LVM as needed, since the added partitions aren't necessary to the operating systems function, and users having additional storage space, quotas, and expansion is the point of having an on-the-fly expandable LV and VG

What it should do, however, is explain that better on install

Steve
  • 51
3

It appears that you need to extend your Logical Volume.

It can be a bit tricky but if you understand that there are 3 parts, it'll be much easier.

  • Physical Volume (PV) => The physical space on a drive.

  • Volume Group (VG) => An abstracted amount of drive space that can be split between multiple drives/devices.

  • Logical Volume (LV) => The space that ubuntu "sees"

You'll need to extend your VG all the way across your 1TB Drive (or extend however much you want), then extend the Logical Volume group to take up that space.

Technet has a nice writeup that (if you follow carefully) you'll be able to follow and extend your drive.

Andy
  • 131