Menu
InformatiWeb Pro
  • Index
  • System admin
  • Virtualization

Login

Registration Password lost ?
FR
  • Windows Server
    • WMS 2012
    • WS2012 R2
    • WS2016
  • Citrix
    • Citrix NetScaler Gateway
    • Citrix XenApp / XenDesktop
    • Citrix XenServer
  • VMware
    • VMware ESXi
    • VMware vSphere
    • VMware Workstation
  • Microsoft
    • Hyper-V
  • RAID
    • Adaptec SmartRAID
  • UPS
    • APC Back-UPS Pro
  • InformatiWeb Pro
  • System admin
  • Linux
  • Partition your hard drive with fdisk
  • Linux
  • 18 September 2016 at 14:04 UTC
  • InformatiWeb

Partition your hard drive with fdisk

When you buy a new hard drive, it is not partitioned by default (except for external hard drives).
To partition your new hard drive on Linux, we will use fdisk.

  1. List hard drives and partitions
  2. Partition a hard disk with fdisk
    1. Create a primary partition
    2. Create an extended partition
    3. Create logical partitions
    4. Change the partition type
    5. Show the created partition table
    6. Write the partition table on the hard disk
  3. Create the file system and format your new partitions

1. List hard drives and partitions

To do this, simply use the command :

Bash

fdisk -l

In our case, we have two hard drives :
- the first hard drive "/dev/sda" which was automatically partitioned at the installation of Debian.
- the 2nd hard drive "/dev/sdb" which contains no partition. It's this hard drive that we will partition in this tutorial.

Plain Text

Disque /dev/sda : 64.4 Go, 64424509440 octets
255 têtes, 63 secteurs/piste, 7832 cylindres, total 125829120 secteurs
Unités = secteurs de 1 * 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 512 octets
taille d'E/S (minimale / optimale) : 512 octets / 512 octets
Identifiant de disque : 0x000d5066

Périphérique Amorce  Début        Fin      Blocs     Id  Système
/dev/sda1   *        2048   120635391    60316672   83  Linux
/dev/sda2       120637438   125827071     2594817    5  Étendue
/dev/sda5       120637440   125827071     2594816   82  partition d'échange Linux / Solaris

Disque /dev/sdb : 128.8 Go, 128849018880 octets
255 têtes, 63 secteurs/piste, 15665 cylindres, total 251658240 secteurs
Unités = secteurs de 1 * 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 512 octets
taille d'E/S (minimale / optimale) : 512 octets / 512 octets
Identifiant de disque : 0x00000000

Le disque /dev/sdb ne contient pas une table de partitions valable

2. Partition a hard disk with fdisk

To partition a hard drive, just use fdisk by specifying the path of the hard disk :

Bash

fdisk /dev/sdb

fdisk will show you this :

Plain Text

Le périphérique ne contient pas une table de partitions DOS ou Sun, SGI, OSF valable
Création d'une nouvelle étiquette DOS avec id de disque 0x062268d6.
Les modifications restent en mémoire jusqu'à ce que vous les écriviez.
Après quoi, bien sûr, le contenu précédent sera irrécupérable.

Avertissement : indicateur 0x0000 incorrect dans la table de partitions 4, sera corrigé par w (écriture)

Commande (m pour l'aide):

If you type "m", it will display the help :

Plain Text

Commande d'action
a   basculer l'indicateur d'amorçage
b   éditer l'étiquette BSD du disque
c   basculer l'indicateur de compatibilité DOS
d   supprimer la partition
l   lister les types de partitions connues
m   afficher ce menu
n   ajouter une nouvelle partition
o   créer une nouvelle table vide de partitions DOS
p   afficher la table de partitions
q   quitter sans enregistrer les changements
s   créer une nouvelle étiquette vide pour disque de type Sun
t   modifier l'identifiant de système de fichiers d'une partition
u   modifier les unités d'affichage/saisie
v   vérifier la table de partitions
w   écrire la table sur le disque et quitter
x   fonctions avancées (pour experts seulement)

In this tutorial, we will create :
- A primary partition of 40 GB
- And an extended partition of 80 GB (which contain a logical disk of 60GB and another of 20GB)

2.1. Create a primary partition

To create a primary partition, just type "n" (new partition), and then "p" (primary partition).
Note that the primary partitions are limited to 4 per hard drive (it's a hardware limit).

Plain Text

Commande (m pour l'aide): n
Type de partition :
p   primaire (0 primaire(s), 0 étendue(s), 4 libre(s))
e   étendue
Sélection (p par défaut) : p

Enter a partition number or leave the default value :

Plain Text

Numéro de partition (1-4, par défaut 1): 1

Then :
- leave the default value for the first sector (this is where the partition will start on the hard drive)
- and specify the desired size for the value "Last sector". The size can be specified in KB, in MB or in GB, but must be preceded by the character +.

Plain Text

Premier secteur (2048-251658239, par défaut 2048): 
Utilisation de la valeur par défaut 2048
Dernier secteur, +secteurs or +taille{K,M,G} (2048-251658239, par défaut 251658239): +40G

2.2. Create an extended partition

An extended partition contains logical drives.
Logical drives are almost identical to the partitions except that they are defined in the EBR instead of the MRB of the hard drive.
Use extended partitions allows you to create more than 4 "partitions" by hard drive.

Note that extended partitions can contain only logical disks and not your data.

To create an extended partition, type "n" (new partition), and then "e" (extended partition).
And leave the default partition number.

Plain Text

Commande (m pour l'aide): n
Type de partition :
p   primaire (1 primaire(s), 0 étendue(s), 3 libre(s))
e   étendue
Sélection (p par défaut) : e
Numéro de partition (1-4, par défaut 2): 

For "First sector" and "Last sector" values, we will leave the default.
So, the extended partition takes the rest of the unallocated space (unpartitioned) of our hard drive.

Plain Text

Premier secteur (83888128-251658239, par défaut 83888128): 
Utilisation de la valeur par défaut 83888128
Dernier secteur, +secteurs or +taille{K,M,G} (83888128-251658239, par défaut 251658239): 
Utilisation de la valeur par défaut 251658239

2.3. Create logical partitions

Now that we have an extended partition, we have the opportunity to also create logical partitions (logical disks).

To do this, type "n" (new partition), and then "l" (logical partition).

Plain Text

Commande (m pour l'aide): n
Type de partition :
p   primaire (1 primaire(s), 1 étendue(s), 2 libre(s))
l   logique (numéroté à partir de 5)
Sélection (p par défaut) : l
Ajout de la partition logique 5

Then :
- Leave the default value for the first sector (this is where the logical partition starts)
- And specify the desired size for the "Last sector" value. The size can be specified in KB, in MB or in GB, but must be preceded by the character : +.

Plain Text

Premier secteur (83890176-251658239, par défaut 83890176): 
Utilisation de la valeur par défaut 83890176
Dernier secteur, +secteurs or +taille{K,M,G} (83890176-251658239, par défaut 251658239): +60G

To create the last logical partition, just leave the default values for "First sector" and "Last sector".

2.4. Change the partition type

To change the partition type :
- Type "t"
- Specify the partition number that you want to change the type
- Then, type the desired hex code. Example : 83 = Linux.

Plain Text

Code Hexa (taper L pour lister les codes): 83

For a complete list of the possible hexadecimal codes, type "L".

Plain Text

Code Hexa (taper L pour lister les codes): L

 0  Vide            24  NEC DOS         81  Minix / Linux a bf  Solaris 
 1  FAT12           27  TFS WinRE masqu 82  partition d'éch c1  DRDOS/sec (FAT-
 2  root XENIX      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  usr XENIX       3c  récupération Pa 84  OS/2 masquée di c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux étendue   c7  Syrinx 
 5  Étendue         41  PPC PReP Boot   86  NTFS volume set da  Non-FS data 
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility 
 8  AIX             4e  2e partie QNX4. 8e  LVM Linux       df  BootIt 
 9  Amorçable AIX   4f  3e partie QNX4. 93  Amoeba          e1  DOS access 
 a  Gestionnaire d' 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O 
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor 
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs 
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT 
 f  Étendue W95 (LB 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  FAT12 masquée   56  Golden Bow      a8  UFS Darwin      f1  SpeedStor 
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor 
14  FAT16 masquée < 61  SpeedStor       ab  Amorce Darwin   f2  DOS secondaire 
16  FAT16 masquée   63  GNU HURD ou Sys af  HFS / HFS+      fb  VMware VMFS 
17  HPFS/NTFS masqu 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  partition d'éch fd  RAID Linux auto
1b  W95 FAT32 masqu 70  DiskSecure Mult bb  Boot Wizard mas fe  LANstep 
1c  W95 FAT32 masqu 75  PC/IX           be  Amorce Solaris  ff  BBT 
1e  W95 FAT16 masqu 80  Minix ancienne

2.5. Show the created partition table

To display the partition table that you will create on the hard disk, type "p".

Plain Text

Commande (m pour l'aide): p

Disque /dev/sdb : 128.8 Go, 128849018880 octets
255 têtes, 63 secteurs/piste, 15665 cylindres, total 251658240 secteurs
Unités = secteurs de 1 * 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 512 octets
taille d'E/S (minimale / optimale) : 512 octets / 512 octets
Identifiant de disque : 0x7804a283

Périphérique Amorce  Début        Fin      Blocs     Id  Système
/dev/sdb1            2048    83888127    41943040   83  Linux
/dev/sdb2        83888128   251658239    83885056    5  Étendue
/dev/sdb5        83890176   209719295    62914560   83  Linux
/dev/sdb6       209721344   251658239    20968448   83  Linux

2.6. Write the partition table on the hard disk

Finally, you must write the partition table on the hard disk.
Warning : if data were present on the hard disk that you are partitioning, they will be permanently lost.

To do this, type "w" (write the partition table on the disk and exit).

Plain Text

Commande (m pour l'aide): w
La table de partitions a été altérée.

Appel de ioctl() pour relire la table de partitions.
Synchronisation des disques.

If you use the "fdisk -l" command again, you will see that the hard drive "/dev/sdb" has been partitioned.

Bash

fdisk -l

Plain Text

...

Disque /dev/sdb : 128.8 Go, 128849018880 octets
255 têtes, 63 secteurs/piste, 15665 cylindres, total 251658240 secteurs
Unités = secteurs de 1 * 512 = 512 octets
Taille de secteur (logique / physique) : 512 octets / 512 octets
taille d'E/S (minimale / optimale) : 512 octets / 512 octets
Identifiant de disque : 0x7804a283

Périphérique Amorce  Début        Fin      Blocs     Id  Système
/dev/sdb1            2048    83888127    41943040   83  Linux
/dev/sdb2        83888128   251658239    83885056    5  Étendue
/dev/sdb5        83890176   209719295    62914560   83  Linux
/dev/sdb6       209721344   251658239    20968448   83  Linux

3. Create the file system and format your new partitions

Finally, be sure to format your new partitions to be able to store data on them.

Bash

mkfs.ext4 /dev/sdb1

Share this tutorial

Partager
Tweet

To see also

  • Debian - Clustering and service balancing (with 2 servers)

    Linux 7/21/2017

    Debian - Clustering and service balancing (with 2 servers)

  • Debian / Ubuntu - Network monitoring with HTML statistics

    Linux 9/12/2015

    Debian / Ubuntu - Network monitoring with HTML statistics

  • StartSSL - Renew your SSL certificates

    Linux 9/8/2016

    StartSSL - Renew your SSL certificates

  • Ubuntu - Install a complete web server

    Linux 1/31/2014

    Ubuntu - Install a complete web server

Comments

You must be logged in to post a comment

Share your opinion

Pinned content

  • Software (System admin)
  • Linux softwares
  • Our programs
  • Terms and conditions
  • Share your opinion

Contact

  • Guest book
  • Technical support
  • Contact

® InformatiWeb-Pro.net - InformatiWeb.net 2008-2022 - © Lionel Eppe - All rights reserved.

Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.