Skip to main content

Storage management


Table of contents

  1. Disks and partitions
  2. lsblk, fdisk, parted
  3. Mounting and unmounting
  4. /etc/fstab: automatic mounting
  5. Introduction to LVM
  6. Hands-on exercises


1 - Disks and partitions

Disk naming

TypeNameExample
SATA/SCSI/dev/sd[a-z]/dev/sda, /dev/sdb
NVMe/dev/nvme[0-9]n[1-9]/dev/nvme0n1
Virtual/dev/vd[a-z]/dev/vda
IDE (old)/dev/hd[a-z]/dev/hda

Partitions

/dev/sda      ← Disque entier
├── /dev/sda1 ← Partition 1
├── /dev/sda2 ← Partition 2
└── /dev/sda3 ← Partition 3

Partition tables

TypeMax partitionsMax sizeUsage
MBR4 primary (or 3 + extended)2 TBLegacy/BIOS
GPT1289.4 ZBModern/UEFI
tip

Always use GPT for new systems, unless you have compatibility constraints.

🔝 Back to table of contents



2 - lsblk, fdisk, parted

lsblk - List block devices

# Affichage simple
lsblk

# Avec système de fichiers
lsblk -f

# Avec tailles
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE

Typical output:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 50G 0 part /
├─sda2 8:2 0 48G 0 part /home
└─sda3 8:3 0 2G 0 part [SWAP]

fdisk - MBR/GPT partitioning

# Voir les partitions
sudo fdisk -l

# Voir un disque spécifique
sudo fdisk -l /dev/sda

# Mode interactif (ATTENTION !)
sudo fdisk /dev/sdb

Interactive fdisk commands:

CommandAction
mHelp
pDisplay the table
nNew partition
dDelete a partition
tChange the type
wWrite and quit
qQuit without saving

parted - Advanced partitioning

# Mode interactif
sudo parted /dev/sdb

# Créer une table GPT
sudo parted /dev/sdb mklabel gpt

# Créer une partition
sudo parted /dev/sdb mkpart primary ext4 0% 100%

# Afficher les partitions
sudo parted /dev/sdb print

Format a partition

# ext4 (standard Linux)
sudo mkfs.ext4 /dev/sdb1

# xfs
sudo mkfs.xfs /dev/sdb1

# Swap
sudo mkswap /dev/sdb2
sudo swapon /dev/sdb2
danger

Partitioning operations are destructive! Make sure you are working on the right disk.

🔝 Back to table of contents



3 - Mounting and unmounting

The concept of mounting

mount - Mount a partition

# Créer un point de montage
sudo mkdir -p /mnt/data

# Monter
sudo mount /dev/sdb1 /mnt/data

# Monter avec options
sudo mount -o ro /dev/sdb1 /mnt/data # Lecture seule
sudo mount -o rw,noexec /dev/sdb1 /mnt/data

# Vérifier
mount | grep sdb1
df -h /mnt/data

umount - Unmount

# Démonter
sudo umount /mnt/data
# ou
sudo umount /dev/sdb1

# Forcer le démontage (si occupé)
sudo umount -l /mnt/data # Lazy unmount
sudo umount -f /mnt/data # Force

Check what is using a mount point

# Processus utilisant le montage
sudo lsof /mnt/data

# Ou avec fuser
sudo fuser -mv /mnt/data

Common mount options

OptionDescription
roRead only
rwRead-write
noexecNo binary execution
nosuidIgnore SUID/SGID
nodevIgnore device files
defaultsrw,suid,dev,exec,auto,nouser,async

🔝 Back to table of contents



4 - /etc/fstab: automatic mounting

Structure of /etc/fstab

# <device>        <mount point>  <type>  <options>       <dump> <pass>
/dev/sda1 / ext4 defaults 0 1
/dev/sda2 /home ext4 defaults 0 2
/dev/sda3 none swap sw 0 0
UUID=abc123... /mnt/data ext4 defaults,nofail 0 2
FieldDescription
1Device (device or UUID)
2Mount point
3Filesystem type
4Mount options
5dump (0 = no backup)
6fsck order (0 = no check, 1 = root, 2 = others)
# Trouver l'UUID
sudo blkid /dev/sdb1
# /dev/sdb1: UUID="abc12345-..." TYPE="ext4"

# Ou
lsblk -f

Add an entry to fstab

# 1. Trouver l'UUID
UUID=$(sudo blkid -s UUID -o value /dev/sdb1)

# 2. Éditer fstab
sudo nano /etc/fstab

# 3. Ajouter la ligne
# UUID=abc12345... /mnt/data ext4 defaults,nofail 0 2

# 4. Tester (monte tout ce qui n'est pas monté)
sudo mount -a

# 5. Vérifier
df -h /mnt/data

The nofail option

UUID=abc123... /mnt/data ext4 defaults,nofail 0 2
warning

Add nofail for external/optional disks. Without this option, the system will not boot if the disk is absent!

🔝 Back to table of contents



5 - Introduction to LVM

What is LVM?

LVM (Logical Volume Manager) adds a layer of abstraction between physical disks and file systems.

Advantages of LVM

AdvantageDescription
ResizingGrow/shrink on the fly
SnapshotsInstant backups
StripingMulti-disk performance
MigrationMove data between disks

LVM concepts

TermAbbreviationDescription
Physical VolumePVPhysical disk or partition
Volume GroupVGStorage pool
Logical VolumeLVVirtual "partition"

Basic commands

# === Physical Volumes ===
# Créer un PV
sudo pvcreate /dev/sdb

# Lister les PV
sudo pvs
sudo pvdisplay

# === Volume Groups ===
# Créer un VG
sudo vgcreate data_vg /dev/sdb

# Ajouter un disque au VG
sudo vgextend data_vg /dev/sdc

# Lister les VG
sudo vgs
sudo vgdisplay

# === Logical Volumes ===
# Créer un LV de 50G
sudo lvcreate -L 50G -n data_lv data_vg

# Créer un LV utilisant 100% de l'espace libre
sudo lvcreate -l 100%FREE -n data_lv data_vg

# Lister les LV
sudo lvs
sudo lvdisplay

Use an LV

# Formater
sudo mkfs.ext4 /dev/data_vg/data_lv

# Monter
sudo mkdir /mnt/data
sudo mount /dev/data_vg/data_lv /mnt/data

# fstab
/dev/data_vg/data_lv /mnt/data ext4 defaults 0 2

Resize an LV

# Agrandir de 10G
sudo lvextend -L +10G /dev/data_vg/data_lv

# Redimensionner le filesystem (ext4)
sudo resize2fs /dev/data_vg/data_lv

# Ou en une commande
sudo lvextend -L +10G -r /dev/data_vg/data_lv

🔝 Back to table of contents



6 - Hands-on exercises

Exercise 1: Explore the storage

# 1. Listez les disques et partitions
lsblk

# 2. Affichez les systèmes de fichiers
lsblk -f

# 3. Vérifiez l'espace
df -h

# 4. Regardez fstab
cat /etc/fstab

Exercise 2: Manual mount (if you have a USB drive)

# 1. Insérez une clé USB
# 2. Identifiez-la
lsblk

# 3. Créez un point de montage
sudo mkdir -p /mnt/usb

# 4. Montez
sudo mount /dev/sdb1 /mnt/usb

# 5. Listez le contenu
ls /mnt/usb

# 6. Démontez
sudo umount /mnt/usb

Quiz

Q1. What is the difference between MBR and GPT?

Answer

MBR: max 4 primary partitions, 2 TB max, legacy BIOS GPT: 128 partitions, enormous capacity, modern UEFI

Q2. Why use UUID rather than /dev/sdX in fstab?

Answer

The /dev/sdX names can change depending on the disk detection order. UUIDs are unique and permanent.

Q3. What does LV mean in LVM?

Answer

Logical Volume - the equivalent of a partition in LVM

🔝 Back to table of contents



Key takeaways

  • SATA disks = /dev/sd*, NVMe = /dev/nvme*
  • lsblk to see the disks, df -h for space
  • Always use UUID in /etc/fstab
  • Add nofail for optional disks
  • LVM allows on-the-fly resizing
  • LVM commands: pv*, vg*, lv* (create, display, extend)

🔝 Back to table of contents


← Previous chapter | Next chapter: Network configuration →