Créer et gérer des périphériques de stockage, des partitions, des systèmes de fichiers et des espaces d’échange à partir de la ligne de commande.
Systèmes de fichiers
Accéder au contenu des systèmes de fichiers en ajoutant et en supprimant des systèmes de fichiers à la hiérarchie des systèmes de fichiers.
Détails sur les partitions :
# lsblk -fp
Information sur les partitions :
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS [...] sdb 8:16 0 5G 0 disk
Partitionner, formater, monter
Créer des partitions de stockage, les formater avec des systèmes de fichiers et les monter pour les utiliser.
# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.37.4). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xbfc09245.
Command (m for help): g Created a new GPT disklabel (GUID: EEC04E38-2ED6-D447-B84C-7831139192AE).
Command (m for help): n Partition number (1-128, default 1): First sector (2048-10485726, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485726, default 10485726): +2G
Created a new partition 1 of type 'Linux filesystem' and of size 2 GiB.
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Vérification avec lsblk :
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS [...] sdc 8:32 0 5G 0 disk └─sdc1 8:33 0 2G 0 part
Création du système de fichier ext4 sur la partition /dev/sdc1 :
# mkfs.ext4 /dev/sdc1
mke2fs 1.46.5 (30-Dec-2021) Creating filesystem with 524288 4k blocks and 131072 inodes Filesystem UUID: 2c671b9e-7851-4bd4-8df1-49edb6a93769 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
Labéliser la partition 1 avec parted :
# parted /dev/sdc
(parted) name 1 BACKUP
Vérification :
# parted /dev/sdc print
[...] Number Start End Size File system Name Flags 1 1049kB 2149MB 2147MB ext4 BACKUP
⚠️ Pour que le système détecte la nouvelle partition et crée le fichier de périphérique /dev/sdc1 :
# partprobe /dev/sdc1 # udevadm settle
Création d’un espace (un répertoire) :
# mkdir -p /home/BACKUP_Users
Montage de la partition sur le nouveau répertoire :
# mount /dev/sdc1 /home/BACKUP_Users/
Vérification :
# mount | grep BACKUP
/dev/sdc1 on /home/BACKUP_Users type ext4 (rw,relatime,seclabel)
⚠️ Forcez le daemon systemd à relire le fichier /etc/fstab :
# systemctl daemon-reload
Le Swap
Créer et gérer des espaces d’échange pour compléter la mémoire physique.
Création de 2 partitions swap :
# fdisk /dev/sdc
[...] Command (m for help): n Partition number (2-128, default 2): First sector (4196352-10485726, default 4196352): Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-10485726, default 10485726): +512M
Created a new partition 2 of type 'Linux filesystem' and of size 512 MiB.
Command (m for help): n Partition number (3-128, default 3): First sector (5244928-10485726, default 5244928): Last sector, +/-sectors or +/-size{K,M,G,T,P} (5244928-10485726, default 10485726): +512M
Created a new partition 3 of type 'Linux filesystem' and of size 512 MiB.
Command (m for help): t Partition number (1-3, default 3): 2 Partition type or alias (type L to list all): Linux Swap
Changed type of partition 'Linux filesystem' to 'Linux swap'.
Command (m for help): t Partition number (1-3, default 3): 3 Partition type or alias (type L to list all): Linux swap
Changed type of partition 'Linux filesystem' to 'Linux swap'.
Command (m for help): w The partition table has been altered. Syncing disks.
Labelisation des swap avec parted :
# parted /dev/sdc
[...] (parted) name 2 SWAP1 (parted) name 3 SWAP2 (parted) q
Vérification :
# parted /dev/sdc print
[...] Number Start End Size File system Name Flags 1 1049kB 2149MB 2147MB ext4 BACKUP 2 2149MB 2685MB 537MB SWAP1 swap 3 2685MB 3222MB 537MB SWAP2 swap
⚠️ Pour que le système détecte les nouvelles partitions et crée les fichiers de périphérique :