File system reminder

Français   |   Source

As I am not manipulating file system everyday, I tend to forget the useful commands, hence this reminder.

Discs and filesystem

Here are some useful commands to manage your discs and filesystems:

  • less /etc/mtab gives information about the filesystems currently mounted
  • less /etc/fstab gives a list of available discs and partitions; in particular, you'll find in this file discs ids (uuid) linked to filesystems (/dev/sda or /dev/hda (/dev/sd being for SCSI and SATA discs whereas /dev/hd stand for IDE discs))
  • ls /dev/disk/by-uuid gives disc ids list
  • sudo dumpe2fs /dev/sda1 provides lots of information about the given filesystem
  • sudo fdisk -l gives information as in /etc/mtab and /etc/fstab

Reduce reserved space

By default, 5% of your disk space is dedicated to priority processes and root's /home. If it made sense on older machines with smaller discs, it becomes anoying now we have bigger ones. To reduce this reserved space is therefore very convenient, and very simple with tune2fs, specifying the percentage of your disc you want to reserve:

tune2fs -m 1 /dev/[partition]

Corrupted superblock

fsck can be used to check and fix a broken filesystem, and mke2fs can be used to create a filesystem; -j option is for ext3:

fsck
mke2fs -j -S /dev/[partition]
fsck

Restore a broken filesystem on a USB stick

sudo /sbin/dosfsck -altrvV /dev/[partition]

Clean-up a partition

dd if=/dev/urandom of=/dev/<partition> bs=4096 status=progress