Skip to content

Instantly share code, notes, and snippets.

@ngoc-minh-do
Created June 27, 2025 02:42
Show Gist options
  • Select an option

  • Save ngoc-minh-do/c5c17c1ee41cd90cabe355af61baa99b to your computer and use it in GitHub Desktop.

Select an option

Save ngoc-minh-do/c5c17c1ee41cd90cabe355af61baa99b to your computer and use it in GitHub Desktop.

Debian disk

Get size of all files/directories in current directory

du -h --max-depth=1

πŸ“Š Check Disk Usage and Partition Info

Use the following commands to view disk space, partitions, and layouts:

df -hT        # View disk usage with filesystem types 
lsblk         # List block devices 
fdisk -lu     # Detailed partition table (MBR) 
sfdisk -l     # Alternative partition listing

πŸ” Swap Partition Management

βœ… Enable a Swap Partition

  1. Create the Swap Partition using parted:
parted > unit s              # Use sectors for units 
> print free          # Show available space 
> mkpart primary swap-partition <start-sector>s 100%
  1. Initialize the Swap Area:
swapon /dev/sdaX
  1. Enable the Swap:
swapon /dev/sdaX
  1. Verify Swap Status:
swapon --show
  1. Make Swap Permanent:
  • Get the UUID of the swap partition:
blkid
  • Edit /etc/fstab and add:
`UUID=<swap-partition-uuid> none swap sw 0 0`

🚫 Disable a Swap Partition

  1. Turn Off the Swap:
swapoff /dev/sdX
  1. Verify:
swapon --show
  1. Delete the Partition:
parted
> print free
> rm <partition-number>`

⬆️ Extend a Partition

  1. Resize with parted:
parted 
> print free 
> resizepart <partition-number> 100%
  1. Resize the filesystem inside the partition
resize2fs /dev/sdX
  1. Verify
df -h

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment