Score:0

How do I make sure I'm utilizing all of my hard drive?

cn flag

I installed Ubuntu Server 20.04 on an old PC of mine which has a Terabyte of storage on its hard drive. I planned to make this into a home media server, but I'm concerned about my disk space. I believe I chose LVM partitioning by accident when I installed, so my sudo df -h shows /dev/mapper/ubuntu--vg-ubuntu--lv as my main partition mounted on "/".

Filesystem                         Size  Used Avail Use% Mounted on
udev                               2.8G     0  2.8G   0% /dev
tmpfs                              570M  1.8M  568M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  196G  113G   74G  61% /
tmpfs                              2.8G     0  2.8G   0% /dev/shm
tmpfs                              5.0M  4.0K  5.0M   1% /run/lock
tmpfs                              2.8G     0  2.8G   0% /sys/fs/cgroup
/dev/sda2                          976M  298M  611M  33% /boot
/dev/loop2                          70M   70M     0 100% /snap/lxd/19188
/dev/loop1                          56M   56M     0 100% /snap/core18/2074
/dev/loop3                          68M   68M     0 100% /snap/lxd/20326
/dev/loop0                          56M   56M     0 100% /snap/core18/2066
/dev/loop5                          32M   32M     0 100% /snap/snapd/10707
/dev/loop4                          33M   33M     0 100% /snap/snapd/12159
overlay                            196G  113G   74G  61% /var/lib/docker/overlay2/099cc8dee5efe66386fdad846cbc028cd7f74f961698b4378dff88e184985584/merged
overlay                            196G  113G   74G  61% /var/lib/docker/overlay2/af47d3da6cd00707ef1971ef0f6fb8a90d239288da2748d8bacdd771067228bb/merged
overlay                            196G  113G   74G  61% /var/lib/docker/overlay2/3584ebdf079771abe86c7d2e282d9bf46e87965517615c2004c67df81bdae96d/merged
overlay                            196G  113G   74G  61% /var/lib/docker/overlay2/089c653433adb03e55fe57a4de5dd1c93fde717d6691e4cc22d03b92a7b5ab32/merged
overlay                            196G  113G   74G  61% /var/lib/docker/overlay2/be5b851448bc9288b7afa58b520a0287c5a2ac1851c41c572695e8920b7791b4/merged
tmpfs                              570M  4.0K  570M   1% /run/user/1000

This is part of the output of sudo fdisk -l:


Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC WD10EADS-65M
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: 2249399A-6905-4681-AA84-3DFB8B43241D

Device       Start        End    Sectors   Size Type
/dev/sda1     2048       4095       2048     1M BIOS boot
/dev/sda2     4096    2101247    2097152     1G Linux filesystem
/dev/sda3  2101248 1953521663 1951420416 930.5G Linux filesystem




Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

There are only 200 gigabytes on this partition according to df. I don't know much about LVM partitioning, but how can I make sure my "/" partition is using all of the available space on the hard drive? Or maybe just my media directory?

paladin avatar
kr flag
Here is a good tutorial about lvm: https://www.2daygeek.com/create-lvm-storage-logical-volume-manager-in-linux/
Nmath avatar
ng flag
In addition to the answer below, before you reinstall the OS, you should format your hard drive using the GPT partition scheme instead of BIOS/MBR
Score:1
cn flag
raj

If reinstall is an option for you, probably the easiest way would be to reinstall the system without using LVM.

If you can't reinstall, the the following commands may help you investigate what's going on.

LVM operates on three "layers" of objects. The bottom layer are the physical volumes (probably you have only one, as you have only one usable partition). Physical volumes are - in short - partitions or whole disks that will be used for LVM. The command sudo pvs will list the physical volumes defined on your system. Here is a sample output:

PV         VG       Fmt  Attr PSize   PFree
/dev/sda1  vg_xymon lvm2 a--  135.97g    0
/dev/sdb2  vg_xymon lvm2 a--  136.17g    0

We can see there are two physical volumes (partitions), on two different disks - /dev/sda1 and /dev/sdb2. Their sizes are shown and the "VG" column indicates that they are both assigned to a volume group called vg_xymon.

Volume groups are an intermediate layer between physical and logical volumes, which allow eg. for a logical volume to span multiple physical volumes. There is usually only one volume group in the system. You can display information about volume groups with the command sudo vgs. Again, sample of the output:

VG       #PV #LV #SN Attr   VSize   VFree
vg_xymon   2   3   0 wz--n- 272.14g    0

We can see that the volume group spans two physical volumes (shown previously), so the volume group size is equal to sum of their sizes (In your case, both the physical volume size and the volume group size should be equal to the size of your partition - if not, then something is really, really wrong). We can also see that there are 3 logical volumes defined within this volume group.

Logical volumes are the top layer - these are places where your filesystems are actually located. Your /dev/mapper/ubuntu--vg-ubuntu--lv device is a logical volume. The last component of the path is a combination of the volume grup name, dash, and a logical volume name. So your logical volume is called ubuntu--lv and belongs to volume group ubuntu--vg.

And one more command, sudo lvs, displays information about logical volumes:

LV      VG       Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
lv_home vg_xymon -wi-ao--- 218.28g
lv_root vg_xymon -wi-ao---  50.00g
lv_swap vg_xymon -wi-ao---   3.86g

(so the first one in this example will be visible as device /dev/mapper/vg_xymon-lv_home). Probably your problem lies here, ie. the logical volume is smaller than your volume group and the rest of the space in the volume group is unallocated.

In that case, you can extend it to fill the entire volume group with the command:

sudo lvextend -r /dev/mapper/ubuntu--vg-ubuntu--lv

However, because your root filesystem is mounted on that logical volume, extending it from the installed system may be impossible and you may need to boot from the install media to do it. In that case maybe it will be better to create an additional logical volume that uses the rest of the space on the volume group and mount it onto your media directory, while keeping your root filesystem unchanged:

sudo lvcreate -l 100%FREE -n media ubuntu--vg

This will create a new logical volume media in existing volume group ubuntu--vg (so the device path will be /dev/mapper/ubuntu--vg-media), using 100% free space in the volume group.

Then you have to format the newly created logical volume:

sudo mkfs /dev/mapper/ubuntu--vg-media

and finally mount it onto your /media directory (or whatever it is called, you must create the empty directory first):

sudo mount /dev/mapper/ubuntu--vg-media /media

If you want this mount to be persistent ie. that you don't need to repeat the above sudo mount command everytime you boot your system, you need to edit your /etc/fstab file (sudo gedit /etc/fstab) and add the following line to it:

/dev/mapper/ubuntu--vg-media  /home  ext4  defaults  0  2

(assuming your filesystem is ext4, use the same value that is used in the line specifying your / filesystem).

ZackT avatar
cn flag
Thanks for the reply. I have a few questions though. I checked with the commands, and the logical volume is smaller than the group. Before I try to extend it through an ssh connection, how would I do this from the install media? Do I need to format a usb with an Ubuntu server iso? I could create a new logical volume for the media folder, but I already have a few large media files on my directory (I'm using plex on docker for this specific directory). Should I just move the files out of the directory then create/mount the new LV and move them back? Thanks for the help
raj avatar
cn flag
raj
@ZackT yes, you need an USB with the install media, basically the same that you used to install your system. Then boot in "live" mode (without system installation) to perform the operation. As for the media directory, you need an empty directory to mount a new device over it, so you should move out your files. You could temporarily mount the new LV on a temporary directory like `/media-temp`, move the files there, unmount and mount again on your proper media dir - the files will be already there. Then you can remove empty `/media-temp`. This way you will need to move files only once.
ZackT avatar
cn flag
I decided to make a new media partition, and I ran into an error while I ran that command you put. `WARNING: atari signature detected on /dev/ubuntu-vg/media at offset 454. Wipe it [y/n]?` What should I do? I'm not sure if typing no backs out of the operation. EDIT: nevermind, I saw what it means. I'll be wiping it.
ZackT avatar
cn flag
I've made a new partition, moved the files to it, mounted it to the proper location, and now all my services are working again with the proper amount of space. Thank you.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.