Hard drives and the filesystems that are used on them are essential for computers, they hold the operating system that boots the computer and our much valued files be that work, music, videos or pictures. # Labelling Disks The structure of `/etc/fstab`, which defines what partitions/disks can be mounted, is such that you can use [[wp>BSD_disklabel|disklabels]] (which are not unique to BSD) to refer to the partition/disk you wish to mount. You can use [[wp>UUID|UUID]] but whilst these are long and unique they can be a pain to remember. ## Labelling a Disk Under GNU/Linux its easy to manipulate the label of any given disk partition using ''e2label''. First you need to know the device filename, if its an internal drive then you can access this by looking at the output of `fdisk -l` which will list all of the partitions on all internal drives. If its an external device such as (micro-)SD card USB flash drive or external USB drive then you should use `dmesg | grep dev` to look for the device after you attach it. Assuming your device is `/dev/sdf1` then you can label it (as `root`) using... ```bash e2label /dev/sdf1 "my-custom-label" exfatlabel /dev/sdf1 "another-custom-label" ## If the filesystem is DOS/NTFS ``` Confirm that it worked by looking in `/dev/disk/by-label/`... ```bash ls -l /dev/disk/by-label/ | grep sdf lrwxrwxrwx 1 root root 10 Dec 16 08:11 my-custom-label -> ../../sdf1 ``` ## Using Disk Labels to mount drives You can now use an entry in ''/etc/fstab'' using this label... ```bash LABEL=my-custom-label /mnt/my-flash-drive auto noauto,rw,users 0 0 ``` ## Resizing LVM filesystems [[wp>logical_volume_management|Logical Volume Management (LVM)]] is not the same thing as [[wp>disk_partitioning|partitioning]] your hard drive, its is much more flexible and allows relatively painless resizing (unless you cock-up as I [once did](https://forums.gentoo.org/viewtopic-t-1073814-highlight-.html)). ## Extend your partitions and filesystems Its now dead easy to expand your partitions on the fly, although in order to use the space you _must_ extend the filesystem after extending the partition. The following adds 50Gb to the pics partition... ```bash umount /mnt/pics e2fsck -f /dev/vg0/pics lvextend -L+50G /dev/vg0/pics Extending logical volume pics to 300.00 GiB Logical volume pics successfully resized resize2fs /dev/vg0/pics ``` ## Reducing your partitions and filesystems ```bash umount /mnt/pics e2fsck -f /dev/vg0/pics resize2fs /dev/vg0/pics 200G lvreduce -L200G /dev/vg0/pics ``` Some advice on determining sizes can be found [here](https://unix.stackexchange.com/questions/41088/how-do-i-determine-the-new-size-for-resize2fs). # Recovering Disk Space Saw a [tweet from @climagic](https://twitter.com/climagic/status/1469033227897745419) that ext files systems reserve 5% of disc space for the `root` user and that you can recover it using by reducing the percentage using... ```bash tune2fs -m2 /dev/sda1 ``` # Links {{tag>linux,howto,hardware,disks,storage,filesystems}}