Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
informatique:linux:fdisk [2008/06/19 17:56] benoit |
informatique:linux:fdisk [2018/09/06 19:10] (Version actuelle) |
||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | |||
| ======= fdisk ======= | ======= fdisk ======= | ||
| - | Permet de partitionner un disque dur | + | ==== Ajouter un nouveau disque et la partitionner ==== |
| - | Pour liste la table de partition : | + | Permet de partitionner un disque dur. |
| + | |||
| + | Si vous ajouter un disque à chaud, lancer la commande suivante pour que le système SCAN le bus scsi : | ||
| + | echo "- - -" > /sys/class/scsi_host/host0/scan | ||
| + | |||
| + | ;-) Astuce pour scanner tous les host scsi : | ||
| + | |||
| + | for i in $(ls -d /sys/class/scsi_host/host*); do echo "- - -" >> $i/scan; done | ||
| + | |||
| + | === Pour liste la table de partition : === | ||
| fdisk -l | fdisk -l | ||
| + | |||
| + | === Création de partitions sur un système :=== | ||
| + | fdisk /dev/sdb | ||
| + | n (add a new partition) | ||
| + | p (primary partition) | ||
| + | 1 (Partition number) | ||
| + | t (change a partition's system id) | ||
| + | 83 Linux | ||
| + | w (write table to disk and exit) | ||
| + | |||
| + | ===Pour lister les types de fs disponibles :=== | ||
| + | fdisk /dev/sdb | ||
| + | l | ||
| + | |||
| + | Résultat : | ||
| + | |||
| + | 0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot | ||
| + | 1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris | ||
| + | 2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- | ||
| + | 3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- | ||
| + | 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- | ||
| + | 5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx | ||
| + | 6 FAT16 42 SFS 86 NTFS volume set da Non-FS data | ||
| + | 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . | ||
| + | 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility | ||
| + | 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt | ||
| + | a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access | ||
| + | b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O | ||
| + | c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor | ||
| + | e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs | ||
| + | f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT | ||
| + | 10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ | ||
| + | 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b | ||
| + | 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor | ||
| + | 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor | ||
| + | 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary | ||
| + | 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto | ||
| + | 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep | ||
| + | 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT | ||
| + | 1c Hidden W95 FAT3 75 PC/IX | ||
| + | |||
| + | === Informer le système des nouvelles partitions === | ||
| + | |||
| + | Une fois le partitionnement effectuer, il faut en informé le noyau par la commande : | ||
| + | partprobe | ||
| + | |||
| + | ==== Partitionner un disque supérieur à 2 To ==== | ||
| + | |||
| + | Vérifier que l'OS prend en charge les partition GPT : | ||
| + | grep CONFIG_EFI_PARTITION /boot/config-4.4.0-62-generic | ||
| + | |||
| + | Si ''CONFIG_EFI_PARTITION=y'' l'OS prendra en charge les partitions GPT si toutes fois le fichier de configuration du noyau ''/boot/config-4.4.0-62-generic'' correspond bien au noyau compilé. | ||
| + | |||
| + | Lancer : | ||
| + | parted /dev/sdb | ||
| + | | ||
| + | Remplacer le label ''msdos'' par le label ''gpt'' : | ||
| + | mklabel gpt | ||
| + | | ||
| + | Confirmer par ''Yes'' :!: **ATTENTION, TOUTES LES DONNEES SERONT SUPPRIMEES** :!: | ||
| + | |||
| + | Quitter : | ||
| + | quit | ||
| + | | ||
| + | Relancer fdisk : | ||
| + | |||
| + | fdisk /dev/sdb | ||
| + | | ||
| + | Et créer vos partition comme décrit plus haut. | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ==== Etendre la capacité d'un disque sans LVM ==== | ||
| + | |||
| + | Visualiser la taille du disk : | ||
| + | |||
| + | fdisk -l /dev/sdb | ||
| + | |||
| + | Exemple de résultat, ici 20 GiB: | ||
| + | |||
| + | Disk /dev/sdb: 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): 1048576 bytes / 1048576 bytes | ||
| + | Disklabel type: dos | ||
| + | Disk identifier: 0x6f033d2f | ||
| + | | ||
| + | Device Boot Start End Sectors Size Id Type | ||
| + | /dev/sdb1 2048 41943039 41940992 20G 83 Linux | ||
| + | |||
| + | |||
| + | Augmenter la taille du disque sur la baie de stockage ou sous la plateforme de virtualisation. | ||
| + | |||
| + | Pour détecter la nouvelle taille lancer (exemple sur /dev/sdb): | ||
| + | |||
| + | echo 1 >> /sys/block/sdb/device/rescan | ||
| + | | ||
| + | Visualiser la nouvelle taille du disk : | ||
| + | |||
| + | fdisk -l /dev/sdb | ||
| + | |||
| + | Exemple de résultat, ici 25 GiB: | ||
| + | |||
| + | Disk /dev/sdb: 25 GiB, 26843545600 bytes, 52428800 sectors | ||
| + | Units: sectors of 1 * 512 = 512 bytes | ||
| + | Sector size (logical/physical): 512 bytes / 512 bytes | ||
| + | I/O size (minimum/optimal): 1048576 bytes / 1048576 bytes | ||
| + | Disklabel type: dos | ||
| + | Disk identifier: 0x6f033d2f | ||
| + | | ||
| + | Device Boot Start End Sectors Size Id Type | ||
| + | /dev/sdb1 2048 41943039 41940992 20G 83 Linux | ||
| + | |||
| + | |||
| + | Nous allons augmenter /dev/sdb1. **:!: ATTENTION, Si vous avez plusieurs partition, l'augmentation d'espace disque ne peut se faire que sur la dernière partition :!:** | ||
| + | |||
| + | Pour augmenter la taille, lancer : | ||
| + | |||
| + | fdisk /dev/sdb | ||
| + | |||
| + | Saisir "p" pour lister les partitions : | ||
| + | |||
| + | Command (m for help): p | ||
| + | Disk /dev/sdb: 25 GiB, 26843545600 bytes, 52428800 sectors | ||
| + | Units: sectors of 1 * 512 = 512 bytes | ||
| + | Sector size (logical/physical): 512 bytes / 512 bytes | ||
| + | I/O size (minimum/optimal): 1048576 bytes / 1048576 bytes | ||
| + | Disklabel type: dos | ||
| + | Disk identifier: 0x6f033d2f | ||
| + | | ||
| + | Device Boot Start End Sectors Size Id Type | ||
| + | /dev/sdb1 2048 41943039 41940992 20G 83 Linux | ||
| + | |||
| + | Saisir "d" pour effacer la dernière partition, dans notre cas il n'y a qu'une seule partition elle est automatiquement supprimée, sinon indiquer la dernière. | ||
| + | |||
| + | Command (m for help): d | ||
| + | Selected partition 1 | ||
| + | Partition 1 has been deleted. | ||
| + | |||
| + | Saisir "n" pour créer une nouvelle partition, le premier secteur commencera au même endroit que l'ancienne partition mais de terminera plus loin (à hauteur des 25 Go). | ||
| + | |||
| + | Command (m for help): n | ||
| + | Partition type | ||
| + | p primary (0 primary, 0 extended, 4 free) | ||
| + | e extended (container for logical partitions) | ||
| + | Select (default p): p | ||
| + | Partition number (1-4, default 1): | ||
| + | First sector (2048-52428799, default 2048): | ||
| + | Last sector, +sectors or +size{K,M,G,T,P} (2048-52428799, default 52428799): | ||
| + | | ||
| + | Created a new partition 1 of type 'Linux' and of size 25 GiB. | ||
| + | |||
| + | Taper "p" pour visualiser la nouvelle taille de /dev/sdb1 | ||
| + | |||
| + | Command (m for help): p | ||
| + | Disk /dev/sdb: 25 GiB, 26843545600 bytes, 52428800 sectors | ||
| + | Units: sectors of 1 * 512 = 512 bytes | ||
| + | Sector size (logical/physical): 512 bytes / 512 bytes | ||
| + | I/O size (minimum/optimal): 1048576 bytes / 1048576 bytes | ||
| + | Disklabel type: dos | ||
| + | Disk identifier: 0x6f033d2f | ||
| + | | ||
| + | Device Boot Start End Sectors Size Id Type | ||
| + | /dev/sdb1 2048 52428799 52426752 25G 83 Linux | ||
| + | |||
| + | Taper "w" pour enregistrer et quitter : | ||
| + | Command (m for help): w | ||
| + | The partition table has been altered. | ||
| + | Calling ioctl() to re-read partition table. | ||
| + | Re-reading the partition table failed.: Device or resource busy | ||
| + | | ||
| + | The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8). | ||
| + | | ||
| + | Executer la commande ci-dessous pour relire le partitionnement : | ||
| + | |||
| + | partprobe | ||
| + | |||
| + | Retailler la taille de la partition au niveau du système de fichier : | ||
| + | |||
| + | resize2fs /dev/sdb1 | ||
| + | |||
| + | Si la partition est utilisée pour [[lvm]], lancer pour prendre en compte la nouvelle taille : | ||
| + | pvresize /dev/sdb1 | ||
| + | | ||
| + | Vérifier la taille finale : | ||
| + | |||
| + | df -h | ||
| + | |||
| + | |||