Booting

lsblk                        # list block devices and partitions
fdisk -l                     # list partition table details
mount /dev/sda1 /mnt         # mount partition to a directory
parted
sfdisk????
  • logical formatting (creation of filesystem)
  • fragmentation
  • efibootmgr
  • bcdedit
  • bcfg
  • vmlinuz
  • enable boot logs
  • changing kernel parameter during booting
    • init=/bin/bash (Reset Password): Bypasses the entire boot process and drops you directly into a root shell. This allows you to reset your password if you ever forget it.
    • text or 3 (Boot to TTY/Console): Bypasses your graphical desktop login screen completely and boots directly into a raw text terminal (tty1). This would have saved you from the chvt 8 lockup earlier!
    • nomodeset (Fix Black Screen): Disables video driver loading until the GUI starts. This is a lifesaver if your display server is glitching or throwing black screen errors.
    • systemd.unit=multi-user.target: Another clean way to boot strictly into text mode without loading the GUI.

Mounting and Unmounting

  • Mounting allows device to interact with the OS
    • Attach device to the filesystem tree
    • Always use an empty folder for mounting
  • Unmounting allows device to be safely detached from the filesystem tree
    • Flushes remaining data cached in RAM down to the storage media before removal
    • If a folder or any file inside Mount folder is being used by a process, the system will block the unmount and throw a target is busy error
mount -t vfat /dev/sdc /mnt/flash
umount /dev/sdc

Find process using the mounted folder

# find all open instances of directory and
# all the files and directories it contains to its complete depth
sudo lsof +D /mnt/flash
 
# using fuser utility
sudo fuser -v /mnt/flash

/dev vs /mnt vs /media

  • /dev (Devices)
    • Houses device nodes or special file descriptors generated dynamically by the Linux kernel layer
    • These are not the mount points
    • They act as interface endpoints pointing directly to raw hardware components
  • /mnt (Mount Points)
    • Manually or temporarily mounted filesystems
  • /media (Removable Media)
    • Managed automatically by desktop environment background daemons
      • These daemons are completely absent in Linux server
      • Examples:
        • udisksd (System daemon)
        • gvfs (User session daemon)
    • Mounted dynamically when external plug-and-play devices are inserted
    • Mounted directories are automatically visible in your GUI file manager
    • The OS automatically deletes the subfolder when you safely click “Eject” on your desktop environment

Internal Process of mounting

[ Physical USB Drive ] 
          ↓ (Hardware connection)
[ Linux Kernel ] ----- Creates device node at /dev/sdb1
          ↓ (Signals the event)
[ udisksd (Daemon) ] ----- Automated mount to /media/user/MyUSB
          ↓ (Signals the desktop environment)
[ gvfs (Virtual FS) ] -----  Translates the mount into a GUI object
          ↓ (Pops up on screen)
[ File Explorer Sidebar ] ----- "MyUSB Drive" appears with an Eject button 

View list of mounted filesystems

# modern way
findmnt
 
# only show block devices
lsblk -f
 
# legacy way
mount

Filesystem table

  • Stored at /etc/fstab
  • Lists the devices that are to be mounted at boot time
  • Format
    • Filesystem
      • Block special device, Remote Filesystem, Filesystem Image for loop device
      • Always prefer LABEL= or UUID= or similar instead of /dev/sdb since the devices can be dynamically reassigned upon reboot
      • Virtual FS
        • tmpfs, sysfs etc.
      • MBR
        • UUID=...
        • LABEL=... (stored in Filesystem)
      • GPT (GUID Partition Table)
        • PARTUUID=...
        • PARTLABEL=... (stored in partition entry)
      • NFS
        • <host>:<dir>
      • Filesystem Image
        • /path/to/img
    • Mount point
    • Filesystem type
    • Options: For example, Read only
    • Dump: Sets binary flags (0 or 1) for the legacy dump backup tool
      • Should always be set to 0 in modern Linux
    • Pass: Sets the integrity test boot sequence
      • Order in which filesystems should be checked with the fsck command.
      • 0 skips
      • 1 targets root
      • 2 checks secondary
# <file system>      <mount point>    <type>      <options>       <dump>  <pass>
UUID=c6c8...316          /             ext4    errors=remount-ro    0       1
UUID=e8f3...442          none          swap    sw                   0       0
LABEL=/boot              /boot         ext4    defaults             0       0
sysfs                    /sys          sysfs   defaults             0       0
knuth.aeb.nl:/           /mnt/remote   nfs     defaults,nofail...   0       0
/home/user/disk.img      /mnt/image    ext4    loop,nofail          0       0
PARTUUID=55...00         /mnt/gpt_part ext4    defaults             0       2
PARTLABEL=DataPartition  /mnt/data     ext4    defaults             0       2
  • Reload config
systemctl daemon-reload
  • Get unique identifier for the partitions
# without sudo gives empty output
sudo blkid

Debugging

  • You can look into logs when a device is inserted
  • You can see how the removable device is named
sudo journalctl -f

Manipulating Partitions

parted

GParted

mkfs