Périphériques de stockage USB

Cette page documente diverses commandes pour identifier, formater et créer des systèmes de fichiers sur des clés USB ou des disques durs externes avec Debian.

Identification

Identifiez la clé ou le disque externe concerné avec la commande lsblk :

# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 119,2G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0  27,9G  0 part /
├─sda3   8:3    0   977M  0 part [SWAP]
└─sda4   8:4    0  89,8G  0 part /home
sdb      8:32   1   961M  0 disk
└─sdb1   8:33   1   959M  0 part
sr0     11:0    1  1024M  0 rom

Il s'agit ici de /dev/sdb.

Préparation

Supprimez ensuite avec gdisk toute table de partition présente afin de repartir sur des bases saines :

# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.9

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/sdc. Proceed? (Y/N): y

GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y

Toujours avec gdisk, créez une partition 0700 (Microsoft basic data).

# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.9

Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present

Creating new GPT entries in memory.

Command (? for help): n
Partition number (1-128, default 1): [Entrée]
First sector (34-1968094, default = 2048) or {+-}size{KMGTP}: [Entrée]
Last sector (2048-1968094, default = 1966079) or {+-}size{KMGTP}: [Entrée]
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 0700
Changed type of partition to 'Microsoft basic data'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

À ce stade, le périphérique est prêt à être formaté.

Formatage

Le formatage en ExFAT permet d'utiliser son périphérique de stockage USB avec GNU/Linux, Windows et MacOS. Celui en FAT32 peut être utilisé pour la compatibilité avec de plus vieux systèmes.

ExFAT

Installez si besoin le paquet exfatprogs :

# apt install exfatprogs

Créez le système de fichiers ExFAT sur la partition /dev/sdb1 :

# mkfs.exfat -n HERMES /dev/sdb1
exfatprogs version : 1.2.0
Creating exFAT filesystem(/dev/sdb1, cluster size=32768)

Writing volume boot record: done
Writing backup volume boot record: done
Fat table creation: done
Allocation bitmap creation: done
Upcase table creation: done
Writing root directory entry: done
Synchronizing...

exFAT format complete!

FAT32

Installez si besoin le paquet dosfstools :

# apt install dosfstools

Créez le système de fichiers FAT32 sur la partition /dev/sdb1 :

# mkfs.vfat -n FAT32 /dev/sdb1