Table des matières

Dernière mise-à-jour : 2020/01/30 03:27

104.1 - Créer des partitions et des systèmes de fichiers (2/60)

LAB #1 - Partionnement de votre Disque avec parted sous Debian

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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  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 12001 12501
(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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   lba

(parted) mkpart logical 12502 12702
(parted) mkpart logical 12703 13003
(parted) mkpart logical 13004 13504
(parted) mkpart logical 13505 13905
(parted) mkpart logical 13906 14406
(parted) mkpart logical 14407 14907
(parted) mkpart logical 14908 15108
(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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   lba
 7      12.5GB  12.7GB  200MB   logical                   lba
 8      12.7GB  13.0GB  300MB   logical                   lba
 9      13.0GB  13.5GB  499MB   logical                   lba
10      13.5GB  13.9GB  401MB   logical                   lba
11      13.9GB  14.4GB  500MB   logical                   lba
12      14.4GB  14.9GB  499MB   logical                   lba
13      14.9GB  15.1GB  200MB   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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   raid, lba
 7      12.5GB  12.7GB  200MB   logical                   lvm, lba
 8      12.7GB  13.0GB  300MB   logical                   lvm, lba
 9      13.0GB  13.5GB  499MB   logical                   raid, lba
10      13.5GB  13.9GB  401MB   logical                   lvm, lba
11      13.9GB  14.4GB  500MB   logical                   raid, lba
12      14.4GB  14.9GB  499MB   logical                   raid, lba
13      14.9GB  15.1GB  200MB   logical                   lba

(parted) set 6 lba off

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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   raid
 7      12.5GB  12.7GB  200MB   logical                   lvm
 8      12.7GB  13.0GB  300MB   logical                   lvm
 9      13.0GB  13.5GB  499MB   logical                   raid
10      13.5GB  13.9GB  401MB   logical                   lvm
11      13.9GB  14.4GB  500MB   logical                   raid
12      14.4GB  14.9GB  499MB   logical                   raid
13      14.9GB  15.1GB  200MB   logical                   lba

(parted)

Quittez parted avec la commande quit :

(parted) quit
<code> 

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

<code>
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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   raid
 7      12.5GB  12.7GB  200MB   logical                   lvm
 8      12.7GB  13.0GB  300MB   logical                   lvm
 9      13.0GB  13.5GB  499MB   logical                   raid
10      13.5GB  13.9GB  401MB   logical                   lvm
11      13.9GB  14.4GB  500MB   logical                   raid
12      14.4GB  14.9GB  499MB   logical                   raid
13      14.9GB  15.1GB  200MB   logical

(parted)  

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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   raid
 7      12.5GB  12.7GB  200MB   logical                   lvm
 8      12.7GB  13.0GB  300MB   logical                   lvm
 9      13.0GB  13.5GB  499MB   logical                   raid
10      13.5GB  13.9GB  401MB   logical                   lvm
11      13.9GB  14.4GB  500MB   logical                   raid
12      14.4GB  14.9GB  499MB   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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   raid
 7      12.5GB  12.7GB  200MB   logical                   lvm
 8      12.7GB  13.0GB  300MB   logical                   lvm
 9      13.0GB  13.5GB  499MB   logical                   raid
10      13.5GB  13.9GB  401MB   logical                   lvm
11      13.9GB  14.4GB  500MB   logical                   raid
12      14.4GB  14.9GB  499MB   logical                   raid

(parted)                                                                  

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

(parted) mkpart logical 14908 15108                                             
(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.0GB  9999MB  primary   ext4            boot
 2      10.0GB  21.5GB  11.5GB  extended
 5      10.0GB  12.0GB  1999MB  logical   linux-swap(v1)
 6      12.0GB  12.5GB  500MB   logical                   raid
 7      12.5GB  12.7GB  200MB   logical                   lvm
 8      12.7GB  13.0GB  300MB   logical                   lvm
 9      13.0GB  13.5GB  499MB   logical                   raid
10      13.5GB  13.9GB  401MB   logical                   lvm
11      13.9GB  14.4GB  500MB   logical                   raid
12      14.4GB  14.9GB  499MB   logical                   raid
13      14.9GB  15.1GB  200MB   logical                   lba

(parted)   

Sortez de parted en utilisant la commande quit.

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

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 :

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 :

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 © 2004-2017 Hugh Norris.<br><br> <a rel=“license” href=“http://creativecommons.org/licenses/by-nc-nd/3.0/fr/”><img alt=“Licence Creative Commons” style=“border-width:0” src=“http://i.creativecommons.org/l/by-nc-nd/3.0/fr/88x31.png” /></a><br />Ce(tte) oeuvre est mise à disposition selon les termes de la <a rel=“license” href=“http://creativecommons.org/licenses/by-nc-nd/3.0/fr/”>Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Pas de Modification 3.0 France</a>.

</html>