1. how to fix a broken filesystem
  2. Use the following (mutatis mutandis for the filesystem type):

    sudo fsck.ext4 -y /dev/sda[NUMBER]
    source

    To understand what can cause a filesystem to become broken see here.

  3. how to detach a busy device immediately
  4. sudo umount -l /media/usb
    source
  5. how to find the filesystem of a thumb drive (not mounted)
  6. sudo blkid /dev/sdc1
    source
  7. how to label a FAT32 file system
  8. In April 2018 to label a FAT32 file system on a USB flash drive I did:

    sudo fatlabel /dev/sdb1 LEXR16GWHIT
    … and it worked like a charm.

    Note however, that there should be no filesystem mounted on that device otherwise you get:

    $ sudo fatlabel /dev/sdb1 LEXR16GWHIT
    0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
     Automatically removing dirty bit.

  9. show labels of mounted filesystems
  10. sudo lsblk -o name,mountpoint,label,size,uuid
    I also think that sudo lsblk alone suffices.
  11. how to find information on how many times a disk had gone through a shutdown / powerup cycle
  12. sudo apt-get install smartmontools
    sudo sudo smartctl -a /dev/sda1

    The Start_Stop_Count and Power_Cycle_Count seem relevant. In my T60 ThinkPad (6 years old) they have a value around 2300.

    Alternatively, you can grep for all pertinent Old_age metrics:

    sudo sudo smartctl -a /dev/sda1 | grep -i old_age

  13. how to find filesystem information on all devices
  14. This only shows mounted filesystems:

    df -Th
    T for the filesystem information, h for human-readable.

    The below provides way more / complementary information on the filesystem (and also works on unmounted devices):

    sudo file -sL /dev/sda1
    In particular, in my system file -sL properly reports FAT (32 bit) whereas df -Th simply reports vfat which is not technically correct as FAT32 is an extension of both FAT and VFAT (and enhances both)

  15. how to find the filesystem that a given path is mounted on
  16. df -P -T /some/path
    If you just want the type of the filesystem:
    df -P -T /some/path | tail -n +2 | awk '{print $2}'
  17. how to mount a new disk
    1. Recognize the new device
    2. This can be done in two ways:
      1. using the lsblk program
      2. In the typical output of this program:

        ... it is easy to see which devices are mounted (i.e. don't have a MOUNTPOINT value. E.g. in the example above that's the device sdb.
      3. using sudo fdisk -l
      4. This option shows all disks but does not show which ones are not mounted (but that may be guessed):
        $ sudo fdisk -l
        
        Disk /dev/sda: 250.1 GB, 250059350016 bytes
        255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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
        Disk identifier: 0x0007fe8d
        
           Device Boot      Start         End      Blocks   Id  System
        /dev/sda1   *        2048   482142207   241070080   83  Linux
        /dev/sda2       482144254   488396799     3126273    5  Extended
        /dev/sda5       482144256   488396799     3126272   82  Linux swap / Solaris
        
        WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
        
        
        Disk /dev/sdb: 2000.4 GB, 2000365289472 bytes
        255 heads, 63 sectors/track, 243197 cylinders, total 3906963456 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
        Disk identifier: 0xa29ef612
        
           Device Boot      Start         End      Blocks   Id  System
        /dev/sdb1               1  3906963455  1953481727+  ee  GPT
                  
      5. if the disk is labelled, lists disks by label
      6. $ ls /dev/disk/by-label/
        total 0
        drwxr-xr-x 2 root root  60 Nov 16 10:34 ./
        drwxr-xr-x 6 root root 120 Nov 16 10:34 ../
        lrwxrwxrwx 1 root root   9 Nov 16 10:34 transc-usb-disk -> ../../sdb
                  
    3. verify that the device name we identified is indeed not mounted
    4. $mount | grep sdb
      $
              
    5. identify the file-system of that device
      sudo lshw  | grep -A20 -B30  sdb
      (... output ommited)
              
      … if the above produces output that's not very helpful try using sudo blkid (see here for more)
    6. mount said device with the correct filesystem type (as discovered in the previous step)
    7. create before doing that, the directory corresponding to the mount point - in our case /media/usb-disk
       sudo mount -t ext3 /dev/sdb2 /media/usb-disk
              
  18. procedure to automatically mount a new filesystem in Ubuntu
    1. get the UUID of the device in question:
    2. sudo blkid
    3. get the user and group of the id of the user who'll be the owner of the files on the mounted filesystem using the id command.
    4. add a line at the end of the /etc/fstab file. E.g.
    5. UUID=e6daad35-1f57-4281-8683-a03c20cfc5a3 /media/Elements ext4 defaults,uid=1000,gid=1000,umask=007
              
  19. Taking snapshots in a ZFS filesystem
  20. In a ZFS filesystem there is no need to use the custom script that rotates backups relying on a combination of cp -al and rsync. rsync alone is enough together with a ZFS pool, e.g. named 'backups' as in:
    rsync -avx --delete --in-place /whatever /mnt/zfs
    zfs snapshot backups@20120925
          
  21. Find the UUID of a drive in Ubuntu precise
  22. To find the drives:
    sudo fdisk -l 
    and then you do a:
    sudo blkid /dev/sdb1
    where, in the above example, /dev/sdb1 is the device we're interested in.
  23. Deep compare two file hierarchies
  24. Either use meld or, from command line:
    diff -qr a b | sort
          
  25. How to find mounted file systems and mount a new one
  26. The following history shows how to do it:
     757  fdisk -l
     758  sudo fdisk -l
     759  clear
     760  sudo fdisk -l
     761  df -l
     762  sudo mount /dev/sdb1 /media/Elements/
     763  df
     764  df -h