# Debian Disk and Filesystems Manage storage: partitions, formatting, mounting, and monitoring disk usage. ## Listing Disks and Partitions ```bash lsblk lsblk -f # show filesystems ``` Show device details: ```bash fdisk -l parted -l ``` ## Partitioning Interactive partition editor: ```bash sudo cfdisk /dev/sda ``` Or `fdisk` (older, text-based): ```bash sudo fdisk /dev/sda ``` Or `parted` (supports GPT): ```bash sudo parted /dev/sda ``` After partitioning, reread partition table: ```bash sudo partprobe /dev/sda ``` ## Formatting Filesystems Create ext4 filesystem (most common): ```bash sudo mkfs.ext4 /dev/sda1 ``` Other options: - `mkfs.ext3` — older, journaled - `mkfs.xfs` — high-performance - `mkfs.btrfs` — modern with snapshots - `mkfs.vfat` — FAT32 (USB drives) ## Mounting Mount filesystem (temporary): ```bash sudo mount /dev/sda1 /mnt sudo umount /mnt ``` List mounted filesystems: ```bash mount df -h ``` ## Persistent Mounts Edit `/etc/fstab`: ``` /dev/sda1 /home ext4 defaults 0 2 ``` Format: `device mount-point filesystem options dump fsck-order` - `options` — usually `defaults`, or comma-separated: `noatime`, `nodiratime`, `noexec` - `dump` — 0 to skip, 1 to include in dumps - `fsck-order` — 0 to skip, 1 for root, 2 for others Test before applying: ```bash sudo mount -a ``` ## Disk Usage Show usage per filesystem: ```bash df -h ``` Show directory size: ```bash du -sh /path/to/dir du -sh /path/to/dir/* ``` Find large files: ```bash find / -type f -size +1G ``` ## Filesystem Types - **ext4** — reliable, default on Debian - **xfs** — high-performance, used on servers - **btrfs** — modern, supports snapshots and RAID - **vfat** — FAT32, USB drives, Windows-compatible - **ntfs** — Windows filesystems (limited support) ## Checking Filesystems Check for errors (unmounted only): ```bash sudo fsck /dev/sda1 sudo e2fsck -n /dev/sda1 # read-only check ``` During boot, systemd runs fsck on damaged filesystems automatically. ## Disk Space Issues If disk is full: ```bash sudo apt autoremove sudo apt clean sudo journalctl --vacuum=size=100M ``` Monitor space regularly to avoid emergency cleanup.