Table des matières

Dernière mise-à-jour : 2020/08/06 15:38

LDF204 - Gestion des Disques, des Systèmes de Fichiers et du Swap

Contenu du Module

  • LDF204 - Gestion des Disques, des Systèmes de Fichiers et du Swap
    • Contenu du Module
    • Périphériques de stockage
    • Partitions
    • Partitionnement
      • LAB #1 - Partitionnement de votre Disque parted
    • Logical Volume Manager (LVM)
      • LAB #2 - Volumes Logiques Linéaires
        • Physical Volume (PV)
        • Volume Group (VG) et Physical Extent (PE)
        • Logical Volumes (LV)
      • LAB #3 - Étendre un Volume Logique à Chaud
      • LAB #4 - Snapshots
      • LAB #5 - Suppression des Volumes
      • LAB #6 - Volumes Logiques en Miroir
      • LAB #7 - Modifier les Attributs LVM
      • LAB #8 - Volumes Logiques en Bandes
      • LAB #9 - Gérer les Métadonnées
    • Systèmes de Fichiers Journalisés
      • Présentation
      • Ext3
        • Gestion d'Ext3
        • LAB #10 - Convertir un Système de Fichiers Ext3 en Ext2
        • LAB #11 - Convertir un Système de Fichiers Ext2 en Ext3
        • LAB #12 - Placer le Journal sur un autre Partition
        • LAB #13 - Modifier la Fréquence de Vérification du Système de Fichiers Ext3
      • Ext4
        • LAB #14 - Créer un Système de Fichiers Ext4
        • LAB #15 - Ajouter une Étiquette au Système de Fichiers Ext4
        • LAB #16 - Convertir un Système de Fichiers Ext3 en Ext4
      • XFS
        • LAB #17 - Créer un Système de Fichiers XFS
        • LAB #18 - Ajouter une Étiquette au Système de Fichiers XFS
      • ReiserFS
        • LAB #19 - Créer un Système de Fichiers ReiserFS
        • LAB #20 - Ajouter une Étiquette au Système de Fichiers ReiserFS
      • JFS
        • LAB #21 - Créer un Système de Fichiers JFS
        • LAB #22 - Ajouter une Étiquette au Système de Fichiers JFS
      • Btrfs
        • LAB #23 - Créer un Système de Fichiers Btrfs
        • LAB #24 - Convertir un Système de Fichiers Ext4 en Brtfs
        • LAB #25 - Créer un Snapshot
        • LAB #26 - Ajouter une Étiquette au Système de Fichiers Btrfs
      • Comparaison des Commandes par Système de Fichiers
    • LAB #27 - Créer un Système de Fichiers ISO
      • La Commande genisoimage
    • Systèmes de Fichiers Chiffrés
      • LAB #28 - Créer un Système de Fichiers Chiffré avec encryptfs
      • LAB #29 - Créer un Système de Fichiers Chiffré avec LUKS
        • Présentation
        • Mise en Place
        • Ajouter une deuxième Passphrase
        • Supprimer une Passphrase
    • Le Swap
      • Taille du swap
      • Partitions de swap
      • La Commande swapon
      • La Commande swapoff
      • LAB #30 - Créer un Fichier de Swap

Périphériques de stockage

Les unités de stockage sous Linux sont référencées par un des fichiers se trouvant dans le répertoire /dev :

  • hd[a-d]
    • Les disques IDE et les lecteurs ATAPI
  • sd[a-z]
    • Les disques SCSI et SATA
  • mmcblk[0-7]
    • Les cartes SD/MMC
  • scd[0-7]
    • Les CDRoms SCSI
  • xd[a-d]
    • Les premiers disques sur IBM XT
  • fd[0-7]
    • Les lecteurs de disquettes
  • st[0-7]
    • Les lecteurs de bandes SCSI/SATA qui supportent le rembobinage
  • nst[0-7]
    • Les lecteurs de bandes SCSI/SATA qui ne supportent pas le rembobinage
  • ht[0-7]
    • Les lecteurs de bandes PATA qui supportent le rembobinage
  • nht[0-7]
    • Les lecteurs de bandes PATA qui ne supportent pas le rembobinage
  • rmt8, rmt16, tape-d, tape-reset
    • Les lecteurs QIC-80
  • ram[0-15]
    • Les disques virtuels. Ils sont supprimés à l'extinction de la machine. Un de ces disques est utilisé par le système pour monter l'image d'un disque racine défini par le fichier initrd au démarrage de la machine
  • Périphériques loop
    • Il existe 16 unités loop qui sont utilisés pour accèder en mode bloc à un système de fichiers contenu dans un fichier, par exemple, une image iso
  • md[x]
    • Un volume RAID logiciel
  • vg[x]
    • Un groupe de volumes
  • lv[x]
    • Un volume logique

Partitions

Un PC comportent en règle générale 2 contrôleurs de disque, chacun capable de gérer 2 disques, un maître et un esclave. Les disques attachés à ces contrôleurs comportent des noms différents pour pouvoir les distinguer :

  • Contrôleur 0
    • Maître
      • hda - disque IDE
      • sda - disque SATA ou SCSI
    • Esclave
      • hdb - disque IDE
      • sdb - disque SATA ou SCSI
  • Contrôleur 1
    • Maître
      • hdc - disque IDE
      • sdc - disque SATA ou SCSI
    • Esclave
      • hdd - disque IDE
      • sdd - disque SATA ou SCSI

Un disque peut comporter trois types de partitions :

  • Partitions primaires,
    • Maximum de 4. En effet, la Table des Partitions est grande de 64 octets. Il faut 16 octets pour codés une partition.
  • Partitions Etendues,
    • Généralement une seule partition étendue par disque. Elle contient des Lecteurs Logiques aussi appelés des partitions,
  • Lecteurs Logiqiques.

Les 4 partitions primaires sont numérotées de 1 à 4. Par exemple :

  • hda1, hda2, hda3 et hda4 pour le premier disque IDE sur le premier contrôleur de disque,
  • sda1, sda2, sda3 et sda4 pour le premier disque SCSI ou SATA sur le premier contrôleur de disque.

Une partition étendue prend la place d'une partition primaire et les lecteurs logiques qui s'y trouvent commencent à partir de hda5 ou de sda5.

Pour clarifier ceci, considérons un disque SATA contenant deux partitions primaires, une seule partition étendue et 3 lecteurs logiques. Dans ce cas, les deux premières partitions sont sda1 et sda2, la partition étendue prend la place de la troisième partition primaire, la sda3 et s'appelle ainsi tandis que la quatrième partition primaire est inexistante.

Les lecteurs logiques commençant à sda5, nous obtenons la liste de partitions suivante : sda1, sda2, sda5, sda6, sda7. Notez que la sda3 ne peut pas être utilisée en tant que partition car elle est cachée par les lecteurs sda5, sda6 et sda7.

Le nombre de partitions sur un disque est limité :

  • IDE,
    • Jusqu'à 63,
  • SCSI,
    • Jusqu'à 15,
  • Disques utilisant l'API libata,
    • Jusqu'à 15.

Important : Ces limites peuvent être dépassées en utilisant la gestion LVM (Logical Volume Management).

Partitionnement

LAB #1 - Partionnement de votre Disque parted

Pour procéder au partitionnement de votre disque ou de vos disques, Linux possède un autre outil dénommé parted.

Lancez parted en fournissant en argument le fichier de référence de votre premier disque dur, par exemple :

root@debian8:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

Pour visualiser la table des partitions actuelle, utilisez la commande print :

(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)

(parted)    

Pour visualiser l'ensemble des commandes de parted, utilisez la commande help :

(parted) help                                                           
  align-check TYPE N                        check partition N for TYPE(min|opt)
        alignment
  help [COMMAND]                           print general help, or help on
        COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition
        table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table,
        available devices, free space, all found partitions, or a particular
        partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START
        and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected
        device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition
        NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and
        copyright information of GNU Parted
(parted)

Pour créer une nouvelle partition, vous devez utiliser la commande mkpart.

Créez donc les partitions suivantes sur votre disque :

Partition Type Taille de la Partition
/dev/sda6 Logique 500 Mo
/dev/sda7 Logique 200 Mo
/dev/sda8 Logique 300 Mo
/dev/sda9 Logique 500 Mo
/dev/sda10 Logique 400 Mo
/dev/sda11 Logique 500 Mo
/dev/sda12 Logique 500 Mo
/dev/sda13 Logique 200 Mo
                                                 
(parted) mkpart logical 12601 13101                                       
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   lba

(parted) mkpart logical 13102 13302                                       
(parted) mkpart logical 13303 13603                                       
(parted) mkpart logical 13604 14104                                       
(parted) mkpart logical 14105 14505                                       
(parted) mkpart logical 14506 15006                                       
(parted) mkpart logical 15007 15507                                       
(parted) mkpart logical 15508 15708                              
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   lba
 7      13.1GB  13.3GB  200MB   logical                   lba
 8      13.3GB  13.6GB  300MB   logical                   lba
 9      13.6GB  14.1GB  500MB   logical                   lba
10      14.1GB  14.5GB  400MB   logical                   lba
11      14.5GB  15.0GB  500MB   logical                   lba
12      15.0GB  15.5GB  500MB   logical                   lba
13      15.5GB  15.7GB  199MB   logical                   lba

(parted)

Ajoutez maintenant les drapeaux raid et LVM aux partitions concernées :

(parted) set 6 raid on                                                    
(parted) set 7 LVM on                                                     
(parted) set 8 LVM on                                                     
(parted) set 9 raid on                                               
(parted) set 10 LVM on                                                    
(parted) set 11 raid on                                              
(parted) set 12 raid on                                                   
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   raid, lba
 7      13.1GB  13.3GB  200MB   logical                   lvm, lba
 8      13.3GB  13.6GB  300MB   logical                   lvm, lba
 9      13.6GB  14.1GB  500MB   logical                   raid, lba
10      14.1GB  14.5GB  400MB   logical                   lvm, lba
11      14.5GB  15.0GB  500MB   logical                   raid, lba
12      15.0GB  15.5GB  500MB   logical                   raid, lba
13      15.5GB  15.7GB  199MB   logical                   lba

(parted)

Supprimer les drapeaux lba sur les partitions de 6 à 13 :

(parted) set 6 lba off                                                    
(parted) set 7 lba off                                                    
(parted) set 8 lba off                                                    
(parted) set 9 lba off                                                    
(parted) set 10 lba off                                                    
(parted) set 11 lba off                                                   
(parted) set 12 lba off                                                   
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   raid
 7      13.1GB  13.3GB  200MB   logical                   lvm
 8      13.3GB  13.6GB  300MB   logical                   lvm
 9      13.6GB  14.1GB  500MB   logical                   raid
10      14.1GB  14.5GB  400MB   logical                   lvm
11      14.5GB  15.0GB  500MB   logical                   raid
12      15.0GB  15.5GB  500MB   logical                   raid
13      15.5GB  15.7GB  199MB   logical                   lba

(parted)     

Quittez parted avec la commande quit :

(parted) quit                                                             
Information: You may need to update /etc/fstab.

Utilisez la commande partprobe pour installer la nouvelle table des partitions :

root@debian8:~# partprobe

Lancez parted puis tapez ensuite la commande print puis ↵ Entrée pour visualiser la table des partitions actuelle :

root@debian8:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   raid
 7      13.1GB  13.3GB  200MB   logical                   lvm
 8      13.3GB  13.6GB  300MB   logical                   lvm
 9      13.6GB  14.1GB  500MB   logical                   raid
10      14.1GB  14.5GB  400MB   logical                   lvm
11      14.5GB  15.0GB  500MB   logical                   raid
12      15.0GB  15.5GB  500MB   logical                   raid
13      15.5GB  15.7GB  199MB   logical  

Pour supprimer une partition, utilisez la commande rm puis ↵ Entrée :

(parted) rm 13                                                            
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   raid
 7      13.1GB  13.3GB  200MB   logical                   lvm
 8      13.3GB  13.6GB  300MB   logical                   lvm
 9      13.6GB  14.1GB  500MB   logical                   raid
10      14.1GB  14.5GB  400MB   logical                   lvm
11      14.5GB  15.0GB  500MB   logical                   raid
12      15.0GB  15.5GB  500MB   logical                   raid

(parted)    

A ce stade, notez la différence entre le comportement de fdisk et de parted :

(parted) quit                                                             
Information: You may need to update /etc/fstab.

root@debian8:~# parted /dev/sda                                     
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   raid
 7      13.1GB  13.3GB  200MB   logical                   lvm
 8      13.3GB  13.6GB  300MB   logical                   lvm
 9      13.6GB  14.1GB  500MB   logical                   raid
10      14.1GB  14.5GB  400MB   logical                   lvm
11      14.5GB  15.0GB  500MB   logical                   raid
12      15.0GB  15.5GB  500MB   logical                   raid

(parted)                                                                     

Re-créez la partition numéro 13 :

(parted) mkpart logical 15508 15708                                       
(parted) print                                                            
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.5GB  10.5GB  primary   ext4            boot
 2      10.5GB  21.5GB  11.0GB  extended
 5      10.5GB  12.6GB  2096MB  logical   linux-swap(v1)
 6      12.6GB  13.1GB  500MB   logical                   raid
 7      13.1GB  13.3GB  200MB   logical                   lvm
 8      13.3GB  13.6GB  300MB   logical                   lvm
 9      13.6GB  14.1GB  500MB   logical                   raid
10      14.1GB  14.5GB  400MB   logical                   lvm
11      14.5GB  15.0GB  500MB   logical                   raid
12      15.0GB  15.5GB  500MB   logical                   raid
13      15.5GB  15.7GB  199MB   logical                   lba

(parted)   

Sortez de parted en utilisant la commande quit :

(parted) quit                                                             
Information: You may need to update /etc/fstab.

root@debian8:~# partprobe                                                 
root@debian8:~# 

Important : Notez que l'utilisation de la commande partprobe n'est pas necéssaire quand les modifications concernent des disques locaux. Par contre l'utilisation est necéssaire sur un deuxième noeud si le premier noeud modifie les partitions d'un stockage partagé.

Options de la Commande parted

Les options de cette commande sont :

root@debian8:~# parted --help
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
interactive mode.

OPTIONs:
  -h, --help                      displays this help message
  -l, --list                      lists partition layout on all block devices
  -m, --machine                   displays machine parseable output
  -s, --script                    never prompts for user intervention
  -v, --version                   displays the version
  -a, --align=[none|cyl|min|opt]  alignment for new partitions

COMMANDs:
  align-check TYPE N                        check partition N for TYPE(min|opt)
        alignment
  help [COMMAND]                           print general help, or help on
        COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition
        table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table,
        available devices, free space, all found partitions, or a particular
        partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START
        and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected
        device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition
        NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and
        copyright information of GNU Parted

Report bugs to bug-parted@gnu.org

Logical Volume Manager (LVM)

LAB #2 - Volumes Logiques Linéaires

Afin de mettre en place le LVM, vous avez besoin du paquet lvm2 et du paquet device-mapper.

Sous Debian 8, installez le paquet lvm2 :

root@debian8:~# apt-get install lvm2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  dmeventd libdevmapper-event1.02.1 liblvm2cmd2.02 libreadline5
Suggested packages:
  thin-provisioning-tools
The following NEW packages will be installed:
  dmeventd libdevmapper-event1.02.1 liblvm2cmd2.02 libreadline5 lvm2
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,530 kB of archives.
After this operation, 3,898 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://httpredir.debian.org/debian/ jessie/main libdevmapper-event1.02.1 i386 2:1.02.90-2.2 [35.7 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main dmeventd i386 2:1.02.90-2.2 [51.5 kB]
Get:3 http://httpredir.debian.org/debian/ jessie/main libreadline5 i386 5.2+dfsg-2 [146 kB]
Get:4 http://httpredir.debian.org/debian/ jessie/main liblvm2cmd2.02 i386 2.02.111-2.2 [552 kB]
Get:5 http://httpredir.debian.org/debian/ jessie/main lvm2 i386 2.02.111-2.2 [745 kB]
Fetched 1,530 kB in 3s (453 kB/s)                                   
Selecting previously unselected package libdevmapper-event1.02.1:i386.
(Reading database ... 159447 files and directories currently installed.)
Preparing to unpack .../libdevmapper-event1.02.1_2%3a1.02.90-2.2_i386.deb ...
Unpacking libdevmapper-event1.02.1:i386 (2:1.02.90-2.2) ...
Selecting previously unselected package dmeventd.
Preparing to unpack .../dmeventd_2%3a1.02.90-2.2_i386.deb ...
Unpacking dmeventd (2:1.02.90-2.2) ...
Selecting previously unselected package liblvm2cmd2.02:i386.
Preparing to unpack .../liblvm2cmd2.02_2.02.111-2.2_i386.deb ...
Unpacking liblvm2cmd2.02:i386 (2.02.111-2.2) ...
Selecting previously unselected package libreadline5:i386.
Preparing to unpack .../libreadline5_5.2+dfsg-2_i386.deb ...
Unpacking libreadline5:i386 (5.2+dfsg-2) ...
Selecting previously unselected package lvm2.
Preparing to unpack .../lvm2_2.02.111-2.2_i386.deb ...
Unpacking lvm2 (2.02.111-2.2) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for systemd (215-17+deb8u2) ...
Setting up libdevmapper-event1.02.1:i386 (2:1.02.90-2.2) ...
Setting up libreadline5:i386 (5.2+dfsg-2) ...
Setting up liblvm2cmd2.02:i386 (2.02.111-2.2) ...
Setting up dmeventd (2:1.02.90-2.2) ...
Setting up lvm2 (2.02.111-2.2) ...
update-initramfs: deferring update (trigger activated)
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Processing triggers for libc-bin (2.19-18+deb8u1) ...
Processing triggers for systemd (215-17+deb8u2) ...
Processing triggers for initramfs-tools (0.120) ...
update-initramfs: Generating /boot/initrd.img-3.16.0-4-586

Nous allons travailler sous Debian 8 avec les partitions suivantes :

 7      12.5GB  12.7GB  200MB   logical                   lvm, lba
 8      12.7GB  13.0GB  300MB   logical                   lvm, lba
10      13.5GB  13.9GB  401MB   logical                   lvm, lba

Pour initialiser le LVM saississez la commande suivante :

root@debian8:~# vgscan
  Reading all physical volumes.  This may take a while...
  No volume groups found

Les options de la commande vgscan sont :

root@debian8:~# vgscan --help
  vgscan: Search for all volume groups

vgscan 	[--cache]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-h|--help]
	[--ignorelockingfailure]
	[--mknodes]
	[-P|--partial] 
	[-v|--verbose]
	[--version]

Physical Volume (PV)

Pour créer le PV il convient d'utiliser la commande pvcreate :

root@debian8:~# pvcreate /dev/sda7 /dev/sda8 /dev/sda10
  Physical volume "/dev/sda7" successfully created
  Physical volume "/dev/sda8" successfully created
  Physical volume "/dev/sda10" successfully created

Les options de la commande pvcreate sont :

root@debian8:~# pvcreate --help
  pvcreate: Initialize physical volume(s) for use by LVM

pvcreate 
	[--norestorefile]
	[--restorefile file]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-f[f]|--force [--force]] 
	[-h|-?|--help] 
	[--labelsector sector] 
	[-M|--metadatatype 1|2]
	[--pvmetadatacopies #copies]
	[--bootloaderareasize BootLoaderAreaSize[bBsSkKmMgGtTpPeE]]
	[--metadatasize MetadataSize[bBsSkKmMgGtTpPeE]]
	[--dataalignment Alignment[bBsSkKmMgGtTpPeE]]
	[--dataalignmentoffset AlignmentOffset[bBsSkKmMgGtTpPeE]]
	[--setphysicalvolumesize PhysicalVolumeSize[bBsSkKmMgGtTpPeE]
	[-t|--test] 
	[-u|--uuid uuid] 
	[-v|--verbose] 
	[-y|--yes]
	[-Z|--zero {y|n}]
	[--version] 
	PhysicalVolume [PhysicalVolume...]

Pour visualiser le PV il convient d'utiliser la commande pvdisplay :

root@debian8:~# pvdisplay /dev/sda7 /dev/sda8 /dev/sda10
  "/dev/sda7" is a new physical volume of "191.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda7
  VG Name               
  PV Size               191.00 MiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               c4Pt5x-jSBj-yAjS-g3Bk-LTT0-qp1M-G3Rxbd
   
  "/dev/sda8" is a new physical volume of "286.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda8
  VG Name               
  PV Size               286.00 MiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               vvvGoQ-e0wt-zEwX-p3cP-piFn-2m7G-OreWFX
   
  "/dev/sda10" is a new physical volume of "382.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda10
  VG Name               
  PV Size               382.00 MiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               onMXRg-NR52-4M28-qIp5-R1Zs-ckPQ-qaACEn

Les options de la commande pvdisplay sont :

root@debian8:~# pvdisplay --help
  pvdisplay: Display various attributes of physical volume(s)

pvdisplay
	[-c|--colon]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-h|--help]
	[--ignorelockingfailure]
	[--ignoreskippedcluster]
	[-m|--maps]
	[--nosuffix]
	[--readonly]
	[-s|--short]
	[--units hHbBsSkKmMgGtTpPeE]
	[-v|--verbose]
	[--version]
	[PhysicalVolumePath [PhysicalVolumePath...]]

pvdisplay --columns|-C
	[--aligned]
	[-a|--all]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-h|--help]
	[--ignorelockingfailure]
	[--ignoreskippedcluster]
	[--noheadings]
	[--nosuffix]
	[-o|--options [+]Field[,Field]]
	[-O|--sort [+|-]key1[,[+|-]key2[,...]]]
	[-S|--select Selection]
	[--readonly]
	[--separator Separator]
	[--unbuffered]
	[--units hHbBsSkKmMgGtTpPeE]
	[-v|--verbose]
	[--version]
	[PhysicalVolumePath [PhysicalVolumePath...]]

Volume Group (VG) et Physical Extent (PE)

Pour créer un Volume Group dénommé vg0, il convient d'utiliser la commande vgcreate :

root@debian8:~# vgcreate -s 8M vg0 /dev/sda7 /dev/sda8 /dev/sda10
  /proc/devices: No entry for device-mapper found
  /proc/devices: No entry for device-mapper found
  /proc/devices: No entry for device-mapper found
  Volume group "vg0" successfully created

Les options de la commande vgcreate sont :

root@debian8:~# vgcreate --help
  vgcreate: Create a volume group

vgcreate
	[-A|--autobackup {y|n}] 
	[--addtag Tag] 
	[--alloc AllocationPolicy] 
	[-c|--clustered {y|n}] 
	[--commandprofile ProfileName]
	[-d|--debug]
	[-h|--help]
	[-l|--maxlogicalvolumes MaxLogicalVolumes]
	[--metadataprofile ProfileName]
	[-M|--metadatatype 1|2] 
	[--[vg]metadatacopies #copies] 
	[-p|--maxphysicalvolumes MaxPhysicalVolumes] 
	[-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]] 
	[-t|--test] 
	[-v|--verbose]
	[--version] 
	[-y|--yes]
	[ PHYSICAL DEVICE OPTIONS ] 
	VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]

Pour afficher les informations concernant vg0, il convient d'utiliser la commande vgdisplay :

root@debian8:~# vgdisplay vg0
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               840.00 MiB
  PE Size               8.00 MiB
  Total PE              105
  Alloc PE / Size       0 / 0   
  Free  PE / Size       105 / 840.00 MiB
  VG UUID               hWJwaj-5h7Z-ToXt-i0Sl-9f3o-q4n5-8JWOrr

Les options de la commande vgdisplay sont :

root@debian8:~# vgdisplay --help
  vgdisplay: Display volume group information

vgdisplay 
	[-A|--activevolumegroups]
	[-c|--colon | -s|--short | -v|--verbose]
	[--commandprofile ProfileName]
	[-d|--debug] 
	[-h|--help] 
	[--ignorelockingfailure]
	[--ignoreskippedcluster]
	[--nosuffix]
	[-P|--partial] 
	[--readonly]
	[--units hHbBsSkKmMgGtTpPeE]
	[--version]
	[VolumeGroupName [VolumeGroupName...]]

vgdisplay --columns|-C
	[--aligned]
	[--commandprofile ProfileName]
	[-d|--debug] 
	[-h|--help] 
	[--ignorelockingfailure]
	[--ignoreskippedcluster]
	[--noheadings]
	[--nosuffix]
	[-o|--options [+]Field[,Field]]
	[-O|--sort [+|-]key1[,[+|-]key2[,...]]]
	[-P|--partial] 
	[-S|--select Selection]
	[--readonly]
	[--separator Separator]
	[--unbuffered]
	[--units hHbBsSkKmMgGtTpPeE]
	[--verbose]
	[--version]
	[VolumeGroupName [VolumeGroupName...]]

Logical Volumes (LV)

Pour créer un Logical Volume dénommé lv0 dans le Volume Group vg0, il convient d'utiliser la commande lvcreate :

root@debian8:~# lvcreate -L 350 -n lv0 vg0
  Rounding up size to full physical extent 352.00 MiB
  Logical volume "lv0" created

Notez que la taille du LV est un multiple du PE.

Les options de la commande lvcreate sont :

root@debian8:~# lvcreate --help
  lvcreate: Create a logical volume

lvcreate 
	[-A|--autobackup {y|n}]
	[-a|--activate [a|e|l]{y|n}]
	[--addtag Tag]
	[--alloc AllocationPolicy]
	[--cachemode CacheMode]
	[-C|--contiguous {y|n}]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-h|-?|--help]
	[--ignoremonitoring]
	[--monitor {y|n}]
	[-i|--stripes Stripes [-I|--stripesize StripeSize]]
	[-k|--setactivationskip {y|n}]
	[-K|--ignoreactivationskip] 
	{-l|--extents LogicalExtentsNumber[%{VG|PVS|FREE}] |
	 -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
	[-M|--persistent {y|n}] [--major major] [--minor minor]
	[--metadataprofile ProfileName]
	[-m|--mirrors Mirrors [--nosync] [{--mirrorlog {disk|core|mirrored}|--corelog}]]
	[-n|--name LogicalVolumeName]
	[--noudevsync]
	[-p|--permission {r|rw}]
	[--[raid]minrecoveryrate Rate]
	[--[raid]maxrecoveryrate Rate]
	[-r|--readahead ReadAheadSectors|auto|none]
	[-R|--regionsize MirrorLogRegionSize]
	[-T|--thin  [-c|--chunksize  ChunkSize]
	  [--discards {ignore|nopassdown|passdown}]
	  [--poolmetadatasize MetadataSize[bBsSkKmMgG]]]
	  [--poolmetadataspare {y|n}]
	[--thinpool ThinPoolLogicalVolume{Name|Path}]
	[-t|--test]
	[--type VolumeType]
	[-v|--verbose]
	[-W|--wipesignatures {y|n}]
	[-Z|--zero {y|n}]
	[--version]
	VolumeGroupName [PhysicalVolumePath...]

lvcreate 
	{ {-s|--snapshot} OriginalLogicalVolume[Path] |
	  [-s|--snapshot] VolumeGroupName[Path] -V|--virtualsize VirtualSize}
	  {-T|--thin} VolumeGroupName[Path][/PoolLogicalVolume] 
	              -V|--virtualsize VirtualSize}
	[-c|--chunksize]
	[-A|--autobackup {y|n}]
	[--addtag Tag]
	[--alloc AllocationPolicy]
	[-C|--contiguous {y|n}]
	[--commandprofile ProfileName]
	[-d|--debug]
	[--discards {ignore|nopassdown|passdown}]
	[-h|-?|--help]
	[--ignoremonitoring]
	[--monitor {y|n}]
	[-i|--stripes Stripes [-I|--stripesize StripeSize]]
	[-k|--setactivationskip {y|n}]
	[-K|--ignoreactivationskip] 
	{-l|--extents LogicalExtentsNumber[%{VG|FREE|ORIGIN}] |
	 -L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
	[--poolmetadatasize MetadataVolumeSize[bBsSkKmMgG]]
	[-M|--persistent {y|n}] [--major major] [--minor minor]
	[--metadataprofile ProfileName]
	[-n|--name LogicalVolumeName]
	[--noudevsync]
	[-p|--permission {r|rw}]
	[-r|--readahead ReadAheadSectors|auto|none]
	[-t|--test]
	[--thinpool ThinPoolLogicalVolume[Path]]
	[-v|--verbose]
	[--version]
	[PhysicalVolumePath...]

Créez maintenant un répertoire dans /mnt pour monter lv0 :

root@debian8:~# mkdir /mnt/lvm

Créez un système de fichiers en ext3 sur /dev/vg0/lv0 :

root@debian8:~# mke2fs -j /dev/vg0/lv0
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 360448 1k blocks and 90112 inodes
Filesystem UUID: 736e900c-8485-4fc7-be44-8ab5dca636e4
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729, 204801, 221185

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done 

Montez votre lv0 :

root@debian8:~# mount -t ext3 /dev/vg0/lv0 /mnt/lvm

Vous allez maintenant copier le contenu de votre répertoire /home vers /mnt/lvm.

Saisissez donc la commande pour copier le contenu de /home :

root@debian8:~# cp -a /home /mnt/lvm

Constatez ensuite le contenu de /mnt/lvm :

root@debian8:~# ls -l /mnt/lvm
total 13
drwxr-xr-x 6 root root  1024 Oct 16 14:16 home
drwx------ 2 root root 12288 Oct 22 13:50 lost+found

Une particularité du volume logique est la capacité de d'être aggrandi ou réduit sans pertes de données. Commencez par constater la taille totale du volume :

root@debian8:~# df -h /mnt/lvm
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv0  333M   49M  267M  16% /mnt/lvm

Dans la cas de notre exemple, la taille est de 333 Mo avec 49 Mo occupé.

LAB #3 - Etendre un Volume Logique à Chaud

Pour agrandir un volume logique, le paquet lvm2 contient les commandes lvextend et resize2fs :

root@debian8:~# lvextend -L +100M /dev/vg0/lv0
  Rounding size to boundary between physical extents: 104.00 MiB
  Size of logical volume vg0/lv0 changed from 352.00 MiB (44 extents) to 456.00 MiB (57 extents).
  Logical volume lv0 successfully resized

Notez que l'agrandissement du volume est un multiple du PE.

Les options de la commande lvextend sont :

root@debian8:~# lvextend --help
  lvextend: Add space to a logical volume

lvextend
	[-A|--autobackup y|n]
	[--alloc AllocationPolicy]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-f|--force]
	[-h|--help]
	[-i|--stripes Stripes [-I|--stripesize StripeSize]]
	{-l|--extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}] |
	 -L|--size [+]LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
	 --poolmetadatasize [+]MetadataVolumeSize[bBsSkKmMgG]}
	[-m|--mirrors Mirrors]
	[--nosync]
	[--use-policies]
	[-n|--nofsck]
	[--noudevsync]
	[-r|--resizefs]
	[-t|--test]
	[--type VolumeType]
	[-v|--verbose]
	[--version]
	LogicalVolume[Path] [ PhysicalVolumePath... ]

Le volume ayant été agrandi, il est necessaire maintenant d'agrandir le filesystem qui s'y trouve :

root@debian8:~# resize2fs /dev/vg0/lv0
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/vg0/lv0 is mounted on /mnt/lvm; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/vg0/lv0 is now 466944 (1k) blocks long.

Constatez maintenant la modification de la taille du volume :

root@debian8:~# df -h /mnt/lvm
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv0  434M   49M  363M  12% /mnt/lvm

Vous noterez que la taille a augmentée mais que les données sont toujours présentes.

LAB #4 - Snapshots

Un snapshot est un instantané d'un système de fichiers. Dans cet exemple, vous allez créer un snapshot de votre lv0 :

Avant de commencer, créez un fichier de 10Mo dans le volume :

root@debian8:~# dd if=/dev/zero of=/mnt/lvm/10M bs=1048576 count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0218448 s, 480 MB/s

Créez maintenant un snapshot :

root@debian8:~# lvcreate -s -L 65M -n testsnap /dev/vg0/lv0
  Rounding up size to full physical extent 72.00 MiB
  Logical volume "testsnap" created

Pour avoir une confirmation de la création du snapshot, utilisez la commande lvs :

root@debian8:~# lvs
  LV       VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0      vg0  owi-aos--- 456.00m                                                    
  testsnap vg0  swi-a-s---  72.00m      lv0    0.02      

Notez que le snapshot est créé dans le même VG que le LV d'origine.

Les options de la commande lvs sont :

root@debian8:~# lvs --help
  lvs: Display information about logical volumes

lvs
	[-a|--all]
	[--aligned]
	[--binary]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-h|--help]
	[--ignorelockingfailure]
	[--ignoreskippedcluster]
	[--nameprefixes]
	[--noheadings]
	[--nosuffix]
	[-o|--options [+]Field[,Field]]
	[-O|--sort [+|-]key1[,[+|-]key2[,...]]]
	[-P|--partial] 
	[--readonly]
	[--rows]
	[--segments]
	[-S|--select Selection]
	[--separator Separator]
	[--trustcache]
	[--unbuffered]
	[--units hHbBsSkKmMgGtTpPeE]
	[--unquoted]
	[-v|--verbose]
	[--version]
	[LogicalVolume[Path] [LogicalVolume[Path]...]]

Créez maintenant un répertoire pour monter le snapshot :

root@debian8:~# mkdir /mnt/testsnap

Montez le snapshot :

root@debian8:~# mount /dev/vg0/testsnap /mnt/testsnap

Comparez le volume d'origine et le snapshot :

root@debian8:~# ls -l /mnt/lvm
total 10294
-rw-r--r-- 1 root root 10485760 Oct 22 13:57 10M
drwxr-xr-x 6 root root     1024 Oct 16 14:16 home
drwx------ 2 root root    12288 Oct 22 13:50 lost+found
root@debian8:~# ls -l /mnt/testsnap
total 10294
-rw-r--r-- 1 root root 10485760 Oct 22 13:57 10M
drwxr-xr-x 6 root root     1024 Oct 16 14:16 home
drwx------ 2 root root    12288 Oct 22 13:50 lost+found

Supprimez maintenant le fichier 10M de votre volume d'origine :

root@debian8:~# rm /mnt/lvm/10M

Constatez le résultat de cette suppression :

root@debian8:~# df -Ph /mnt/lvm
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv0  434M   49M  363M  12% /mnt/lvm
root@debian8:~# df -Ph /mnt/testsnap
Filesystem                Size  Used Avail Use% Mounted on
/dev/mapper/vg0-testsnap  434M   59M  353M  15% /mnt/testsnap
root@debian8:~# lvs
  LV       VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0      vg0  owi-aos--- 456.00m                                                    
  testsnap vg0  swi-aos---  72.00m      lv0    0.08         

Restaurez le fichier 10M à partir du snapshot.

LAB #5 - Suppression des Volumes

La suppression d'un volume logique se fait grace à la commande lvremove :

root@debian8:~# umount /mnt/testsnap/
root@debian8:~# lvremove /dev/vg0/testsnap
Do you really want to remove active logical volume testsnap? [y/n]: y
  Logical volume "testsnap" successfully removed
root@debian8:~# umount /mnt/lvm
root@debian8:~# lvremove /dev/vg0/lv0
Do you really want to remove active logical volume lv0? [y/n]: y
  Logical volume "lv0" successfully removed

Notez que cette opération necéssite à ce que le volume logique soit démonté.

Les options de la commande lvremove sont :

root@debian8:~# lvremove --help
  lvremove: Remove logical volume(s) from the system

lvremove
	[-A|--autobackup y|n]
	[--commandprofile ProfileName]
	[-d|--debug]
	[-f|--force]
	[-h|--help]
	[--noudevsync]
	[-t|--test]
	[-v|--verbose]
	[--version]
	LogicalVolume[Path] [LogicalVolume[Path]...]

Le Volume Group peut aussi être supprimé :

root@debian8:~# vgremove vg0
  Volume group "vg0" successfully removed

Les options de la commande vgremove sont :

root@debian8:~# vgremove --help
  vgremove: Remove volume group(s)

vgremove
	[--commandprofile ProfileName]
	[-d|--debug]
	[-f|--force]
	[-h|--help]
	[--noudevsync]
	[-t|--test]
	[-v|--verbose]
	[--version]
	VolumeGroupName [VolumeGroupName...]

Ainsi que le volume physique :

root@debian8:~# pvremove /dev/sda7 /dev/sda8 /dev/sda10
  Labels on physical volume "/dev/sda7" successfully wiped
  Labels on physical volume "/dev/sda8" successfully wiped
  Labels on physical volume "/dev/sda10" successfully wiped

Les options de la commande pvremove sont :

root@debian8:~# pvremove --help
  pvremove: Remove LVM label(s) from physical volume(s)

pvremove 
	[--commandprofile ProfileName]
	[-d|--debug]
	[-f[f]|--force [--force]] 
	[-h|-?|--help] 
	[-t|--test] 
	[-v|--verbose] 
	[--version] 
	[-y|--yes]
	PhysicalVolume [PhysicalVolume...]

LAB #6 - Volumes Logiques en Miroir

Re-créez maintenant votre Volume Group :

root@debian8:~# pvcreate /dev/sda7 /dev/sda8 /dev/sda10
  Physical volume "/dev/sda7" successfully created
  Physical volume "/dev/sda8" successfully created
  Physical volume "/dev/sda10" successfully created
root@debian8:~# vgcreate -s 8M vg0 /dev/sda7 /dev/sda8 /dev/sda10
  Volume group "vg0" successfully created

Créez maintenant un Logical Volume en miroir grâce à l'option -m de la commande lvcreate, suivi du nombre de miroirs :

root@debian8:~# lvcreate -m 1 -L 100M -n lv1 vg0
  Rounding up size to full physical extent 104.00 MiB
  Logical volume "lv1" created

Constatez miantenant la présence du miroir :

root@debian8:~# lvdisplay -m /dev/vg0/lv1
  --- Logical volume ---
  LV Path                /dev/vg0/lv1
  LV Name                lv1
  VG Name                vg0
  LV UUID                hpUo64-x8Tc-EycA-mBON-rcvQ-2mcb-aHBXSy
  LV Write Access        read/write
  LV Creation host, time debian8, 2015-10-22 14:12:01 +0200
  LV Status              available
  # open                 0
  LV Size                104.00 MiB
  Current LE             13
  Mirrored volumes       2
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:4
   
  --- Segments ---
  Logical extents 0 to 12:
    Type		raid1
    Monitoring		monitored
    Raid Data LV 0
      Logical volume	lv1_rimage_0
      Logical extents	0 to 12
    Raid Data LV 1
      Logical volume	lv1_rimage_1
      Logical extents	0 to 12
    Raid Metadata LV 0	lv1_rmeta_0
    Raid Metadata LV 1	lv1_rmeta_1

Le miroir s'étend sur plusieurs volumes physiques :

root@debian8:~# pvdisplay -m /dev/sda7 /dev/sda8 /dev/sda10
  --- Physical volume ---
  PV Name               /dev/sda7
  VG Name               vg0
  PV Size               191.00 MiB / not usable 7.00 MiB
  Allocatable           yes 
  PE Size               8.00 MiB
  Total PE              23
  Free PE               9
  Allocated PE          14
  PV UUID               a0GZ9s-c4f5-0Nnq-LX2k-zFY8-UCNH-0u7qnv
   
  --- Physical Segments ---
  Physical extent 0 to 0:
    Logical volume	/dev/vg0/lv1_rmeta_0
    Logical extents	0 to 0
  Physical extent 1 to 13:
    Logical volume	/dev/vg0/lv1_rimage_0
    Logical extents	0 to 12
  Physical extent 14 to 22:
    FREE
   
  --- Physical volume ---
  PV Name               /dev/sda8
  VG Name               vg0
  PV Size               286.00 MiB / not usable 6.00 MiB
  Allocatable           yes 
  PE Size               8.00 MiB
  Total PE              35
  Free PE               21
  Allocated PE          14
  PV UUID               0IBD6i-CycF-OcaT-xNoj-AiPG-9s37-cYjYHk
   
  --- Physical Segments ---
  Physical extent 0 to 0:
    Logical volume	/dev/vg0/lv1_rmeta_1
    Logical extents	0 to 0
  Physical extent 1 to 13:
    Logical volume	/dev/vg0/lv1_rimage_1
    Logical extents	0 to 12
  Physical extent 14 to 34:
    FREE
   
  --- Physical volume ---
  PV Name               /dev/sda10
  VG Name               vg0
  PV Size               382.00 MiB / not usable 6.00 MiB
  Allocatable           yes 
  PE Size               8.00 MiB
  Total PE              47
  Free PE               47
  Allocated PE          0
  PV UUID               c1iqw2-L5Tu-Xm9T-KUDy-0H7o-9CzQ-3CZdsI
   
  --- Physical Segments ---
  Physical extent 0 to 46:
    FREE

La suppression du miroir se fait en utilisant la commande lvconvert en indiquant quel volume physique doit être vidé de son contenu :

root@debian8:~# lvconvert -m 0 /dev/vg0/lv1 /dev/sda8

De même, il est possible de créer un miroir pour un volume logique existant :

root@debian8:~# lvconvert -m 1 /dev/vg0/lv1

Supprimez de nouveau votre miroir :

root@debian8:~# lvconvert -m 0 /dev/vg0/lv1 /dev/sda8

Les options de la commande lvconvert sont :

root@debian8:~# lvconvert --help
  lvconvert: Change logical volume layout

lvconvert [-m|--mirrors Mirrors [{--mirrorlog {disk|core|mirrored}|--corelog}]]
	[--type SegmentType]
	[--repair [--use-policies]]
	[--replace PhysicalVolume]
	[-R|--regionsize MirrorLogRegionSize]
	[--alloc AllocationPolicy]
	[-b|--background]
	[-f|--force]
	[-i|--interval seconds]
	[--stripes Stripes [-I|--stripesize StripeSize]]
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	LogicalVolume[Path] [PhysicalVolume[Path]...]

lvconvert [--splitmirrors Images --trackchanges]
	[--splitmirrors Images --name SplitLogicalVolumeName]
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	LogicalVolume[Path] [SplittablePhysicalVolume[Path]...]

lvconvert --splitsnapshot
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	SnapshotLogicalVolume[Path]

lvconvert [--type snapshot|-s|--snapshot]
	[-c|--chunksize]
	[-Z|--zero {y|n}]
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	OriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]

lvconvert --merge
	[-b|--background]
	[-i|--interval seconds]
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	LogicalVolume[Path]

lvconvert [--type thin[-pool]|-T|--thin]
	[--thinpool ThinPoolLogicalVolume[Path]]
	[--chunksize size]
	[--discards {ignore|nopassdown|passdown}]
	[--poolmetadataspare {y|n}]
	[--poolmetadata ThinMetadataLogicalVolume[Path] |
	 [--poolmetadatasize size]
	 [-r|--readahead ReadAheadSectors|auto|none]
	 [--stripes Stripes [-I|--stripesize StripeSize]]]
	[--originname NewExternalOriginVolumeName]]
	[-Z|--zero {y|n}]
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	[ExternalOrigin|ThinDataPool]LogicalVolume[Path]

lvconvert [--type cache[-pool]|--cache]
	[--cachepool CacheDataLogicalVolume[Path]]
	[--cachemode CacheMode]
	[--chunksize size]
	[--poolmetadataspare {y|n}]]
	[--poolmetadata CacheMetadataLogicalVolume[Path] |
	 [--poolmetadatasize size]
	[--commandprofile ProfileName] [-d|--debug] [-h|-?|--help]
	[--noudevsync] [-t|--test] [-v|--verbose] [--version] [-y|--yes]
	[Cache|CacheDataPool]LogicalVolume[Path]

LAB #7 - Modifier les Attributs LVM

En cas de présence d'un miroir, la commande lvs indique la présence du miroir dans la colonne Attr avec la lettre m :

root@debian8:~# lvs
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg0  -wi-a----- 104.00m           

Consultez cette page pour comprendre les attributs.

La commande equivalente pour les Volume Groups est vgs :

root@debian8:~# vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  vg0    3   1   0 wz--n- 840.00m 736.00m

Consultez cette page pour comprendre les attributs.

La commande équivalente pour les Physical Volumes est pvs :

root@debian8:~# pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sda10 vg0  lvm2 a--  376.00m 376.00m
  /dev/sda7  vg0  lvm2 a--  184.00m  80.00m
  /dev/sda8  vg0  lvm2 a--  280.00m 280.00m

Consultez cette page pour comprendre les attributs.

Les commandes lvchange, vgchange et pvchange permettent de modifier les attributs des Logical Volumes, Volume Groups et Physical Volumes respectivement.

Par exemple, pour rendre inutilisable un Logical Volume, il convient d'enlever l'attribut a :

root@debian8:~# lvchange -a n /dev/vg0/lv1

Pour faire l'inverse il convient de saisir la commande suivante :

root@debian8:~# lvchange -a y /dev/vg0/lv1

Les options de la commande lvchange sont :

root@debian8:~# lvchange --help
  lvchange: Change the attributes of logical volume(s)

lvchange
	[-A|--autobackup y|n]
	[-a|--activate [a|e|l]{y|n}]
	[--activationmode {complete|degraded|partial}	[--addtag Tag]
	[--alloc AllocationPolicy]
	[-C|--contiguous y|n]
	[--commandprofile ProfileName]
	[-d|--debug]
	[--deltag Tag]
	[--detachprofile]
	[-f|--force]
	[-h|--help]
	[--discards {ignore|nopassdown|passdown}]
	[--ignorelockingfailure]
	[--ignoremonitoring]
	[--ignoreskippedcluster]
	[-k|--setactivationskip {y|n}]
	[-K|--ignoreactivationskip] 
	[--monitor {y|n}]
	[--poll {y|n}]
	[--noudevsync]
	[-M|--persistent y|n] [--major major] [--minor minor]
	[--metadataprofile ProfileName]
	[-P|--partial] 
	[-p|--permission r|rw]
	[--[raid]minrecoveryrate Rate]
	[--[raid]maxrecoveryrate Rate]
	[--[raid]syncaction {check|repair}
	[--[raid]writebehind IOCount]
	[--[raid]writemostly PhysicalVolume[:{t|n|y}]]
	[-r|--readahead ReadAheadSectors|auto|none]
	[--refresh]
	[--resync]
	[--sysinit]
	[-t|--test]
	[-v|--verbose]
	[--version]
	[-y|--yes]
	[-Z|--zero {y|n}]
	LogicalVolume[Path] [LogicalVolume[Path]...]

LAB #8 - Volumes Logiques en Bandes

Un volume logique en bandes est créé pour augmenter, comme dans le cas du RAID, les performances des entrées et sorties. Pour créer ce volume, la commande lvcreate prend deux option supplémentaires :

  • -i - indique le nombre de volumes de bandes,
  • -I - indique la taille en Ko de chaque bande.

Saisissez donc la commande suivante :

root@debian8:~# lvcreate -i2 -I64 -n lv2 -L 100M vg0 /dev/sda8 /dev/sda10
  Rounding up size to full physical extent 104.00 MiB
  Rounding size (13 extents) up to stripe boundary size (14 extents).
  Logical volume "lv2" created

Constatez la présence de vos bandes sur /dev/sda7 et sur /dev/sda9 :

root@debian8:~# lvdisplay -m /dev/vg0/lv2
  --- Logical volume ---
  LV Path                /dev/vg0/lv2
  LV Name                lv2
  VG Name                vg0
  LV UUID                PLq8Gr-fsBs-2BfK-y832-HgeJ-N3lm-QRPfld
  LV Write Access        read/write
  LV Creation host, time debian8, 2015-10-22 14:22:59 +0200
  LV Status              available
  # open                 0
  LV Size                112.00 MiB
  Current LE             14
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     512
  Block device           254:0
   
  --- Segments ---
  Logical extents 0 to 13:
    Type		striped
    Stripes		2
    Stripe size		64.00 KiB
    Stripe 0:
      Physical volume	/dev/sda8
      Physical extents	0 to 6
    Stripe 1:
      Physical volume	/dev/sda10
      Physical extents	0 to 6

Utilisez maintenant la commande lvs pour visualiser les volumes physiques utilisés par le volume logique :

root@debian8:~# lvs -o +devices
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Devices                   
  lv1  vg0  -wi-a----- 104.00m                                                     /dev/sda7(1)              
  lv2  vg0  -wi-a----- 112.00m                                                     /dev/sda8(0),/dev/sda10(0)

LAB #9 - Gérer les Métadonnées

Les métadonnées pour chaque Volume Group sont stockés dans un fichier texte au nom du Volume Group dans le répertoire /etc/lvm/backup :

root@debian8:~# cat /etc/lvm/backup/vg0
# Generated by LVM2 version 2.02.111(2) (2014-09-01): Thu Oct 22 14:22:59 2015

contents = "Text Format Volume Group"
version = 1

description = "Created *after* executing 'lvcreate -i2 -I64 -n lv2 -L 100M vg0 /dev/sda8 /dev/sda10'"

creation_host = "debian8"	# Linux debian8 3.16.0-4-586 #1 Debian 3.16.7-ckt11-1+deb8u5 (2015-10-09) i686
creation_time = 1445516579	# Thu Oct 22 14:22:59 2015

vg0 {
	id = "Cf0msZ-We50-kq9s-EPr8-2jwD-hNz5-dlZaxC"
	seqno = 10
	format = "lvm2"			# informational
	status = ["RESIZEABLE", "READ", "WRITE"]
	flags = []
	extent_size = 16384		# 8 Megabytes
	max_lv = 0
	max_pv = 0
	metadata_copies = 0

	physical_volumes {

		pv0 {
			id = "a0GZ9s-c4f5-0Nnq-LX2k-zFY8-UCNH-0u7qnv"
			device = "/dev/sda7"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 391168	# 191 Megabytes
			pe_start = 2048
			pe_count = 23	# 184 Megabytes
		}

		pv1 {
			id = "0IBD6i-CycF-OcaT-xNoj-AiPG-9s37-cYjYHk"
			device = "/dev/sda8"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 585728	# 286 Megabytes
			pe_start = 2048
			pe_count = 35	# 280 Megabytes
		}

		pv2 {
			id = "c1iqw2-L5Tu-Xm9T-KUDy-0H7o-9CzQ-3CZdsI"
			device = "/dev/sda10"	# Hint only

			status = ["ALLOCATABLE"]
			flags = []
			dev_size = 782336	# 382 Megabytes
			pe_start = 2048
			pe_count = 47	# 376 Megabytes
		}
	}

	logical_volumes {

		lv1 {
			id = "hpUo64-x8Tc-EycA-mBON-rcvQ-2mcb-aHBXSy"
			status = ["READ", "WRITE", "VISIBLE"]
			flags = []
			creation_host = "debian8"
			creation_time = 1445515921	# 2015-10-22 14:12:01 +0200
			segment_count = 1

			segment1 {
				start_extent = 0
				extent_count = 13	# 104 Megabytes

				type = "striped"
				stripe_count = 1	# linear

				stripes = [
					"pv0", 1
				]
			}
		}

		lv2 {
			id = "PLq8Gr-fsBs-2BfK-y832-HgeJ-N3lm-QRPfld"
			status = ["READ", "WRITE", "VISIBLE"]
			flags = []
			creation_host = "debian8"
			creation_time = 1445516579	# 2015-10-22 14:22:59 +0200
			segment_count = 1

			segment1 {
				start_extent = 0
				extent_count = 14	# 112 Megabytes

				type = "striped"
				stripe_count = 2
				stripe_size = 128	# 64 Kilobytes

				stripes = [
					"pv1", 0,
					"pv2", 0
				]
			}
		}
	}
}

Des archives sont créées lors de chaque modification d'un groupe de volumes et elles sont placés dans le répertoire /etc/lvm/archives :

root@debian8:~# ls /etc/lvm/archive/
vg0_00000-919045492.vg	vg0_00003-845034099.vg	vg0_00006-1448503574.vg  vg0_00009-905120123.vg   vg0_00012-1659523787.vg
vg0_00001-296445091.vg	vg0_00004-931677691.vg	vg0_00007-1865951038.vg  vg0_00010-1782755213.vg  vg0_00013-1273577903.vg
vg0_00002-147807785.vg	vg0_00005-852924022.vg	vg0_00008-310650886.vg	 vg0_00011-565385152.vg   vg0_00014-1486245343.vg

La commande vgcfgbackup est utilisée pour sauvegarder les métadonnées manuellement dans le fichier /etc/lvm/backup/nom_du_volume_group :

La commande vgcfgrestore permet de restaurer une sauvegarde. Sans l'option -f pour spécifier la sauvegarde à restaurer, cette commande renvoie la liste des sauvegardes disponibles :

root@debian8:~# vgcfgbackup vg0
  Volume group "vg0" successfully backed up.

Il est aussi possible de modifier l'emplacement de la sauvegarde avec l'option -f de la commande :

root@debian8:~# vgcfgbackup -f /tmp/vg0_backup vg0
  Volume group "vg0" successfully backed up.
root@debian8:~# vgcfgrestore --list vg0
   
  File:		/etc/lvm/archive/vg0_00000-919045492.vg
  Couldn't find device with uuid c4Pt5x-jSBj-yAjS-g3Bk-LTT0-qp1M-G3Rxbd.
  Couldn't find device with uuid vvvGoQ-e0wt-zEwX-p3cP-piFn-2m7G-OreWFX.
  Couldn't find device with uuid onMXRg-NR52-4M28-qIp5-R1Zs-ckPQ-qaACEn.
  VG name:    	vg0
  Description:	Created *before* executing 'vgcreate -s 8M vg0 /dev/sda7 /dev/sda8 /dev/sda10'
  Backup Time:	Thu Oct 22 11:44:22 2015

   
  File:		/etc/lvm/archive/vg0_00001-296445091.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvcreate -L 350 -n lv0 vg0'
  Backup Time:	Thu Oct 22 13:49:04 2015

   
  File:		/etc/lvm/archive/vg0_00002-147807785.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvextend -L +100M /dev/vg0/lv0'
  Backup Time:	Thu Oct 22 13:55:00 2015

   
  File:		/etc/lvm/archive/vg0_00003-845034099.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvcreate -s -L 65M -n testsnap /dev/vg0/lv0'
  Backup Time:	Thu Oct 22 13:58:09 2015

   
  File:		/etc/lvm/archive/vg0_00004-931677691.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvremove /dev/vg0/testsnap'
  Backup Time:	Thu Oct 22 14:03:54 2015

   
  File:		/etc/lvm/archive/vg0_00005-852924022.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvremove /dev/vg0/lv0'
  Backup Time:	Thu Oct 22 14:04:16 2015

   
  File:		/etc/lvm/archive/vg0_00006-1448503574.vg
  VG name:    	vg0
  Description:	Created *before* executing 'vgremove vg0'
  Backup Time:	Thu Oct 22 14:08:11 2015

   
  File:		/etc/lvm/archive/vg0_00007-1865951038.vg
  VG name:    	vg0
  Description:	Created *before* executing 'vgcreate -s 8M vg0 /dev/sda7 /dev/sda8 /dev/sda10'
  Backup Time:	Thu Oct 22 14:11:23 2015

   
  File:		/etc/lvm/archive/vg0_00008-310650886.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvcreate -m 1 -L 100M -n lv1 vg0'
  Backup Time:	Thu Oct 22 14:12:01 2015

   
  File:		/etc/lvm/archive/vg0_00009-905120123.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvconvert -m 0 /dev/vg0/lv1 /dev/sda8'
  Backup Time:	Thu Oct 22 14:15:19 2015

   
  File:		/etc/lvm/archive/vg0_00010-1782755213.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvconvert -m 1 /dev/vg0/lv1'
  Backup Time:	Thu Oct 22 14:16:06 2015

   
  File:		/etc/lvm/archive/vg0_00011-565385152.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvconvert -m 0 /dev/vg0/lv1 /dev/sda8'
  Backup Time:	Thu Oct 22 14:17:01 2015

   
  File:		/etc/lvm/archive/vg0_00012-1659523787.vg
  VG name:    	vg0
  Description:	Created *before* executing 'vgs'
  Backup Time:	Thu Oct 22 14:19:45 2015

   
  File:		/etc/lvm/archive/vg0_00013-1273577903.vg
  VG name:    	vg0
  Description:	Created *before* executing 'vgs'
  Backup Time:	Thu Oct 22 14:19:45 2015

   
  File:		/etc/lvm/archive/vg0_00014-1486245343.vg
  VG name:    	vg0
  Description:	Created *before* executing 'lvcreate -i2 -I64 -n lv2 -L 100M vg0 /dev/sda8 /dev/sda10'
  Backup Time:	Thu Oct 22 14:22:59 2015

   
  File:		/etc/lvm/backup/vg0
  VG name:    	vg0
  Description:	Created *after* executing 'vgcfgbackup vg0'
  Backup Time:	Thu Oct 22 14:27:22 2015

Systèmes de Fichiers Journalisés

Présentation

Un journal est la partie d'un système de fichiers journalisé qui trace les opérations d'écriture tant qu'elles ne sont pas terminées et cela en vue de garantir l'intégrité des données en cas d'arrêt brutal.

L'intérêt est de pouvoir plus facilement et plus rapidement récupérer les données en cas d'arrêt brutal du système d'exploitation (coupure d'alimentation, plantage du système, etc.), alors que les partitions n'ont pas été correctement synchronisées et démontées.

Sans un tel fichier journal, un outil de récupération de données après un arrêt brutal doit parcourir l'intégralité du système de fichier pour vérifier sa cohérence. Lorsque la taille du système de fichiers est importante, cela peut durer très longtemps pour un résultat moins efficace car entraînant des pertes de données.

Linux peut utiliser un des systèmes de fichiers journalisés suivants :

Système de fichier Taille maximum - fichier Taille maximum - système de fichier
Ext3 2 To 32 To
Ext4 16 To 1 EiB
XFS 8 EiB 16 EiB
ReiserFS v3 8 To 16 To
JFS 4 Po 32 Po
Btrfs 16 EiB 16 EiB

A faire : Pour comparer ces six systèmes de fichier, veuillez consulter cette page

Ext3

Ext3 est une évolution de Ext2 et a pour principale différence d'utiliser un fichier journal. Il peut :

  • être utilisé à partir d'une partition Ext2, sans avoir à sauvegarder et à restaurer des données,
  • utiliser tous les utilitaires de maintenance pour les systèmes de fichiers ext2, comme fsck,
  • utiliser le logiciel dump, ce qui n'est pas le cas avec ReiserFS.

Pour plus d'information concernant Ext3, consultez cette page

Gestion d'Ext3

Notez maintenant le numéro de la dernière partition que vous avez précédemment créée :

root@debian8:~# fdisk -l

Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1008b1da

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 19531775 19529728  9.3G 83 Linux
/dev/sda2       19533822 41943039 22409218 10.7G  5 Extended
/dev/sda5       19533824 23437311  3903488  1.9G 82 Linux swap / Solaris
/dev/sda6       23439360 24416255   976896  477M fd Linux raid autodetect
/dev/sda7       24418304 24809471   391168  191M 8e Linux LVM
/dev/sda8       24811520 25397247   585728  286M 8e Linux LVM
/dev/sda9       25399296 26374143   974848  476M fd Linux raid autodetect
/dev/sda10      26376192 27158527   782336  382M 8e Linux LVM
/dev/sda11      27160576 28137471   976896  477M fd Linux raid autodetect
/dev/sda12      28139520 29114367   974848  476M fd Linux raid autodetect
/dev/sda13      29116416 29507583   391168  191M 83 Linux

Disk /dev/mapper/vg0-lv1: 104 MiB, 109051904 bytes, 212992 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/vg0-lv2: 112 MiB, 117440512 bytes, 229376 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 65536 bytes / 131072 bytes

Dans ce cas, il s'agit de /dev/sda13.

Créez un filesystem Ext3 sur /dev/sda13 en utilisant la commande mke2fs -j :

root@debian8:~# mke2fs -j /dev/sda13
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 195584 1k blocks and 48960 inodes
Filesystem UUID: 955fc810-ca1f-4bd9-b71b-4c1f8cf41aea
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

Les options de la commande mke2fs sont :

root@debian8:~# mke2fs --help
mke2fs: invalid option -- '-'
Usage: mke2fs [-c|-l filename] [-b block-size] [-C cluster-size]
	[-i bytes-per-inode] [-I inode-size] [-J journal-options]
	[-G flex-group-size] [-N number-of-inodes]
	[-m reserved-blocks-percentage] [-o creator-os]
	[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
	[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
	[-t fs-type] [-T usage-type ] [-U UUID] [-jnqvDFKSV] device [blocks-count]

Important : Lors de la mise en place d'un filesystem ext2/ext3/ext4, le système réserve 5% de l'espace disque pour root. Sur des disques de grande taille il est parfois préférable de récupérer une partie de cet espace en utilisant la commande tune2fs -m n /dev/sdXY ou n est le nouveau pourcentage à réserver.

LAB #10 - Convertir un Système de Fichiers Ext3 en Ext2

Pour vérifier si un système de fichiers Ext2 est journalisé, utilisez la commande dumpe2fs :

root@debian8:~# dumpe2fs -h /dev/sda13
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          955fc810-ca1f-4bd9-b71b-4c1f8cf41aea
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype sparse_super
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              48960
Block count:              195584
Reserved block count:     9779
Free blocks:              183740
Free inodes:              48949
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      256
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         2040
Inode blocks per group:   255
Filesystem created:       Thu Oct 22 15:31:22 2015
Last mount time:          n/a
Last write time:          Thu Oct 22 15:31:22 2015
Mount count:              0
Maximum mount count:      -1
Last checked:             Thu Oct 22 15:31:22 2015
Check interval:           0 (<none>)
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          128
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      5a87e558-f510-4ec5-8c63-de8c025def85
Journal backup:           inode blocks
Journal features:         (none)
Journal size:             4113k
Journal length:           4096
Journal sequence:         0x00000001
Journal start:            0

Important : Le drapeau Filesystem features: has_journal … démontre que Ext3 est utilisé sur cette partition.

Les options de cette commande sont :

root@debian8:~# dumpe2fs --help
dumpe2fs 1.42.12 (29-Aug-2014)
dumpe2fs: invalid option -- '-'
Usage: dumpe2fs [-bfhixV] [-o superblock=<num>] [-o blocksize=<num>] device

Pour supprimer Ext3 sur cette partition, il convient d'utiliser la commande tune2fs

root@debian8:~# tune2fs -O ^has_journal /dev/sda13
tune2fs 1.42.12 (29-Aug-2014)

Les options de cette commande sont :

root@debian8:~# tune2fs --help
tune2fs 1.42.12 (29-Aug-2014)
tune2fs: invalid option -- '-'
Usage: tune2fs [-c max_mounts_count] [-e errors_behavior] [-g group]
	[-i interval[d|m|w]] [-j] [-J journal_options] [-l]
	[-m reserved_blocks_percent] [-o [^]mount_options[,...]] [-p mmp_update_interval]
	[-r reserved_blocks_count] [-u user] [-C mount_count] [-L volume_label]
	[-M last_mounted_dir] [-O [^]feature[,...]]
	[-Q quota_options]
	[-E extended-option[,...]] [-T last_check_time] [-U UUID]
	[ -I new_inode_size ] device

Constatez le résultat de cette commande :

root@debian8:~# dumpe2fs -h /dev/sda13
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          955fc810-ca1f-4bd9-b71b-4c1f8cf41aea
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      ext_attr resize_inode dir_index filetype sparse_super
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              48960
Block count:              195584
Reserved block count:     9779
Free blocks:              187853
Free inodes:              48949
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      256
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         2040
Inode blocks per group:   255
Filesystem created:       Thu Oct 22 15:31:22 2015
Last mount time:          n/a
Last write time:          Thu Oct 22 15:34:23 2015
Mount count:              0
Maximum mount count:      -1
Last checked:             Thu Oct 22 15:31:22 2015
Check interval:           0 (<none>)
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          128
Default directory hash:   half_md4
Directory Hash Seed:      5a87e558-f510-4ec5-8c63-de8c025def85
Journal backup:           inode blocks

Important : Notez que le drapeau Filesystem features: has_journal … a été supprimé.

Supprimez maintenant l'inode du journal :

root@debian8:~# fsck /dev/sda13
fsck from util-linux 2.25.2
e2fsck 1.42.12 (29-Aug-2014)
/dev/sda13: clean, 11/48960 files, 7731/195584 blocks

Créez un point de montage pour /dev/sda13 :

root@debian8:~# mkdir /mnt/sda13

Essayez de monter /dev/sda13 en tant que système de fichiers Ext3. Vous obtiendrez un résultat similaire à celui-ci :

root@debian8:~# mount -t ext3 /dev/sda13 /mnt/sda13
mount: wrong fs type, bad option, bad superblock on /dev/sda13,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

Important : Notez l'erreur due au mauvais système de fichiers qui suit l'option -t.

Montez maintenant le système de fichiers en tant que Ext2 :

root@debian8:~# mount -t ext2 /dev/sda13 /mnt/sda13
root@debian8:~# 

LAB #11 - Convertir un Système de Fichiers Ext2 en Ext3

Pour replacer le journal sur /dev/sda13, il convient d'utiliser la commande tune2fs :

root@debian8:~# umount /mnt/sda13

root@debian8:~# tune2fs -j /dev/sda13
tune2fs 1.42.12 (29-Aug-2014)
Creating journal inode: done

Important : Notez que vous avez du démonter la partition avant d'exécuter la commande tune2fs.

LAB #12 - Placer le Journal sur un autre Partition

Le journal d'un système de fichiers peut être placé sur un autre périphérique bloc.

Créez un système de fichiers sur /dev/sda12 :

root@debian8:~# mke2fs -O journal_dev /dev/sda12
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 487424 1k blocks and 0 inodes
Filesystem UUID: afc7fa56-461a-469b-b3fa-44f3dab662dc
Superblock backups stored on blocks: 

Zeroing journal device: root@debian8:~# 

Important : Notez l'utilisation de l'option -O.

Créez maintenant un système de fichiers Ext3 sur /dev/sda13 en plaçant le journal sur /dev/sda12 :

                     
root@debian8:~# mke2fs -j -J device=/dev/sda12 /dev/sda13
mke2fs 1.42.12 (29-Aug-2014)
Using journal device's blocksize: 1024
/dev/sda13 contains a ext3 file system
	last mounted on Fri Oct 23 09:45:20 2015
Proceed anyway? (y,n) y
Creating filesystem with 195584 1k blocks and 48960 inodes
Filesystem UUID: 7576f36e-5e43-484c-868a-e63da2d7a068
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Adding journal to device /dev/sda12: done
Writing superblocks and filesystem accounting information: done  

Important : Notez que le journal a été placé sur /dev/sda11 et /dev/sda12 graĉe à l'utilisation de l'option -J.

LAB #13 - Modifier la Fréquence de Vérification du Système de Fichiers Ext3

Pour modifiez la fréquence de vérification du système de fichiers sur /dev/sda13, il convient d'utiliser soit l'option -c, soit l'option -i :

root@debian8:~# tune2fs -i 100d /dev/sda13
tune2fs 1.42.12 (29-Aug-2014)
Setting interval between checks to 8640000 seconds

Dernièrement, pour obtenir seul l'UUID du système de fichiers, utilisez les commandes dumpe2fs et grep :

root@debian8:~# dumpe2fs /dev/sda13 | grep UUID
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem UUID:          7576f36e-5e43-484c-868a-e63da2d7a068
Journal UUID:             afc7fa56-461a-469b-b3fa-44f3dab662dc

Ext4

Le système de fichiers Ext4 fut introduit dans le noyau 2.6.19 en mode expérimental et est devenu stable dans le noyau 2.6.28.

Ext4 n'est pas une évolution de Ext3. Cependant il a une compatibilité ascendante avec Ext3.

Les fonctionnalités majeures d'Ext4 sont :

  • la gestion des volumes d'une taille allant jusqu'à 1 024 pébioctets,
  • l'allocation par extents qui permettent la pré-allocation d'une zone contiguë pour un fichier afin de minimiser la fragmentation.

L'option extents est activée par défaut depuis le noyau 2.6.23.

La compatibilité ascendante avec ext3 comprend :

  • la possibilité de monter une partition Ext3 en tant que partition Ext4,
  • la possibilité de monter une partition Ext4 en tant que partition Ext3 mais uniquement dans le cas où la partition Ext4 n'ait jamais utilisé l'allocation par extents pour enregistrer des fichiers, mais l'allocation binaire comprise par ext3.

Pour plus d'informations concernant Ext4, consultez cette page.

LAB #14 - Créer un Système de Fichiers Ext4

Créez un système de fichiers Ext4 sur /dev/sda12 :

root@debian8:~# mkfs.ext4 /dev/sda12
mke2fs 1.42.12 (29-Aug-2014)
/dev/sda12 contains a jbd file system
Proceed anyway? (y,n) y
Creating filesystem with 487424 1k blocks and 121920 inodes
Filesystem UUID: 93bcb045-0c3a-4b26-8407-6b33c84ba4cb
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done  

Les options de cette commande sont :

root@debian8:~# mkfs.ext4 --help
mkfs.ext4: invalid option -- '-'
Usage: mkfs.ext4 [-c|-l filename] [-b block-size] [-C cluster-size]
	[-i bytes-per-inode] [-I inode-size] [-J journal-options]
	[-G flex-group-size] [-N number-of-inodes]
	[-m reserved-blocks-percentage] [-o creator-os]
	[-g blocks-per-group] [-L volume-label] [-M last-mounted-directory]
	[-O feature[,...]] [-r fs-revision] [-E extended-option[,...]]
	[-t fs-type] [-T usage-type ] [-U UUID] [-jnqvDFKSV] device [blocks-count]

Consultez maintenant les caractéristiques du système de fichier :

root@debian8:~# dumpe2fs /dev/sda12 | more
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          93bcb045-0c3a-4b26-8407-6b33c84ba4cb
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              121920
Block count:              487424
Reserved block count:     24371
Free blocks:              461526
Free inodes:              121909
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      256
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         2032
Inode blocks per group:   254
Flex block group size:    16
Filesystem created:       Fri Oct 23 09:57:16 2015
Last mount time:          n/a
Last write time:          Fri Oct 23 09:57:16 2015
Mount count:              0
--More--

LAB #15 - Ajouter une Etiquette au Système de Fichiers Ext4

Utilisez la commande e2label pour associer une étiquette au système de fichiers :

root@debian8:~# e2label /dev/sda12 my_ext4
root@debian8:~# dumpe2fs /dev/sda12 | more
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem volume name:   my_ext4
Last mounted on:          <not available>
Filesystem UUID:          93bcb045-0c3a-4b26-8407-6b33c84ba4cb
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              121920
Block count:              487424
Reserved block count:     24371
Free blocks:              461526
Free inodes:              121909
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      256
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         2032
Inode blocks per group:   254
Flex block group size:    16
Filesystem created:       Fri Oct 23 09:57:16 2015
Last mount time:          n/a
Last write time:          Fri Oct 23 10:00:09 2015
Mount count:              0
--More--

Important - Notez que l'étiquette doit être de 16 caractères maximum.

Créez un point de montage dans /mnt et essayez de monter /dev/sda12 en tant qu'Ext3 :

root@debian8:~# mkdir /mnt/sda12

root@debian8:~# mount -t ext3 /dev/sda12 /mnt/sda12
mount: wrong fs type, bad option, bad superblock on /dev/sda12,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

Important - Notez l'erreur qui est signalée.

Montez de nouveau la partition sans stipuler le type de système de fichiers :

root@debian8:~# mount /dev/sda12 /mnt/sda12

root@debian8:~# mount | grep sda12
/dev/sda12 on /mnt/sda12 type ext4 (rw,relatime,data=ordered)

Important - Constatez que la partition a été monté en tant qu'Ext4.

LAB #16 - Convertir un Système de Fichiers Ext3 en Ext4

Créez un système de fichiers ext3 sur /dev/sda13 :

root@debian8:~# mkfs.ext3 /dev/sda13
mke2fs 1.42.12 (29-Aug-2014)
/dev/sda13 contains a ext3 file system
	created on Fri Oct 23 09:52:56 2015
Proceed anyway? (y,n) y
Creating filesystem with 195584 1k blocks and 48960 inodes
Filesystem UUID: 637d05dc-c5df-4785-89a0-37138ff94ce5
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

Montez maintenant /dev/sda13 sur /mnt/sda13 :

root@debian8:~# mount /dev/sda13 /mnt/sda13

root@debian8:~# ls -l /mnt/sda13
total 12
drwx------ 2 root root 12288 Oct 23 10:18 lost+found

Créez le fichier /mnt/sda13/check_file :

root@debian8:~# touch /mnt/sda13/check_file

Injectez la chaine check file dans le fichier /mnt/sda13/check_file puis démontez /dev/sda13 :

root@debian8:~# echo "check file" > /mnt/sda13/check_file

root@debian8:~# umount /mnt/sda13

Exécutez e2fsck sur /dev/sda13 :

root@debian8:~# e2fsck /dev/sda13
e2fsck 1.42.12 (29-Aug-2014)
/dev/sda13: clean, 12/48960 files, 11845/195584 blocks

Convertissez /dev/sda13 en Ext4 :

root@debian8:~# tune2fs -O extents,uninit_bg,dir_index /dev/sda13
tune2fs 1.42.12 (29-Aug-2014)

Optimisez le système de fichiers :

root@debian8:~# e2fsck -fDC0 /dev/sda13
e2fsck 1.42.12 (29-Aug-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure                                           
Pass 3: Checking directory connectivity
Pass 3A: Optimizing directories
Pass 4: Checking reference counts
Pass 5: Checking group summary information
                                                                                
/dev/sda13: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda13: 12/48960 files (0.0% non-contiguous), 11845/195584 blocks

Essayez de monter /dev/sda13 en tant qu'Ext3 :

root@debian8:~# mount -t ext3 /dev/sda13 /mnt/sda13
mount: wrong fs type, bad option, bad superblock on /dev/sda13,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

Montez /dev/sda13 sans spécifier le type de fichiers Ext3 et vérifiez le contenu du fichier check_file :

root@debian8:~# mount /dev/sda13 /mnt/sda13

root@debian8:~# ls -l /mnt/sda13
total 13
-rw-r--r-- 1 root root    11 Oct 23 10:20 check_file
drwx------ 2 root root 12288 Oct 23 10:18 lost+found

root@debian8:~# cat /mnt/sda13/check_file
check file

Dernièrement, pour obtenir seul l'UUID du système de fichiers, utilisez les commandes dumpe2fs et grep :

root@debian8:~# dumpe2fs /dev/sda12 | grep UUID
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem UUID:          93bcb045-0c3a-4b26-8407-6b33c84ba4cb

root@debian8:~# dumpe2fs /dev/sda13 | grep UUID
dumpe2fs 1.42.12 (29-Aug-2014)
Filesystem UUID:          637d05dc-c5df-4785-89a0-37138ff94ce5

XFS

XFS est un système de fichiers 64-bit journalisé de haute performance crée par SGI pour son système d'exploitation IRIX. XFS est inclus par défaut avec les versions du noyau Linux 2.5.xx et 2.6.xx. XFS est le système de fichiers par défaut de RHEL/CentOS 7.

Debian propose aussi une version 32 bits du système de fichiers XFS.

Pour plus d'informations concernant XFS, consultez cette page.

LAB #17 - Créer un Système de Fichiers XFS

Installez le paquet xfsprogs :

root@debian8:~# apt-get install xfsprogs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
Suggested packages:
  xfsdump attr quota
The following NEW packages will be installed:
  xfsprogs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 721 kB of archives.
After this operation, 3,851 kB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main xfsprogs i386 3.2.1 [721 kB]
Fetched 721 kB in 11s (61.9 kB/s) 
Selecting previously unselected package xfsprogs.
(Reading database ... 159613 files and directories currently installed.)
Preparing to unpack .../xfsprogs_3.2.1_i386.deb ...
Unpacking xfsprogs (3.2.1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up xfsprogs (3.2.1) ...
Processing triggers for libc-bin (2.19-18+deb8u1) ...

Créez un système de fichiers XFS sur la partition /dev/sda11 :

root@debian8:~# mkfs.xfs /dev/sda11
meta-data=/dev/sda11             isize=256    agcount=4, agsize=30528 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=122112, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Les options de cette commande sont :

root@debian8:~# mkfs.xfs --help
mkfs.xfs: invalid option -- '-'
unknown option -- 
Usage: mkfs.xfs
/* blocksize */		[-b log=n|size=num]
/* metadata */		[-m crc=0|1,finobt=0|1]
/* data subvol */	[-d agcount=n,agsize=n,file,name=xxx,size=num,
			    (sunit=value,swidth=value|su=num,sw=num|noalign),
			    sectlog=n|sectsize=num
/* force overwrite */	[-f]
/* inode size */	[-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
			    projid32bit=0|1]
/* no discard */	[-K]
/* log subvol */	[-l agnum=n,internal,size=num,logdev=xxx,version=n
			    sunit=value|su=num,sectlog=n|sectsize=num,
			    lazy-count=0|1]
/* label */		[-L label (maximum 12 characters)]
/* naming */		[-n log=n|size=num,version=2|ci,ftype=0|1]
/* no-op info only */	[-N]
/* prototype file */	[-p fname]
/* quiet */		[-q]
/* realtime subvol */	[-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */	[-s log=n|size=num]
/* version */		[-V]
			devicename
<devicename> is required unless -d name=xxx is given.
<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),
      xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
<value> is xxx (512 byte blocks).

Consultez maintenant les caractéristiques du système de fichier :

root@debian8:~# xfs_info /dev/sda11
xfs_info: /dev/sda11 is not a mounted XFS filesystem

root@debian8:~# mkdir /mnt/sda11

root@debian8:~# mount -t xfs /dev/sda11 /mnt/sda11

root@debian8:~# xfs_info /dev/sda11
meta-data=/dev/sda11             isize=256    agcount=4, agsize=30528 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=122112, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Notez que la partition XFS doit être monté pour pouvoir utiliser la commande xfs_info.

Les options de cette commande sont :

root@debian8:~# xfs_info --help
Illegal option --
Usage: xfs_info [-V] [-t mtab] mountpoint

LAB #18 - Ajouter une Etiquette au Système de Fichiers XFS

Utilisez la commande xfs_admin pour associer une étiquette au système de fichiers :

root@debian8:~# xfs_admin -L my_xfs /dev/sda11
xfs_admin: /dev/sda11 contains a mounted filesystem

fatal error -- couldn't initialize XFS library

root@debian8:~# umount /dev/sda11

root@debian8:~# xfs_admin -L my_xfs /dev/sda11
writing all SBs
new label = "my_xfs"

Notez que la partition XFS doit être démonté pour pouvoir utiliser la commande xfs_admin.

Pour voir l'étiquette, utilisez la commande suivante :

root@debian8:~# xfs_admin -l /dev/sda11
label = "my_xfs"

Notez que l'étiquette doit être de 12 caractères maximum.

Les options de cette commande sont :

root@debian8:~# xfs_admin --help
Illegal option --
Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-U uuid] device

Dernièrement, pour obtenir seul l'UUID du système de fichiers, utilisez la commande xfs-admin et l'option -u :

root@debian8:~# xfs_admin -u /dev/sda11
UUID = 07e8787d-23d6-451e-9bb7-e3d02ae2f075

Important - La commande xfs_metadump est utilisée pour sauvegarder les méta-données du système de fichiers, tandis que la commande xfs_mdrestore est utilisée pour restaurer les les méta-données du système de fichiers.

Important - Veuillez noter que le support des systèmes de fichiers ReiserFS, JFS et Btrfs est absent du noyau des distributions de Red Hat. Pour cette raison, l'étude de ces trois systèmes de fichiers doit être faite en utilisant la VM Debian 8.

ReiserFS

ReiserFS permet :

  • de meilleurs temps d'accès à des sous-répertoires que Ext3, même ceux contenant des dizaines de milliers de fichiers,
  • une plus grande efficacité pour ce qui concerne le stockage des fichiers moins de quelques ko. Le gain d'espace peut aller jusqu'à 10% par rapport à Ext2/Ext3.

Pour plus d'informations concernant ReiserFS, consultez cette page.

Avant de continuer, installer le paquet reiserfsprogs :

root@debian8:~# apt-get install reiserfsprogs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following NEW packages will be installed:
  reiserfsprogs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 229 kB of archives.
After this operation, 1,103 kB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main reiserfsprogs i386 1:3.6.24-1 [229 kB]
Fetched 229 kB in 0s (324 kB/s)       
Selecting previously unselected package reiserfsprogs.
(Reading database ... 159667 files and directories currently installed.)
Preparing to unpack .../reiserfsprogs_1%3a3.6.24-1_i386.deb ...
Unpacking reiserfsprogs (1:3.6.24-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up reiserfsprogs (1:3.6.24-1) ...

LAB #19 - Créer un Système de Fichiers ReiserFS

Créez un système de fichiers ReiserFS sur la partition /dev/sda9 :

root@debian8:~# mkfs.reiserfs /dev/sda9
mkfs.reiserfs 3.6.24

Guessing about desired format.. Kernel 3.16.0-4-586 is running.
Format 3.6 with standard journal
Count of blocks on the device: 121856
Number of blocks consumed by mkreiserfs formatting process: 8215
Blocksize: 4096
Hash function used to sort names: "r5"
Journal Size 8193 blocks (first block 18)
Journal Max transaction length 1024
inode generation number: 0
UUID: 19ef2a56-7b36-4c8c-a5f9-420cf95bf87f
ATTENTION: YOU SHOULD REBOOT AFTER FDISK!
	ALL DATA WILL BE LOST ON '/dev/sda9'!
Continue (y/n):y
Initializing journal - 0%....20%....40%....60%....80%....100%
Syncing..ok
ReiserFS is successfully created on /dev/sda9.

Les options de cette commande sont :

root@debian8:~# mkfs.reiserfs --help
mkfs.reiserfs: unrecognized option '--help'
Usage: mkfs.reiserfs [options]  device [block-count]

Options:

  -b | --block-size N              size of file-system block, in bytes
  -j | --journal-device FILE       path to separate device to hold journal
  -s | --journal-size N            size of the journal in blocks
  -o | --journal-offset N          offset of the journal from the start of
                                   the separate device, in blocks
  -t | --transaction-max-size N    maximal size of transaction, in blocks
  -B | --badblocks file            store all bad blocks given in file on the fs
  -h | --hash rupasov|tea|r5       hash function to use by default
  -u | --uuid UUID                 store UUID in the superblock
  -l | --label LABEL               store LABEL in the superblock
  --format 3.5|3.6                 old 3.5 format or newer 3.6
  -f | --force                     specified once, make mkreiserfs the whole
                                   disk, not block device or mounted partition;
                                   specified twice, do not ask for confirmation
  -q | --quiet                     quiet work without messages, progress and
                                   questions. Useful if run in a script. For use
                                   by end users only.
  -d | --debug                     print debugging information during mkreiser
  -V                               print version and exit

Consultez maintenant les caractéristiques du système de fichier :

root@debian8:~# debugreiserfs /dev/sda9
debugreiserfs 3.6.24


Filesystem state: consistent

Reiserfs super block in block 16 on 0x809 of format 3.6 with standard journal
Count of blocks on the device: 121856
Number of bitmaps: 4
Blocksize: 4096
Free blocks (count of blocks - used [journal, bitmaps, data, reserved] blocks): 113641
Root block: 8211
Filesystem is clean
Tree height: 2
Hash function used to sort names: "r5"
Objectid map size 2, max 972
Journal parameters:
	Device [0x0]
	Magic [0x4c47fce6]
	Size 8193 blocks (including 1 for journal header) (first block 18)
	Max transaction length 1024 blocks
	Max batch size 900 blocks
	Max commit age 30
Blocks reserved by journal: 0
Fs state field: 0x0:
sb_version: 2
inode generation number: 0
UUID: 19ef2a56-7b36-4c8c-a5f9-420cf95bf87f
LABEL: 
Set flags in SB:
	ATTRIBUTES CLEAN
Mount count: 1
Maximum mount count: 30
Last fsck run: Fri Oct 23 10:52:48 2015
Check interval in days: 180

Les options de cette commande sont :

root@debian8:~# debugreiserfs --help
debugreiserfs: invalid option -- '-'
debugreiserfs: invalid option -- 'h'
debugreiserfs: invalid option -- 'e'
Usage: debugreiserfs [options] device

Options:
  -d		print blocks details of the internal tree
  -D		print blocks details of all used blocks
  -B file	extract list of badblocks
  -m		print bitmap blocks
  -o		print objectid map

  -J		print journal header
  -j filename
		print journal located on the device 'filename'
  		stores the journal in the specified file 'filename.
  -p		send filesystem metadata to stdout
  -u		read stdin and unpack the metadata
  -S		handle all blocks, not only used
  -1 block	block to print
  -q		no speed info
  -V		print version and exit

LAB #20 - Ajouter une Etiquette au Système de Fichiers ReiserFS

Utilisez la commande reiserfstune pour associer une étiquette au système de fichiers :

root@debian8:~# reiserfstune -l my_reiserfs /dev/sda9
reiserfstune: Journal device has not been specified. Assuming journal is on the main device (/dev/sda9).

Current parameters:

Filesystem state: consistent

Reiserfs super block in block 16 on 0x809 of format 3.6 with standard journal
Count of blocks on the device: 121856
Number of bitmaps: 4
Blocksize: 4096
Free blocks (count of blocks - used [journal, bitmaps, data, reserved] blocks): 113641
Root block: 8211
Filesystem is clean
Tree height: 2
Hash function used to sort names: "r5"
Objectid map size 2, max 972
Journal parameters:
	Device [0x0]
	Magic [0x4c47fce6]
	Size 8193 blocks (including 1 for journal header) (first block 18)
	Max transaction length 1024 blocks
	Max batch size 900 blocks
	Max commit age 30
Blocks reserved by journal: 0
Fs state field: 0x0:
sb_version: 2
inode generation number: 0
UUID: 19ef2a56-7b36-4c8c-a5f9-420cf95bf87f
LABEL: my_reiserfs
Set flags in SB:
	ATTRIBUTES CLEAN
Mount count: 1
Maximum mount count: 30
Last fsck run: Fri Oct 23 10:52:48 2015
Check interval in days: 180

Important - Notez que l'étiquette doit être de 16 caractères maximum.

Les options de cette commande sont :

root@debian8:~# reiserfstune --help
reiserfstune: Usage: reiserfstune [options] device [block-count]

Options:

  -j | --journal-device file	current journal device
  --journal-new-device file	new journal device
  -o | --journal-new-offset N	new journal offset in blocks
  -s | --journal-new-size N	new journal size in blocks
  -t | --trans-max-size N	new journal max transaction size in blocks
  --no-journal-available	current journal is not available
  --make-journal-standard	new journal to be standard
  -b | --add-badblocks file	add to bad block list
  -B | --badblocks file		set the bad block list
  -u | --uuid UUID|random	set new UUID
  -l | --label LABEL		set new label
  -f | --force			force tuning, less confirmations
  -c | --check-interval		set interval in days for fsck -a to check,
                       		"disable" to disable check,
                       		or "default" to restore default
  -C | --time-last-checked	set the time the filesystem was last checked
                          	(now or YYYYMMDD[HH[MM[SS]]])
  -m | --max-mnt-count		set maximum number of mounts before fsck -a
                      		checks, "disable" to disable check,
                      		or "default" to restore default
  -M | --mnt-count		set the number of times the filesystem
                  		has been mounted
  -h | --help			print help and exit
  -V				print version and exit

Dernièrement, pour obtenir l'UUID du système de fichiers, utilisez les commandes debugreiserfs et grep :

root@debian8:~# debugreiserfs /dev/sda9 | grep UUID
debugreiserfs 3.6.24

UUID: 19ef2a56-7b36-4c8c-a5f9-420cf95bf87f

JFS

JFS Journaled File System est un système de fichiers journalisé mis au point par IBM et disponible sous licence GPL.

Pour plus d'informations concernant JFS, consultez cette page.

Avant de continuer, installer le paquet jfsutils :

root@debian8:~# apt-get install jfsutils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following NEW packages will be installed:
  jfsutils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 292 kB of archives.
After this operation, 1,128 kB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main jfsutils i386 1.1.15-2.1 [292 kB]
Fetched 292 kB in 0s (308 kB/s)
Selecting previously unselected package jfsutils.
(Reading database ... 159695 files and directories currently installed.)
Preparing to unpack .../jfsutils_1.1.15-2.1_i386.deb ...
Unpacking jfsutils (1.1.15-2.1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up jfsutils (1.1.15-2.1) ...

LAB #21 - Créer un Système de Fichiers JFS

Créez un système de fichiers JFS sur /dev/sda6 :

root@debian8:~# mkfs.jfs /dev/sda6
mkfs.jfs version 1.1.15, 04-Mar-2011
Warning!  All data on device /dev/sda6 will be lost!

Continue? (Y/N) y
   |

Format completed successfully.

488448 kilobytes total disk space.

Les options de cette commande sont :

root@debian8:~# mkfs.jfs --help
mkfs.jfs version 1.1.15, 04-Mar-2011
mkfs.jfs: invalid option -- '-'

Usage:  mkfs.jfs [-cOqV] [-j log_device] [-J options] [-L vol_label] [-s log_size] device [ blocks ]

Emergency help:
 -c            Check device for bad blocks before building file system.
 -O            Provide case-insensitive support for OS/2 compatability.
 -q            Quiet execution.
 -V            Print version information only.
 -j log_device Set external journal device.
 -J options    Set external journal options.
 -L vol_label  Set volume label for the file system.
 -s log_size   Set log size (in megabytes).

NOTE: -j and -J cannot be used at the same time.

Consultez maintenant les caractéristiques du système de fichier :

root@debian8:~# jfs_tune -l /dev/sda6
jfs_tune version 1.1.15, 04-Mar-2011

JFS filesystem superblock:

JFS magic number:	'JFS1'
JFS version:		1
JFS state:		clean
JFS flags:		JFS_LINUX  JFS_COMMIT  JFS_GROUPCOMMIT  JFS_INLINELOG  
Aggregate block size:	4096 bytes
Aggregate size:		972360 blocks
Physical block size:	512 bytes
Allocation group size:	8192 aggregate blocks
Log device number:	0x0
Filesystem creation:	Fri Oct 23 11:00:25 2015
Volume label:		''

Les options de cette commande sont :

root@debian8:~# jfs_tune --help
jfs_tune version 1.1.15, 04-Mar-2011
jfs_tune: invalid option -- '-'

Usage:  jfs_tune [-J options] [-l] [-L vol_label] [-U uuid] [-V] device

Emergency help:
 -J options    Set external journal options.
 -l            Display superblock
 -L vol_label  Set volume label.
 -U uuid       Set UUID.
 -V            Print version information only.

LAB #22 - Ajouter une Etiquette au Système de Fichiers JFS

Utilisez la commande jfs_tune pour associer une étiquette au système de fichiers :

root@debian8:~# jfs_tune -L my_jfs /dev/sda6
jfs_tune version 1.1.15, 04-Mar-2011
Volume label updated successfully.

root@debian8:~# jfs_tune -l /dev/sda6
jfs_tune version 1.1.15, 04-Mar-2011

JFS filesystem superblock:

JFS magic number:	'JFS1'
JFS version:		1
JFS state:		clean
JFS flags:		JFS_LINUX  JFS_COMMIT  JFS_GROUPCOMMIT  JFS_INLINELOG  
Aggregate block size:	4096 bytes
Aggregate size:		972360 blocks
Physical block size:	512 bytes
Allocation group size:	8192 aggregate blocks
Log device number:	0x0
Filesystem creation:	Fri Oct 23 11:00:25 2015
Volume label:		'my_jfs'

Notez que l'étiquette doit être de 16 caractères maximum.

Créez maintenant un UUID pour le système de fichiers :

root@debian8:~# jfs_tune -U random /dev/sda6
jfs_tune version 1.1.15, 04-Mar-2011
UUID updated successfully.

Dernièrement, pour visualiser l'UUID du système de fichiers, utilisez les commandes jfs_tune et grep :

root@debian8:~# jfs_tune -l /dev/sda6 | grep UUID
File system UUID:	5a98ef13-e89f-4b00-addc-f6477e3747e2
External log UUID:	00000000-0000-0000-0000-000000000000

Btrfs

Btrfs, (B-tree file system, prononcé ButterFS) est un système de fichiers expérimental basé sur la copie sur écriture sous licence GNU GPL, développé principalement par Oracle, Red Hat, Fujitsu, Intel, SUSE et STRATO AG, qui s'inspire grandement du système de fichiers ZFS utilisé par Solaris.

A noter sont les points suivants :

  • Btrfs utilise des extents,
  • Btrfs stocke les données des très petits fichiers directement dans l'extent du fichier répertoire, et non dans un extent séparé,
  • Btrfs gère une notion de « sous-volumes » permettant ainsi des snapshots,
  • Btrfs possède ses techniques propres de protection des données,
  • Btrfs permet de redimensionner à chaud la taille du système de fichiers,
  • Btrfs gère le RAID 0 ainsi que le RAID 1 logiciel,
  • Btrfs gère la comprssion du système de fichiers.

Avant de continuer, installer le paquet btrfs-tools :

root@debian8:~# apt-get install btrfs-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following NEW packages will be installed:
  btrfs-tools
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 460 kB of archives.
After this operation, 3,227 kB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main btrfs-tools i386 3.17-1.1 [460 kB]
Fetched 460 kB in 1s (400 kB/s)      
Selecting previously unselected package btrfs-tools.
(Reading database ... 159719 files and directories currently installed.)
Preparing to unpack .../btrfs-tools_3.17-1.1_i386.deb ...
Unpacking btrfs-tools (3.17-1.1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up btrfs-tools (3.17-1.1) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.120) ...
update-initramfs: Generating /boot/initrd.img-3.16.0-4-586
Processing triggers for libc-bin (2.19-18+deb8u1) ...

LAB #23 - Créer un Système de Fichiers Btrfs

Créez un système de fichiers Btrfs sur /dev/mapper/vg0-lv1 :

root@debian8:~# mkfs.btrfs /dev/mapper/vg0-lv1
SMALL VOLUME: forcing mixed metadata/data groups
Btrfs v3.17
See http://btrfs.wiki.kernel.org for more information.

Turning ON incompat feature 'mixed-bg': mixed data and metadata block groups
Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Created a data/metadata chunk of size 8388608
fs created label (null) on /dev/mapper/vg0-lv1
	nodesize 4096 leafsize 4096 sectorsize 4096 size 104.00MiB

Les options de cette commande sont :

root@debian8:~# mkfs.btrfs --help
mkfs.btrfs: unrecognized option '--help'
usage: mkfs.btrfs [options] dev [ dev ... ]
options:
	 -A --alloc-start the offset to start the FS
	 -b --byte-count total number of bytes in the FS
	 -d --data data profile, raid0, raid1, raid5, raid6, raid10, dup or single
	 -f --force force overwrite of existing filesystem
	 -l --leafsize size of btree leaves
	 -L --label set a label
	 -m --metadata metadata profile, values like data profile
	 -M --mixed mix metadata and data together
	 -n --nodesize size of btree nodes
	 -s --sectorsize min block allocation (may not mountable by current kernel)
	 -r --rootdir the source directory
	 -K --nodiscard do not perform whole device TRIM
	 -O --features comma separated list of filesystem features
	 -U --uuid specify the filesystem UUID
	 -V --version print the mkfs.btrfs version and exit
Btrfs v3.17

Montez la partition btrfs sur /mnt :

root@debian8:~# mount -t btrfs /dev/vg0/lv1 /mnt/
root@debian8:~# mount | grep btrfs
/dev/mapper/vg0-lv1 on /mnt type btrfs (rw,relatime,space_cache)

Sous Btrfs, il est possible de créer des sous volumes. Pour comprendre, comparez notre partition Btrfs à un VG et des sous volumes comme des LV :

root@debian8:~# btrfs subvolume create /mnt/volume1
Create subvolume '/mnt/volume1'
root@debian8:~# btrfs subvolume list /mnt/
ID 256 gen 6 top level 5 path volume1
root@debian8:~# ls -l /mnt
total 0
drwxr-xr-x 1 root root 0 Oct 23 11:50 volume1

Important - L'ID identifie le volume d'une manière unique.

LAB #24 - Convertir un Système de Fichiers Ext4 en Brtfs

Agrandisez le volume logique /dev/vg0/lv2 :

root@debian8:~# lvextend -L +600M /dev/vg0/lv2
  Using stripesize of last segment 64.00 KiB
  Rounding size (89 extents) up to stripe boundary size for segment (90 extents)
  Size of logical volume vg0/lv2 changed from 112.00 MiB (14 extents) to 720.00 MiB (90 extents).
  Logical volume lv2 successfully resized

Créez un système de fichiers Ext4 sur /dev/vg0/lv2 :

root@debian8:~# mkfs.ext4 /dev/vg0/lv2
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 184320 4k blocks and 46080 inodes
Filesystem UUID: 78894e95-7847-419c-b41d-458a1115c5ad
Superblock backups stored on blocks: 
	32768, 98304, 163840

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Convertissez maintenant le systèm de fichiers Ext4 en Btrfs :

root@debian8:~# btrfs-convert /dev/vg0/lv2
creating btrfs metadata.
creating ext2fs image file.
cleaning up system chunk.
conversion complete. 

Visualisez les systèmes de fichiers Btrfs :

root@debian8:~# btrfs filesystem show
Label: none  uuid: c4441ea1-0b4b-4d7a-9777-5663b542c74e
	Total devices 1 FS bytes used 36.00KiB
	devid    1 size 104.00MiB used 12.00MiB path /dev/mapper/vg0-lv1

Label: none  uuid: d24a3b9f-2ebd-4321-a408-91e0fa698f0a
	Total devices 1 FS bytes used 28.08MiB
	devid    1 size 720.00MiB used 720.00MiB path /dev/mapper/vg0-lv2

Btrfs v3.17

Ajouter la partition /dev/vg0/lv2 à /mnt :

root@debian8:~# btrfs device add /dev/vg0/lv2 /mnt/
/dev/vg0/lv2 appears to contain an existing filesystem (btrfs).
Use the -f option to force overwrite.

root@debian8:~# btrfs device add -f /dev/vg0/lv2 /mnt/

root@debian8:~# btrfs filesystem show
Label: none  uuid: c4441ea1-0b4b-4d7a-9777-5663b542c74e
	Total devices 2 FS bytes used 36.00KiB
	devid    1 size 104.00MiB used 12.00MiB path /dev/mapper/vg0-lv1
	devid    2 size 720.00MiB used 0.00B path /dev/mapper/vg0-lv2

Btrfs v3.17

root@debian8:~# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda1            9.1G  4.1G  4.5G  48% /
udev                  10M     0   10M   0% /dev
tmpfs                202M  4.9M  197M   3% /run
tmpfs                505M  220K  504M   1% /dev/shm
tmpfs                5.0M  4.0K  5.0M   1% /run/lock
tmpfs                505M     0  505M   0% /sys/fs/cgroup
tmpfs                101M  8.0K  101M   1% /run/user/119
tmpfs                101M   12K  101M   1% /run/user/1000
/dev/mapper/vg0-lv1  824M   36K  819M   1% /mnt

LAB #25 - Créer un Snapshot

Creéz un snapshot du volume /mnt :

root@debian8:~# btrfs subvolume snapshot /mnt /mnt/snapshot
Create a snapshot of '/mnt' in '/mnt/snapshot'

root@debian8:~# ls -l /mnt
total 4
drwxr-xr-x 1 root root 14 Oct 23 11:47 snapshot
drwxr-xr-x 1 root root  0 Oct 23 11:50 volume1

Démontez le système de fichiers btrfs :

root@debian8:~# umount /mnt

Montez ensuite le snapshot :

root@debian8:~# mount -o subvol=snapshot /dev/vg0/lv1 /mnt/
root@debian8:~# ls -l /mnt
total 0
drwxr-xr-x 1 root root 0 Oct 23 13:46 volume1
root@debian8:~# btrfs filesystem df /mnt/
System, single: total=4.00MiB, used=4.00KiB
Data+Metadata, single: total=8.00MiB, used=44.00KiB
GlobalReserve, single: total=4.00MiB, used=0.00B

LAB #26 - Ajouter une Etiquette au Système de Fichiers Btrfs

Pour voir les caractéristques du système de fichiers Btrfs, utilisez la commande suivante :

root@debian8:~# btrfs-show-super /dev/vg0/lv1
superblock: bytenr=65536, device=/dev/vg0/lv1
---------------------------------------------------------
csum			0xb649976a [match]
bytenr			65536
flags			0x1
magic			_BHRfS_M [match]
fsid			c4441ea1-0b4b-4d7a-9777-5663b542c74e
label			
generation		12
root			4218880
sys_array_size		97
chunk_root_generation	8
root_level		1
chunk_root		135168
chunk_root_level	0
log_root		0
log_root_transid	0
log_root_level		0
total_bytes		864026624
bytes_used		49152
sectorsize		4096
nodesize		4096
leafsize		4096
stripesize		4096
root_dir		6
num_devices		2
compat_flags		0x0
compat_ro_flags		0x0
incompat_flags		0x45
			( MIXED_BACKREF |
			  MIXED_GROUPS |
			  EXTENDED_IREF )
csum_type		0
csum_size		4
cache_generation	12
uuid_tree_generation	12
dev_item.uuid		0eeb0660-05cc-400c-89be-a26210567872
dev_item.fsid		c4441ea1-0b4b-4d7a-9777-5663b542c74e [match]
dev_item.type		0
dev_item.total_bytes	109051904
dev_item.bytes_used	12582912
dev_item.io_align	4096
dev_item.io_width	4096
dev_item.sector_size	4096
dev_item.devid		1
dev_item.dev_group	0
dev_item.seek_speed	0
dev_item.bandwidth	0
dev_item.generation	0

Créez un une etiquette avec la commande btrfs filesystem label :

root@debian8:~# btrfs filesystem label /mnt my_btrfs
root@debian8:~# btrfs-show-super /dev/vg0/lv1
superblock: bytenr=65536, device=/dev/vg0/lv1
---------------------------------------------------------
csum			0x1ad1feb0 [match]
bytenr			65536
flags			0x1
magic			_BHRfS_M [match]
fsid			c4441ea1-0b4b-4d7a-9777-5663b542c74e
label			my_btrfs
generation		13
root			4202496
sys_array_size		97
chunk_root_generation	8
root_level		1
chunk_root		135168
chunk_root_level	0
log_root		0
log_root_transid	0
log_root_level		0
total_bytes		864026624
bytes_used		49152
sectorsize		4096
nodesize		4096
leafsize		4096
stripesize		4096
root_dir		6
num_devices		2
compat_flags		0x0
compat_ro_flags		0x0
incompat_flags		0x45
			( MIXED_BACKREF |
			  MIXED_GROUPS |
			  EXTENDED_IREF )
csum_type		0
csum_size		4
cache_generation	13
uuid_tree_generation	13
dev_item.uuid		0eeb0660-05cc-400c-89be-a26210567872
dev_item.fsid		c4441ea1-0b4b-4d7a-9777-5663b542c74e [match]
dev_item.type		0
dev_item.total_bytes	109051904
dev_item.bytes_used	12582912
dev_item.io_align	4096
dev_item.io_width	4096
dev_item.sector_size	4096
dev_item.devid		1
dev_item.dev_group	0
dev_item.seek_speed	0
dev_item.bandwidth	0
dev_item.generation	0

Comparaison des Commandes par Système de Fichiers

Description Ext3 Ext4 XFS ReiserFS JFS Btrfs
Build a Linux filesystem mkfs.ext3 (mke2fs -j) mkfs.ext4 (mke4fs) mkfs.xfs mkfs.reiserfs (mkreiserfs) mkfs.jfs (jfs_mkfs) mkfs.btrfs
Check a Linux filesystem e2fsck e2fsck xfs_check / xfs_repair reiserfsck jfs_fsck btrfsck
Adjust tunable filesystem parameters Linux filesystems tune2fs tune2fs xfs_admin reiserfstune jfs_tune btrfs-show-super, btrfs filesystem show, et btrfs filesystem df
File system resizer resize2fs resize2fs xfs_growfs resize_reiserfs S/O btrfs filesystem resize
Dump filesystem information dumpe2fs dumpe2fs xfs_info / xfs_metadump debugreiserfs jfs_tune btrfstune
File system debugger debugfs debugfs xfs_db debugreiserfs jfs_debugfs btrfs-debug-tree
Change the label on a filesystem e2label e2label xfs_admin reiserfstune jfs_tune btrfs filesystem label

LAB #27 - Créer un Système de Fichiers ISO

Pour créer un fichier ISO à partir d'une arborescence de fichiers, il convient d'utiliser la commande mkisofs :

root@debian8:~# cd /tmp
root@debian8:/tmp#
root@debian8:/tmp# genisoimage -o tmp.iso /tmp
I: -input-charset not specified, using utf-8 (detected in locale settings)
Using SYSTE000.SER for  /systemd-private-955a923939014d9c944629081b295d9b-cups.service-HuvevL (systemd-private-955a923939014d9c944629081b295d9b-colord.service-6FoA2L)
Using SYSTE001.SER for  /systemd-private-955a923939014d9c944629081b295d9b-colord.service-6FoA2L (systemd-private-955a923939014d9c944629081b295d9b-rtkit-daemon.service-lZZmlA)
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 34816
Path table size(bytes): 282
Max brk space used 21000
394 extents written (0 MB)

Le fichier ISO peut être monter en utilisant un périphérique de type loop :

root@debian8:/tmp# mount tmp.iso /mnt -o loop
mount: /dev/loop0 is write-protected, mounting read-only
root@debian8:/tmp# ls -l /mnt
total 428
dr-xr-xr-x 1 root root   2048 Oct 20 10:59 attribut
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 _font_un
-r-xr-xr-x 1 root root 407666 Oct 23 11:05 gestion_.pdf
dr-xr-xr-x 1 root root   2048 Oct 22 09:15 _ice_uni
dr-xr-xr-x 1 root root   2048 Jan  1  1970 orbit_tr
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 pulse_pk
dr-xr-xr-x 1 root root   2048 Oct 22 09:15 ssh_vrxr
dr-xr-xr-x 1 root root   2048 Oct 22 09:19 syste000.ser
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 syste001.ser
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 systemd_.ser
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 _test_un
dr-xr-xr-x 1 root root   2048 Oct 23 14:11 tracker_.100
-r-xr-xr-x 1 root root   2147 Oct 22 14:28 vg0_back
-r-xr-xr-x 1 root root     11 Oct 22 09:14 _x0_lock
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 _x11_uni
dr-xr-xr-x 1 root root   2048 Oct 22 09:14 _xim_uni

Démontez maintenant le fichier ISO :

root@debian8:/tmp# cd ~
root@debian8:~# umount /tmp/tmp.iso

Options de la Commande genisoimage

Les options de cette commande sont :

root@debian8:~# genisoimage --help
Usage: genisoimage [options] file...
Options:
  -nobak                      Do not include backup files
  -no-bak                     Do not include backup files
  -abstract FILE              Set Abstract filename
  -A ID, -appid ID            Set Application ID
  -biblio FILE                Set Bibliographic filename
  -cache-inodes               Cache inodes (needed to detect hard links)
  -no-cache-inodes            Do not cache inodes (if filesystem has no unique unides)
  -check-oldnames             Check all imported ISO9660 names from old session
  -check-session FILE         Check all ISO9660 names from previous session
  -copyright FILE             Set Copyright filename
  -debug                      Set debug flag
  -b FILE, -eltorito-boot FILE
                              Set El Torito boot image name
  -eltorito-alt-boot          Start specifying alternative El Torito boot parameters
  -B FILES, -sparc-boot FILES Set sparc boot image names
  -sunx86-boot FILES          Set sunx86 boot image names
  -G FILE, -generic-boot FILE Set generic boot image name
  -sparc-label label text     Set sparc boot disk label
  -sunx86-label label text    Set sunx86 boot disk label
  -c FILE, -eltorito-catalog FILE
                              Set El Torito boot catalog name
  -C PARAMS, -cdrecord-params PARAMS
                              Magic paramters from cdrecord
  -d, -omit-period            Omit trailing periods from filenames (violates ISO9660)
  -dir-mode mode              Make the mode of all directories this mode.
  -D, -disable-deep-relocation
                              Disable deep directory relocation (violates ISO9660)
  -file-mode mode             Make the mode of all plain files this mode.
  -f, -follow-links           Follow symbolic links
  -gid gid                    Make the group owner of all files this gid.
  -graft-points               Allow to use graft points for filenames
  -root DIR                   Set root directory for all new files and directories
  -old-root DIR               Set root directory in previous session that is searched for files
  -help                       Print option help
  -hide GLOBFILE              Hide ISO9660/RR file
  -hide-list FILE             File with list of ISO9660/RR files to hide
  -hidden GLOBFILE            Set hidden attribute on ISO9660 file
  -hidden-list FILE           File with list of ISO9660 files with hidden attribute
  -hide-joliet GLOBFILE       Hide Joliet file
  -hide-joliet-list FILE      File with list of Joliet files to hide
  -hide-joliet-trans-tbl      Hide TRANS.TBL from Joliet tree
  -hide-rr-moved              Rename RR_MOVED to .rr_moved in Rock Ridge tree
  -gui                        Switch behaviour for GUI
  -i ADD_FILES                No longer supported
  -input-charset CHARSET      Local input charset for file name conversion
  -output-charset CHARSET     Output charset for file name conversion
  -iso-level LEVEL            Set ISO9660 conformance level (1..3) or 4 for ISO9660 version 2
  -J, -joliet                 Generate Joliet directory information
  -joliet-long                Allow Joliet file names to be 103 Unicode characters
  -jcharset CHARSET           Local charset for Joliet directory information
  -l, -full-iso9660-filenames Allow full 31 character filenames for ISO9660 names
  -max-iso9660-filenames      Allow 37 character filenames for ISO9660 names (violates ISO9660)
  -allow-limited-size         Allow different file sizes in ISO9660/UDF on large files
  -allow-leading-dots         Allow ISO9660 filenames to start with '.' (violates ISO9660)
  -ldots                      Allow ISO9660 filenames to start with '.' (violates ISO9660)
  -L, -allow-leading-dots     Allow ISO9660 filenames to start with '.' (violates ISO9660)
  -log-file LOG_FILE          Re-direct messages to LOG_FILE
  -m GLOBFILE, -exclude GLOBFILE
                              Exclude file name
  -exclude-list FILE          File with list of file names to exclude
  -pad                        Pad output to a multiple of 32k (default)
  -no-pad                     Do not pad output to a multiple of 32k
  -M FILE, -prev-session FILE Set path to previous session to merge
  -dev SCSIdev                Set path to previous session to merge
  -N, -omit-version-number    Omit version number from ISO9660 filename (violates ISO9660)
  -new-dir-mode mode          Mode used when creating new directories.
  -force-rr                   Inhibit automatic Rock Ridge detection for previous session
  -no-rr                      Inhibit reading of Rock Ridge attributes from previous session
  -no-split-symlink-components
                              Inhibit splitting symlink components
  -no-split-symlink-fields    Inhibit splitting symlink fields
  -o FILE, -output FILE       Set output file name
  -path-list FILE             File with list of pathnames to process
  -p PREP, -preparer PREP     Set Volume preparer
  -print-size                 Print estimated filesystem size and exit
  -publisher PUB              Set Volume publisher
  -P PUB, -publisher PUB      Set Volume publisher
  -quiet                      Run quietly
  -r, -rational-rock          Generate rationalized Rock Ridge directory information
  -R, -rock                   Generate Rock Ridge directory information
  -s TYPE, -sectype TYPE      Set output sector type to e.g. data/xa1/raw
  -alpha-boot FILE            Set alpha boot image name (relative to image root)
  -hppa-cmdline CMDLINE       Set hppa boot command line (relative to image root)
  -hppa-kernel-32 FILE        Set hppa 32-bit image name (relative to image root)
  -hppa-kernel-64 FILE        Set hppa 64-bit image name (relative to image root)
  -hppa-bootloader FILE       Set hppa boot loader file name (relative to image root)
  -hppa-ramdisk FILE          Set hppa ramdisk file name (relative to image root)
  -mips-boot FILE             Set mips boot image name (relative to image root)
  -mipsel-boot FILE           Set mipsel boot image name (relative to image root)
  -jigdo-jigdo FILE           Produce a jigdo .jigdo file as well as the .iso
  -jigdo-template FILE        Produce a jigdo .template file as well as the .iso
  -jigdo-min-file-size SIZE   Minimum size for a file to be listed in the jigdo file
  -jigdo-force-md5 PATTERN    Pattern(s) where files MUST match an externally-supplied MD5sum
  -jigdo-exclude PATTERN      Pattern(s) to exclude from the jigdo file
  -jigdo-map PATTERN1=PATTERN2
                              Pattern(s) to map paths (e.g. Debian=/mirror/debian)
  -md5-list FILE              File containing MD5 sums of the files that should be checked
  -jigdo-template-compress ALGORITHM
                              Choose to use gzip or bzip2 compression for template data; default is gzip
  -checksum_algorithm_iso alg1,alg2,...
                              Specify the checksum types desired for the output image
  -checksum_algorithm_template alg1,alg2,...
                              Specify the checksum types desired for the output jigdo template
  -sort FILE                  Sort file content locations according to rules in FILE
  -split-output               Split output into files of approx. 1GB size
  -stream-file-name FILE_NAME Set the stream file ISO9660 name (incl. version)
  -stream-media-size #        Set the size of your CD media in sectors
  -sysid ID                   Set System ID
  -T, -translation-table      Generate translation tables for systems that don't understand long filenames
  -table-name TABLE_NAME      Translation table file name
  -ucs-level LEVEL            Set Joliet UCS level (1..3)
  -udf                        Generate UDF file system
  -dvd-video                  Generate DVD-Video compliant UDF file system
  -uid uid                    Make the owner of all files this uid.
  -U, -untranslated-filenames Allow Untranslated filenames (for HPUX & AIX - violates ISO9660). Forces -l, -d, -N, -allow-leading-dots, -relaxed-filenames, -allow-lowercase, -allow-multidot
  -relaxed-filenames          Allow 7 bit ASCII except lower case characters (violates ISO9660)
  -no-iso-translate           Do not translate illegal ISO characters '~', '-' and '#' (violates ISO9660)
  -allow-lowercase            Allow lower case characters in addition to the current character set (violates ISO9660)
  -allow-multidot             Allow more than one dot in filenames (e.g. .tar.gz) (violates ISO9660)
  -use-fileversion LEVEL      Use file version # from filesystem
  -v, -verbose                Verbose
  -version                    Print the current version
  -V ID, -volid ID            Set Volume ID
  -volset ID                  Set Volume set ID
  -volset-size #              Set Volume set size
  -volset-seqno #             Set Volume set sequence number
  -x FILE, -old-exclude FILE  Exclude file name(depreciated)
  -hard-disk-boot             Boot image is a hard disk image
  -no-emul-boot               Boot image is 'no emulation' image
  -no-boot                    Boot image is not bootable
  -boot-load-seg #            Set load segment for boot image
  -boot-load-size #           Set numbers of load sectors
  -boot-info-table            Patch boot image with info table
  -XA                         Generate XA directory attruibutes
  -xa                         Generate rationalized XA directory attruibutes
  -z, -transparent-compression
                              Enable transparent compression of files
  -hfs-type TYPE              Set HFS default TYPE
  -hfs-creator CREATOR        Set HFS default CREATOR
  -g, -apple                  Add Apple ISO9660 extensions
  -h, -hfs                    Create ISO9660/HFS hybrid
  -map MAPPING_FILE           Map file extensions to HFS TYPE/CREATOR
  -H MAPPING_FILE, -map MAPPING_FILE
                              Map file extensions to HFS TYPE/CREATOR
  -magic FILE                 Magic file for HFS TYPE/CREATOR
  -probe                      Probe all files for Apple/Unix file types
  -mac-name                   Use Macintosh name for ISO9660/Joliet/RockRidge file name
  -no-mac-files               Do not look for Unix/Mac files (depreciated)
  -boot-hfs-file FILE         Set HFS boot image name
  -part                       Generate HFS partition table
  -cluster-size SIZE          Cluster size for PC Exchange Macintosh files
  -auto FILE                  Set HFS AutoStart file name
  -no-desktop                 Do not create the HFS (empty) Desktop files
  -hide-hfs GLOBFILE          Hide HFS file
  -hide-hfs-list FILE         List of HFS files to hide
  -hfs-volid HFS_VOLID        Volume name for the HFS partition
  -icon-position              Keep HFS icon position
  -root-info FILE             finderinfo for root folder
  -input-hfs-charset CHARSET  Local input charset for HFS file name conversion
  -output-hfs-charset CHARSET Output charset for HFS file name conversion
  -hfs-unlock                 Leave HFS Volume unlocked
  -hfs-bless FOLDER_NAME      Name of Folder to be blessed
  -hfs-parms PARAMETERS       Comma separated list of HFS parameters
  -prep-boot FILE             PReP boot image file -- up to 4 are allowed
  -chrp-boot                  Add CHRP boot header
  --cap                       Look for AUFS CAP Macintosh files
  --netatalk                  Look for NETATALK Macintosh files
  --double                    Look for AppleDouble Macintosh files
  --ethershare                Look for Helios EtherShare Macintosh files
  --exchange                  Look for PC Exchange Macintosh files
  --sgi                       Look for SGI Macintosh files
  --macbin                    Look for MacBinary Macintosh files
  --single                    Look for AppleSingle Macintosh files
  --ushare                    Look for IPT UShare Macintosh files
  --xinet                     Look for XINET Macintosh files
  --dave                      Look for DAVE Macintosh files
  --sfm                       Look for SFM Macintosh files
  --osx-double                Look for MacOS X AppleDouble Macintosh files
  --osx-hfs                   Look for MacOS X HFS Macintosh files

Report problems to debburn-devel@lists.alioth.debian.org.

Systèmes de Fichiers Chiffrés

LAB #28 - Créer un Système de Fichiers Chiffré avec encryptfs

Commencez par installer le paquet ecryptfs-utils dans la machine virtuelle Debian 8 :

root@debian8:~# apt-get install ecryptfs-utils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  keyutils libecryptfs0 libnss3-1d libtspi1
Suggested packages:
  cryptsetup
The following NEW packages will be installed:
  ecryptfs-utils keyutils libecryptfs0 libnss3-1d libtspi1
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 399 kB of archives.
After this operation, 1,171 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://httpredir.debian.org/debian/ jessie/main libnss3-1d i386 2:3.17.2-1.1+deb8u2 [18.1 kB]           
Get:2 http://httpredir.debian.org/debian/ jessie/main libecryptfs0 i386 103-5 [43.7 kB]                       
Get:3 http://httpredir.debian.org/debian/ jessie/main keyutils i386 1.5.9-5+b1 [53.2 kB]     
Get:4 http://httpredir.debian.org/debian/ jessie/main libtspi1 i386 0.3.13-3 [184 kB]
Get:5 http://httpredir.debian.org/debian/ jessie/main ecryptfs-utils i386 103-5 [99.1 kB]                                                            
Fetched 399 kB in 6s (64.2 kB/s)                                                                                                                     
Selecting previously unselected package libnss3-1d:i386.
(Reading database ... 159789 files and directories currently installed.)
Preparing to unpack .../libnss3-1d_2%3a3.17.2-1.1+deb8u2_i386.deb ...
Unpacking libnss3-1d:i386 (2:3.17.2-1.1+deb8u2) ...
Selecting previously unselected package libecryptfs0.
Preparing to unpack .../libecryptfs0_103-5_i386.deb ...
Unpacking libecryptfs0 (103-5) ...
Selecting previously unselected package libtspi1.
Preparing to unpack .../libtspi1_0.3.13-3_i386.deb ...
Unpacking libtspi1 (0.3.13-3) ...
Selecting previously unselected package keyutils.
Preparing to unpack .../keyutils_1.5.9-5+b1_i386.deb ...
Unpacking keyutils (1.5.9-5+b1) ...
Selecting previously unselected package ecryptfs-utils.
Preparing to unpack .../ecryptfs-utils_103-5_i386.deb ...
Unpacking ecryptfs-utils (103-5) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libnss3-1d:i386 (2:3.17.2-1.1+deb8u2) ...
Setting up libecryptfs0 (103-5) ...
Setting up libtspi1 (0.3.13-3) ...
Setting up keyutils (1.5.9-5+b1) ...
Setting up ecryptfs-utils (103-5) ...
Processing triggers for libc-bin (2.19-18+deb8u1) ...

Si ce n'est pas déjà fait, créez un système de fichiers ext4 sur /dev/sda12 :

root@debian8:/# mkfs.ext4 /dev/sda12

Si ce n'est pas déjà fait, montez /dev/sda12 sur /mnt/sda12 :

root@debian8:/# mkdir /mnt/sda12
root@debian8:/# mount /dev/sda12 /mnt/sda12

Montez maintenant /mnt/sda12 sur lui-même :

root@debian8:/# mount -t ecryptfs /mnt/sda12 /mnt/sda12
Select key type to use for newly created files: 
 1) tspi
 2) passphrase
Selection: 2
Passphrase: 
Select cipher: 
 1) aes: blocksize = 16; min keysize = 16; max keysize = 32
 2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56
 3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24
 4) twofish: blocksize = 16; min keysize = 16; max keysize = 32
 5) cast6: blocksize = 16; min keysize = 16; max keysize = 32
 6) cast5: blocksize = 8; min keysize = 5; max keysize = 16
Selection [aes]: 1
Select key bytes: 
 1) 16
 2) 32
 3) 24
Selection [16]: 1
Enable plaintext passthrough (y/n) [n]: n
Enable filename encryption (y/n) [n]: y
Filename Encryption Key (FNEK) Signature [91aefde99b5a4977]: 
Attempting to mount with the following options:
  ecryptfs_unlink_sigs
  ecryptfs_fnek_sig=91aefde99b5a4977
  ecryptfs_key_bytes=16
  ecryptfs_cipher=aes
  ecryptfs_sig=91aefde99b5a4977
WARNING: Based on the contents of [/root/.ecryptfs/sig-cache.txt],
it looks like you have never mounted with this key 
before. This could mean that you have typed your 
passphrase wrong.

Would you like to proceed with the mount (yes/no)? : yes
Would you like to append sig [91aefde99b5a4977] to
[/root/.ecryptfs/sig-cache.txt] 
in order to avoid this warning in the future (yes/no)? : yes
Successfully appended new sig to user sig cache file
Mounted eCryptfs

Ce montage est visible dans la sortie de la commande df :

root@debian8:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       9.1G  4.1G  4.5G  48% /
udev             10M     0   10M   0% /dev
tmpfs           202M  8.9M  193M   5% /run
tmpfs           505M  220K  504M   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           505M     0  505M   0% /sys/fs/cgroup
tmpfs           101M  8.0K  101M   1% /run/user/119
tmpfs           101M   12K  101M   1% /run/user/1000
/mnt/sda12      453M  2.3M  423M   1% /mnt/sda12
/dev/sda13      181M  1.6M  167M   1% /mnt/sda13

Plus de détails sont visibles avec la commande mount :

root@debian8:/# mount
...
/dev/sda12 on /mnt/sda12 type ext4 (rw,relatime,data=ordered)
/dev/sda13 on /mnt/sda13 type ext4 (rw,relatime,data=ordered)
/mnt/sda12 on /mnt/sda12 type ecryptfs (rw,relatime,ecryptfs_fnek_sig=91aefde99b5a4977,ecryptfs_sig=91aefde99b5a4977,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_unlink_sigs)

Créez maintenant le fichier encrypt contenant la chaîne de caractères fenestros dans /mnt/sda12 :

root@debian8:/# touch /mnt/sda12/encrypt

root@debian8:/# echo "fenestros" > /mnt/sda12/encrypt

root@debian8:/# cat /mnt/sda12/encrypt
fenestros

Démontez maintenant /mnt/sda12 :

root@debian8:/# umount /mnt/sda12

root@debian8:/# mount
...
/dev/sda12 on /mnt/sda12 type ext4 (rw,relatime,data=ordered)
/dev/sda13 on /mnt/sda13 type ext4 (rw,relatime,data=ordered)

Important : Notez que /dev/sda12 est toujours monté sur /mnt/sda12.

Constatez maintenant le contenu de /mnt/sda12 :

root@debian8:/# ls -l /mnt/sda12
total 24
-rw-r--r-- 1 root root 12288 Oct 23 14:52 ECRYPTFS_FNEK_ENCRYPTED.FWaFfjrdapd7RkRCT3OFIdaE.-6mxquDYm8R4p7VFuV0SGgSJauuQJ2hEE--
drwx------ 2 root root 12288 Oct 23 09:57 lost+found

Important : Notez que le nom du fichier encrypt a été chiffré.

Constatez maintenant le contenu du fichier ECRYPTFS_FNEK_ENCRYPTED.FWaFfjrdapd7RkRCT3OFIdaE.-6mxquDYm8R4p7VFuV0SGgSJauuQJ2hEE– :

root@debian8:/# cat /mnt/sda12/ECRYPTFS_FNEK_ENCRYPTED.FWaFfjrdapd7RkRCT3OFIdaE.-6mxquDYm8R4p7VFuV0SGgSJauuQJ2hEE--

w��JKs�
�"3DUfw`޾�xN�:K����A�_CONSOLE�����ZIw�ݏ��J��`��<a���,]H`R)(N�@%^h�U���Z�>��h�I�W�B�ߗH�<��ӣ*X�!Ubo��K⧑���*Ԗ
                                                                                                                     3c����t��[YQ7�ϱ��}+�rp��H9�s���)0��&ƿ���dx-}�qҽX���L�$�����a��R{����{�i|4�O2Fa���A9�����єw�J�d�bQ�⏰��<��zU��W*A{g�`y�O�J��-5h�E����:I/�=L�c�]�h�,xh	̢��ٝ�
                                                                                                                                    �Q���oO���S�$ѧ��&�r����hˇ�9(�d�ה#����
                       6˯�f[��F�^k���d�]ǯ����0�*e�K�hE�
�H#y��zm\�I�%����J/�T�6�:�r�z����                    ��a)]Y$`
                                   |�B��~׻	a�h�L���O����N��=���@8F�T�3"֬v����뎆m���&}q�^[Wmk�Pi
                                                                                                          Ҭei�!���⃧�{�])�Wb�C �]�Db��X�V���;O4���H������r}@�i q\�0<���:�Zc��1T��˾)�of�לcN�0x!L�!�c�I��s�#�LD����$lo�ԋE���i���`�Rl��sU�oF�ׅK��t��*���,����3�����R��r�mA�xa�]]Mb
                                                                                                                                            �u�ժ�Emȭ�2�	��ۋ��� �m��,�C��q��dI�'�fI'A	
�����*S�)sƵ�r)Z�]���/�!��aݠ69KC��s3KE�
                                          яn#�!���R7�L^�d�u�WW2�B�pz�VE��鼹�����Y�-`�'l�{���Ho\x��
70��������e)^��Sz� "fCXjW�up����L�^�wǶ!lк@�e�@�/��ߤ��8S�]�0�a��y��3
                                                                     9��B ��*m
                                                                                ~	�!�\�\eZe��̩"��		ץ�nm�(gg�8/X\�:H�N�ɤ��2��~K@V`ERSģ81kI׽�@�� ^H7�CD&�v�X]xb�iؐ�Rq;�yX�C�J�G�+>1+����v��8�2˧�Q��$k�F?N��,�'��>�'�v�3�3@��%,�#��h��M����@�oH�`H��&>0���v��7!�N�"TJ
                                                  ���5�7@ri)D��EP�V�1p7!{%06�C��k���1bc�Or�
������=Ԫp%%#�<�8�>,2�[���|�u+r6�|�Wf�?.Ш�0�D8ɃȜ'�|gsT�|�̧��
                                                 l�f�(�}�TM�β�#^�`-����\��ޓ�C�<��:���
�VZ��0ܖ,��(̎�3��c���(w����Р�m㎇��R,��08�g���}����#Ү��HBg�p�d�����4D�����!��H
��B�                                       ��kg!��-��R�jt\�s�4�»���	����|2qi�
     e�g���,�?کӛ�oH\:��BB
                         �Y�������U7�
�YdM����鳱]��.,~�61gI6ADO�m�zĩ�Ӵ��룛W��Cї�%BZ�R�6֩����&��G�����ϭ�&�<55J�#h��7/.
Ť��a���)g�$��{d:1V1d䩧������+*�!�R st,׬$𙎨-*�c`g�e{��F��(��5��CQ�����GE���N_ņXB	@�b4��#d)��z��u	���L��&�ӾvuP����1+�yT��$�2i�_������X3ݛ�T�:w����+=��z���)2�Bc��8�i��;����g��pDV�;�x����$p0t��ǂ���(���]F���Ă:���h�y���TV -�c�w�S�l�Ћ�7�\��R����"8)Z����S���v�I�G��{��3
                                                                                                                                                  L����Y?�گUҳ��Rg�t� 恕��c6��k��~']�����„��
3�҃�\W������\��:�r�e�%�J�}N��N�s��"Jc��:��u���yl`��+�
              @x+"��­�����4s\h �jeo�q��K�p��?T�+i������{O�
����Mc���+�5����ƹ�a�g+u�^���
�3,����'5Ї��D�������Ĥ�пV�� K�jX�U�1Cz������{p	}�t�|�9��C���wY�Ox��3��0���6|,�pW�cmʺ���ҋ�@��A��Y���Վ|Uy_�r��8���:��@�o{&Y��;��)U��g�=��΍��v_���>�i��8ʰ3��Hi���
Q�NI��*���m�v�  )����^�b>�v�sx%�p~o���0l4��ę�C��2��(lZfO�c���6cn�q�q�=�N�}���r�L�m����w�}9Y#U�%i0�j�M����we?L�������Y�����yo</����w�I�j����@�3��mP��Z.�<
                     s<ro���\��l�GYõ�Y
�y}�F�z���y�^�10�_�M6�*U�7�A��m4X�h��{���%��>��ЄjP0xZh����տ���ꙺx�*^�p�=�eYB�,ŽK�,1���o׉`e�W �Ę����+� -n񧟭��uG�s"XC,��]J�����XG]y��I�pA���ϛbk[E
�_}:y�Z�j�!�1������\O�S�VTH��|��8��eX�a�S?��L�����֨V�g���	�����[�ַ�4&�t��0 ]�0
                                                                                      F�E���L��{�!�����zDd]������IJ0�ׄu��U�x��h��kx��|�l��s��B"�Mqޢ�z�n��H��f���j��P��|X���y�[���j%����.��FP���H���k5�x�"���
nH^B�s����y���0O������h���CGAFi���$���
u�;՘(Z��n�������
5��>�w6}ɫ�.Ќ<�fs���\�n�?�o�-�D���OZ3w��F7J��I`K�5��
                                                      -�U���;�3f]�a�u�&����M~s��ZI����{�~�B�'�FY�ʥ��+�
��κG���E:gXr���䂸�{��L�NPY��:2-%}�+0ۄ�Z�$��8��O�-���o��Z6�¤m�~ETzM@;�؍0�_���rg�8�!�ۗA��_���}텖��U^[�*A92'�}��[CЗ��;W�u�����c����.�]�����nֆ�����&ɖ��ϐncg�h X�}y^J��z�W�'kH�H]�o}�*yv>V�3�
'�|9.�}(���y�62�A���Z� ��+-1�]dx���#��,vv��^G����s�*�8yzF�[j\"?\��~O��Y�E�F��&#���hv��o[D�root@debian8:/# 

Important : Notez que le contenu du fichier encrypt a été chiffré. Pour pouvoir lire le nom et le contenu de ce fichier de nouveau, il faut remonter /mnt/sda12 en spécifiant les mêmes options ainsi que la même passphrase. Notez que si vous vous trompez au niveau de la passphrase ceci n’empêchera pas le processus de montage. Par contre vous ne pourrez ni lire le nom ni lire le contenu du fichier chiffré.

LAB #29 - Créer un Système de Fichiers Chiffré avec LUKS

Présentation

LUKS ( Linux Unified Key Setup ) permet de chiffrer l'intégralité d'un disque de telle sorte que celui-ci soit utilisable sur d'autres plates-formes et distributions de Linux (voire d'autres systèmes d'exploitation). Il supporte des mots de passe multiples, afin que plusieurs utilisateurs soient en mesure de déchiffrer le même volume sans partager leur mot de passe.

Mise en Place

Commencez par installer le paquet cryptsetup :

root@debian8:/# apt-get install cryptsetup
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  mc-data
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  cryptsetup-bin
The following NEW packages will be installed:
  cryptsetup cryptsetup-bin
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 337 kB of archives.
After this operation, 1,213 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://httpredir.debian.org/debian/ jessie/main cryptsetup-bin i386 2:1.6.6-5 [177 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main cryptsetup i386 2:1.6.6-5 [159 kB]
Fetched 337 kB in 0s (353 kB/s)                                           
Preconfiguring packages ...
Selecting previously unselected package cryptsetup-bin.
(Reading database ... 159901 files and directories currently installed.)
Preparing to unpack .../cryptsetup-bin_2%3a1.6.6-5_i386.deb ...
Unpacking cryptsetup-bin (2:1.6.6-5) ...
Selecting previously unselected package cryptsetup.
Preparing to unpack .../cryptsetup_2%3a1.6.6-5_i386.deb ...
Unpacking cryptsetup (2:1.6.6-5) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for systemd (215-17+deb8u2) ...
Setting up cryptsetup-bin (2:1.6.6-5) ...
Setting up cryptsetup (2:1.6.6-5) ...
update-initramfs: deferring update (trigger activated)
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Processing triggers for systemd (215-17+deb8u2) ...
Processing triggers for initramfs-tools (0.120) ...
update-initramfs: Generating /boot/initrd.img-3.16.0-4-586

Montez /dev/sda11 :

root@debian8:/# mount /dev/sda11 /mnt/sda11

Remplissez la partition /dev/sda11 avec des données aléatoires :

root@debian8:/# shred -v --iterations=1 /dev/sda11
shred: /dev/sda12: pass 1/1 (random)...
shred: /dev/sda12: pass 1/1 (random)...350MiB/476MiB 73%
shred: /dev/sda12: pass 1/1 (random)...476MiB/476MiB 100%

Important : L'étape ci-dessus est très importante parce que elle permet de s'assurer qu'aucune donnée ne reste sur la partition.

Démontez /dev/sda11 :

root@debian8:/# umount /mnt/sda11

Initialisez la partition avec LUKS :

root@debian8:/# cryptsetup --verbose --verify-passphrase luksFormat /dev/sda11

WARNING!
========
This will overwrite data on /dev/sda11 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: fenestros123456789
Verify passphrase: fenestros123456789
Command successful.

Important : La passphrase ne sera pas en claire. Elle l'est ici pour vous montrer un mot de passe acceptable pour LUKS.

Ouvrez la partition LUKS en lui donnant le nom sda11 :

root@debian8:/# cryptsetup luksOpen /dev/sda11 sda11
Enter passphrase for /dev/sda11: fenestros123456789

Vérifiez que le système voit la partition :

root@debian8:/# ls -l /dev/mapper | grep sda11
lrwxrwxrwx 1 root root       7 Oct 23 15:21 sda11 -> ../dm-1

Créez maintenant un système de fichiers sur /dev/mapper/sda11 :

root@debian8:/# mkfs.ext4 /dev/mapper/sda11
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 486400 1k blocks and 121920 inodes
Filesystem UUID: 301680a5-28cd-4a30-99e5-146f1098c195
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done 

Montez la partition LUKS :

root@debian8:/# mount /dev/mapper/sda11 /mnt/sda11

Vérifiez la présence du montage :

root@debian8:/# df -h | grep sda11
/dev/mapper/sda11  452M  2.3M  422M   1% /mnt/sda11

Editez le fichier /etc/crypttab/ :

root@debian8:/# cat /etc/crypttab
# <target name>	<source device>		<key file>	<options>
sda11 /dev/sda11 none

Modifiez le fichier /etc/fstab :

root@debian8:/# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=86088c53-36ad-4dc7-8ddd-74be3b1f59e1 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=e2dc08f6-9910-4aff-af59-c4e3b061e7de none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
/dev/mapper/sda11			              /mnt/sda11		      ext4	  defaults	      1 2
Ajouter une deuxième Passphrase

Pour ajouter une deuxième passphrase, utilisez la commande cryptsetup avec la sous-commande luksAddKey :

root@debian8:/# cryptsetup luksAddKey /dev/sda11
Enter any existing passphrase: fenestros123456789
Enter new passphrase for key slot: debian123456789
Verify passphrase: debian123456789

Important : Les passphrases ne seront pas en claire. Elle le sont ici pour vous montrer des mots de passe acceptables pour LUKS.

Supprimer une Passphrase

Pour supprimer une passphrase, utilisez la commande cryptsetup avec la sous-commande luksRemoveKey :

root@debian8:/# cryptsetup luksRemoveKey /dev/sda11
Enter passphrase to be deleted: debian123456789
Tester LUKS

Redémarrez votre machine virtuelle :

[root@centos7 ~]# shutdown -r now

Important : Lors du démarrage de la machine virtuelle, le système devrait vous demander d'entrer la passphrase fenestros123456789 pour permettre le montage de /dev/sda11.

Le Swap

Taille du swap

Le tableau suivant résume la taille du swap recommandée en fonction de la mémoire de la machine :

Mémoire Taille du swap
4 Go ou moins 2 Go
4 Go à 16 Go 4 Go
16 Go à 64 Go 8 Go
64 Go à 256 Go 16 Go

Partitions de swap

Une partition de swap peut être créée sur :

  • une partition du disque dur
  • un RAID logiciel
  • un Volume Logique

La Commande swapon

Pour préparer un espace de swap, il convient d'utiliser la commande mkswap. Pour activer une partition de swap, il convient d'utiliser la commande swapon. Pour consulter la liste des partitions swap, il convient d'utiliser la commande swapon avec l'option -s.

root@debian8:~# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda5                              	partition	1951740	0	-1

Important : Vous noterez que dans l'exemple ci-dessus, le swap n'est pas utilisé. Notez aussi qu'il existe une notion de priorité pour les partions de swap.

Options de la Commande

Les options de la commande swapon sont :

root@debian8:~# swapon --help

Usage:
 swapon [options] [<spec>]

Options:
 -a, --all                enable all swaps from /etc/fstab
 -d, --discard[=<policy>] enable swap discards, if supported by device
 -e, --ifexists           silently skip devices that do not exist
 -f, --fixpgsz            reinitialize the swap space if necessary
 -p, --priority <prio>    specify the priority of the swap device
 -s, --summary            display summary about used swap devices (DEPRECATED)
     --show[=<columns>]   display summary in definable table
     --noheadings         don't print headings, use with --show
     --raw                use the raw output format, use with --show
     --bytes              display swap size in bytes in --show output
 -v, --verbose            verbose mode

 -h, --help     display this help and exit
 -V, --version  output version information and exit

The <spec> parameter:
 -L <label>             synonym for LABEL=<label>
 -U <uuid>              synonym for UUID=<uuid>
 LABEL=<label>          specifies device by swap area label
 UUID=<uuid>            specifies device by swap area UUID
 PARTLABEL=<label>      specifies device by partition label
 PARTUUID=<uuid>        specifies device by partition UUID
 <device>               name of device to be used
 <file>                 name of file to be used

Available discard policy types (for --discard):
 once	  : only single-time area discards are issued. (swapon)
 pages	  : discard freed pages before they are reused.
 * if no policy is selected both discard types are enabled. (default)

Available columns (for --show):
 NAME  device file or partition path
 TYPE  type of the device
 SIZE  size of the swap area
 USED  bytes in use
 PRIO  swap priority

For more details see swapon(8)

Important : L'option -p de la commande swapon permet de régler la priorité.

La Commande swapoff

Dans le cas de notre exemple, la partition de swap se trouve sur /dev/sda3. Pour la désactiver, il convient de saisir la commande suivante :

root@debian8:~# swapoff /dev/sda5
root@debian8:~# swapon -s
root@debian8:~# 

Options de la Commande

root@debian8:~# swapoff --help

Usage:
 swapoff [options] [<spec>]

Options:
 -a, --all              disable all swaps from /proc/swaps
 -v, --verbose          verbose mode

 -h, --help     display this help and exit
 -V, --version  output version information and exit

The <spec> parameter:
 -L <label>             LABEL of device to be used
 -U <uuid>              UUID of device to be used
 LABEL=<label>          LABEL of device to be used
 UUID=<uuid>            UUID of device to be used
 <device>               name of device to be used
 <file>                 name of file to be used

For more details see swapoff(8).

LAB #30 - Créer un Fichier de Swap

Sous Linux, vous pouvez aussi bien utiliser un fichier de swap qu'une partition. La mise en place de ce fichier est faite en utilisant la commande dd.

La commande dd copie le fichier passé en entrée dans le fichier de sortie en limitant le nombre d'octets copiés par l'utilisation de deux options :

  • count
    • le nombre
  • bs
    • la taille du bloc à copier

Dans le cas du fichier swap il convient d'utiliser le fichier spécial /dev/zero en tant que fichier d'entrée. Le fichier /dev/zero contient une valeur null.

Pour créer votre fichier de swap de 268Mo, appelé swap, saisissez la commande suivante :

root@debian8:~# dd if=/dev/zero of=/swap bs=1024k count=256
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 1.66162 s, 162 MB/s

Pour préparer le fichier en tant qu'espace de swap, saisissez la commande suivante :

root@debian8:~# mkswap /swap
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=68393385-7543-49ad-ab2a-3cd17725c5cc

Pour activer le fichier avec une priorité de 3, saisissez la commande suivante :

root@debian8:~# swapon -p3 /swap
swapon: /swap: insecure permissions 0644, 0600 suggested.
root@debian8:~# swapon /dev/sda5

Pour visualiser les éspaces swap, saisissez la commande suivante :

root@debian8:~# swapon -s
Filename				Type		Size	Used	Priority
/swap                                  	file    	262140	0	3
/dev/sda5                              	partition	1951740	0	-1

Important : Le fichier de swap ayant une priorité de 3 sera utilisé avant la partition de swap ayant une priorité de -1.

Important : Pour activer le fichier swap d'une manière permanente, il convient d'ajouter une ligne au fichier /etc/fstab. Ne modifiez pas votre fichier /etc/fstab car vous allez supprimer le fichier de swap.

Désactivez maintenant le fichier swap :

root@debian8:~# swapoff /swap
root@debian8:~# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda5                              	partition	1951740	0	-1

Supprimez maintenant le fichier de swap :

root@debian8:~# rm /swap
root@debian8:~# 

<html>

Copyright © 2020 Hugh Norris.<br><br>

</html>


Menu