Table of Contents
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 disklabels (which are not unique to BSD) to refer to the partition/disk you wish to mount. You can use 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…
- snippet.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/
…
- snippet.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…
- snippet.bash
LABEL=my-custom-label /mnt/my-flash-drive auto noauto,rw,users 0 0
Resizing LVM filesystems
Logical Volume Management (LVM) is not the same thing as partitioning your hard drive, its is much more flexible and allows relatively painless resizing (unless you cock-up as I once did).
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…
- snippet.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
- snippet.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.
Recovering Disk Space
Saw a tweet from @climagic 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…
- snippet.bash
tune2fs -m2 /dev/sda1
Links
linux,howto,hardware,disks,storage,filesystems