Handbook:AMD64/Blocks/Disks/it

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:AMD64/Blocks/Disks and the translation is 8% complete.
Outdated translations are marked like this.


Benché per ospitare un sistema Linux sia teoricamente possibile usare un disco grezzo e non partizionato (quando si crea un RAID btrfs per esempio), praticamente ciò non viene mai fatto. Piuttosto, i dischi vengono suddivisi in unità a blocchi più piccole e maneggevoli. Su sistemi amd64, esse sono chiamate partizioni. Attualmente sono standardizzate due tecnologie di partizionamento: MBR e GPT.

GPT

La configurazione tramite GPT (GUID Partition Table) usa identificatori a 64 bit per le partizioni. Lo spazio dove memorizza le informazioni sulle partizioni è molto più grande dei 512 byte dell'MBR, il ché significa che non c'è praticamente alcun limite alla quantità di partizioni definibili su un disco GPT. Inoltre, il limite per la dimensione massima di una partizione è di gran lunga maggiore (quasi 8 ZB - sì, zettabytes).

Quando l'interfaccia software del sistema, che si pone tra il sistema operativo e il firmware, è UEFI (anziché BIOS), GPT è quasi obbligatoria in quanto potrebbero sorgere problemi di compatibilità con MBR.

GPT trae anche vantaggio dalle somme di controllo (checksum) e dalla ridondanza. Porta il controllo CRC32 alla testata delle tabelle di partizione per rilevare errori ed offre un backup del segmento GPT alla fine del disco. Questo backup può essere usato per ripristinare i danni del segmento GPT corrente all'inizio del disco.

Importante
There are a few caveats regarding GPT:
  • Using GPT on a BIOS-based computer works, but then one cannot dual-boot with a Microsoft Windows operating system. The reason is that Microsoft Windows will boot in UEFI mode if it detects a GPT partition label.
  • Some buggy (old) motherboard firmware configured to boot in BIOS/CSM/legacy mode might also have problems with booting from GPT labeled disks.

MBR

La configurazione tramite MBR (Master Boot Record) usa identificatori a 32 bit per il settore di avvio e per stabilire la grandezza delle partizioni. Supporta tre tipi di partizione: primaria, estesa e logica. Le partizioni primarie memorizzano le loro informazioni nel master boot record stesso - uno spazio molto piccolo (solitamente 512 byte) all'inizio del disco. A causa del poco spazio, vengono supportate solo quattro partizioni primarie (per esempio, da /dev/sda1 a /dev/sda4).

Per supportare più partizioni, una delle partizioni primarie può essere definita come partizione estesa. Questa partizione può in tal caso contenere a sua volta delle partizioni logiche (partizioni all'interno di una partizione).

Importante
Although still supported by most motherboard manufacturers, MBR boot sectors and their associated partitioning limitations are considered legacy. Unless working with hardware that is pre-2010, it best to partition a disk with GUID Partition Table. Readers who must proceed with setup type should knowingly acknowledge the following information:
  • Most post-2010 motherboards consider using MBR boot sectors a legacy (supported, but not ideal) boot mode.
  • Due to using 32-bit identifiers, partition tables in the MBR cannot address storage space that is larger than 2 TiBs in size.
  • Unless an extended partition is created, MBR supports a maximum of four partitions.
  • This setup does not provide a backup boot sector, so if something overwrites the partition table, all partition information will be lost.
That said, MBR and legacy BIOS boot may still used in virtualized cloud environments such as AWS.

The Handbook authors suggest using GPT whenever possible for Gentoo installations.

Partizionamento avanzato

I CD di installazione amd64 forniscono supporto per il gestore dei volumi logici (LVM). LVM accresce la flessibilità offerta dalla configurazione di partizionamento. Le istruzioni di installazione riportate di seguito si concentrano su partizioni "regolari", ma è bene sapere che anche LVM è supportato se si desidera proseguire per quella strada. Leggere l'articolo LVM per ulteriori dettagli. I nuovi arrivati stiano attenti: benché LVM sia completamente supportato, va al di là dello scopo di questa guida.

Schema di partizionamento predefinito

Throughout the remainder of the handbook, we will discuss and explain two cases:

  1. UEFI firmware with GUID Partition Table (GPT) disk.
  2. MBR DOS/legacy BIOS firmware with a MBR partition table disk.

While it is possible to mix and match boot types with certain motherboard firmware, mixing goes beyond the intention of the handbook. As previously stated, it is strongly recommended for installations on modern hardware to use UEFI boot with a GPT disklabel disk.

Per tutto il resto del manuale, verrà usato il seguento schema di partizionamento come esempio semplice di configurazione:

Importante
The first row of the following table contains exclusive information for either a GPT disklabel or a MBR DOS/legacy BIOS disklabel. When in doubt, proceed with GPT, since amd64 machines manufactured after the year 2010 generally support UEFI firmware and GPT boot sector.
Partizione Filesystem Dimensione Descrizione
/dev/sda1 (bootloader) 2M Partizione di avvio BIOS
/dev/sda1 ext2 (o fat32 se si utilizza UEFI) 128M Partizione di sistema Boot/EFI
/dev/sda3 (swap) 512M o maggiore Partizione di swap
/dev/sda4 ext4 Spazio rimanente del disco Partizione radice (root)

Se ciò è sufficiente e il lettore ha scelto la configurazione GPT, si può proseguire con la sezione Predefinito: Uso di parted per partizionare il disco. Coloro che sono ancora interessati a MBR (ehi, capita!) e vogliono usare la configurazione d'esempio, possono proseguire con l'Alternativa: Uso di fdisk per partizionare il disco.

Sia fdisk che parted sono utilità di partizionamento. fdisk è ben noto, stabile, e raccomandato per la configurazione di partizionamento MBR, mentre parted è stata una delle prima utilità di gestione dei dispositivi a blocchi Linux a supportare le partizioni GPT. Coloro a cui piace l'interfaccia di fdisk possono usare gdisk (fdisk GPT) come alternativa a parted.

Prima di proseguire con le istruzioni di creazione, il primo insieme di sezioni descriverà con maggiori dettagli come si possono creare schemi di partizionamento e si menzioneranno alcune trappole comuni.

Progettazione di uno schema delle partizioni

Quante partizioni e quanto grandi?

Il numero di partizioni dipende fortemente dal tipo di ambiente. Per esempio, se sono previsti molti utenti, allora è consigliato avere la /home/ separata così da migliorare la sicurezza e rendere più facili i backup. Se Gentoo viene installato per fare da server di posta elettronica, allora /var/ è meglio che stia separata in quanto le email vengono memorizzate all'interno di /var/. Una buona scelta del filesystem massimizzerà le prestazioni. I server da gioco avranno /opt/ separata, in quando la maggior parte dei server da gioco sono installati lì. La ragione è simile al percorso /home/: sicurezza e backup. Nella maggior parte delle situazioni, /usr/ dovrà essere capiente: non solo contiene la maggior parte delle applicazioni, ma in genere ospita anche repository ebuild di Gentoo (solitamente su /usr/portage), che fin dall'inizio occupa già 650 MB. Questa stima dello spazio su disco esclude le cartelle packages/ e distfiles/ che sono generalmente memorizzate all'interno di questo archivio ebuild.

In most situations on Gentoo, /usr and /var should be kept relatively large in size. /usr hosts the majority of applications available on the system and the Linux kernel sources (under /usr/src). By default, /var hosts the Gentoo ebuild repository (located at /var/db/repos/gentoo) which, depending on the file system, generally consumes around 650 MiB of disk space. This space estimate excludes the /var/cache/distfiles and /var/cache/binpkgs directories, which will gradually fill with source files and (optionally) binary packages respectively as they are added to the system.

Molto dipende da ciò che desidera l'amministratore. Partizioni o volumi separati hanno i seguenti vantaggi:

  • Scelta del miglior filesystem per ciascuna partizione o volume.
  • L'intero sistema non esaurirà lo spazio, nel caso in cui uno strumento invalido continui a scrivere file su una partizione o un volume.
  • Se necessario, i controlli del filesystem impiegheranno meno tempo, in quanto possono essere fatti in parallelo (benché questo vantaggio sia maggiore con i dischi multipli piuttosto che con le sole partizioni multiple).
  • La sicurezza può essere migliorata montando alcune partizioni o volumi in modalità di sola lettura, nosuid (ignora i bit setuid), noexec (ignora i bit eseguibili), ecc.


Tuttavia, anche avere partizioni multiple presenta degli svantaggi. Se il sistema non viene appropriatamente configurato potrebbe avere molto spazio libero su una partizione e niente più spazio su un'altra. Un altro aspetto noioso è che partizioni separate - specialmente per i punti di montaggio importanti come /usr/ o /var/ - richiedono spesso che l'amministratore avvii il sistema con un initramfs per montare la partizione, prima che altri script all'avvio vengano eseguiti. Non sempre si verifica questo caso, quindi i risultati possono variare.

C'è anche un limite di 15 partizioni per SCSI e SATA a meno che il disco non usi una configurazione GPT.

Nota
Installations that intend to use systemd as the service and init system must have the /usr directory available at boot, either as part of the root filesystem or mounted via an initramfs.

Riguardo lo spazio di swap?

Non c'è un valore perfetto per la partizione di swap. Lo scopo dello spazio di swap è quello di fornire, tramite disco, memoria al kernel quando la memoria interna (RAM) è sotto pressione. Uno spazio di swap permette al kernel di spostare le pagine di memoria, che non verranno utilizzate entro breve tempo, sul disco (swap o spaginazione), liberando memoria. Ovviamente, se quella memoria torna improvvisamente necessaria, queste pagine vengono rimesse nella memoria (paginazione), ciò richiederà un po' di tempo (dato che i dischi sono molto lenti, se paragonati alla memoria interna).

Quando il sistema non esegue applicazioni che occupano molta memoria oppure se il sistema ha tantissima memoria disponibile, allora è probabile che non serva molto spazio di swap. Comunque, lo spazio di swap è usato anche per scriverci tutta la memoria in caso di ibernazione. Se il sistema deve andare in ibernazione, allora è richiesto uno spazio di swap più grande, spesso pari ad almeno la quantità di memoria installata sul sistema.


Uso di UEFI

Quando si installa Gentoo su un sistema che utilizza UEFI per avviare il sistema operativo (invece di BIOS), allora è importante creare una Partizione di Sistema EFI (ESP). Le istruzioni per parted di seguito contengono i puntatori necessari per gestire questa operazione correttamente.

La partizione ESP deve essere una variante di FAT (talvolta mostrata come vfat sui sistemi Linux). Le specifiche UEFI ufficiali dichiarano che i filesystem FAT12, 16 o 32 vengono riconosciuti dal firmware UEFI, benché sia raccomandato FAT32 per la ESP. Procedere con la formattazione della ESP in FAT32:

root #mkfs.fat -F 32 /dev/sda1
Importante
Se non viene usata una variante FAT per l'ESP, non è garantito che il firmware UEFI di sistema trovi il bootloader (o il kernel Linux) e probabilmente non sarà in grado di avviare il sistema!

Cos'è la partizione di avvio BIOS?

Una partizione di avvio BIOS è una partizione molto piccola (da 1 a 2 MB) in cui i bootloader come GRUB2 possono inserire dati aggiuntivi se non riescono a stare nello spazio allocato (poche centinaia di byte nel caso di MBR) e se non possono stare altrove.

Alternativa: Uso di fdisk per partizionare il disco

La seguente parte spiega come impostare le partizioni secondo l'esempio usando fdisk. Lo schema delle partizioni d'esempio menzionato prima:

Modificare lo schema di partizionamento in base alle proprie personali preferenze.

Partizione Descrizione
/dev/sda1 Partizione di avvio BIOS
/dev/sda1 Partizione di avvio
/dev/sda3 Partizione di swap
/dev/sda4 Partizione radice (root)

Visualizzare lo schema delle partizioni correnti con fdisk

fdisk è un famoso e potente strumento per dividere un disco in partizioni. Lanciare fdisk per il disco (nel nostro esempio usiamo /dev/sda):

root #fdisk /dev/sda

Usare il tasto p per visualizzare l'attuale configurazione delle partizioni sul disco:

Command (m for help):p
Disk /dev/sda: 240 heads, 63 sectors, 2184 cylinders
Units = cylinders of 15120 * 512 bytes
  
   Device Boot    Start       End    Blocks   Id  System
/dev/sda1   *         1        14    105808+  83  Linux
/dev/sda2            15        49    264600   82  Linux swap
/dev/sda3            50        70    158760   83  Linux
/dev/sda4            71      2184  15981840    5  Extended
/dev/sda5            71       209   1050808+  83  Linux
/dev/sda6           210       348   1050808+  83  Linux
/dev/sda7           349       626   2101648+  83  Linux
/dev/sda8           627       904   2101648+  83  Linux
/dev/sda9           905      2184   9676768+  83  Linux

Device Start End Sectors Size Type /dev/sda1 2048 2099199 2097152 1G EFI System /dev/sda2 2099200 10487807 8388608 4G Linux swap /dev/sda3 10487808 1953523711 1943035904 926.5G Linux root (x86-64)

}}

Questo particolare disco è stato configurato per ospitare 7 filesystem Linux (ciascuno con una corrispondente partizione elencata come "Linux") e una partizione di swap (indicata con "Linux swap").

Rimuovere tutte le partizioni con fdisk

Pressing the g key will instantly remove all existing disk partitions and create a new GPT disklabel:

Command (m for help):g
Created a new GPT disklabel (GUID: 3E56EE74-0571-462B-A992-9872E3855D75).

Prima rimuovere tutte le partizioni esistenti dal disco. Digitare d per eliminare una partizione. Per esempio, per eliminare un'esistente /dev/sda1:

Command (m for help):d
Partition number (1-4): 1

La partizione è ora programmata per l'eliminazione. Non sarà più mostrata quando si richiede l'elenco delle partizioni (p), comunque non sarà effettivamente eliminata finché i cambiamenti non saranno salvati. Ciò permette agli utenti di annullare l'operazione se è stato commesso qualche errore - in tal caso, digitare subito q e premere Enter così la partizione non sarà eliminata.

Digitare nuovamente p per visualizzare un elenco delle partizioni e premere d seguito dal numero della partizione da eliminare. Alla fine, la tabella delle partizioni sarà vuota:

Command (m for help):p
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
  
Device Boot    Start       End    Blocks   Id  System

Ora che la tabella delle partizioni risulta vuota, anche se solo nella memoria, siamo pronti per creare le nuove partizioni.

Creare la partizione di avvio BIOS

Nota
A smaller ESP is possible but not recommended, especially given it may be shared with other OSes.

Per prima cosa si crei una piccola partizione di avvio per il BIOS. Digitare n per creare una nuova partizione, quindi p per selezionare una partizione primaria, seguito da 1 per selezionare la prima partizione primaria. Quando viene richiesto il settore di inizio, assicurarsi che inizi dal 2048 (necessario per il boot loader) e premere Enter. Quando viene richiesto il settore finale, digitare +2M per creare una partizione grande 2 MByte:

Command (m for help):n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (64-10486533532, default 64): 2048
Last sector, +sectors +size{M,K,G} (4096-10486533532, default 10486533532): +2M

Do you want to remove the signature? [Y]es/[N]o: Y The signature will be removed by a write command.

}}

Segnare la partizione per gli scopi di UEFI:

Command (m for help):t
Selected partition 1
Hex code (type L to list codes): 4
Changed system type of partition 1 to 4 (BIOS boot)

Optionally, to have the ESP conform to the Discoverable System Partition (DSP) specification, switch to expert mode and perform the following extra step to set the partition's UUID:

Command (m for help):x
Expert command (m for help):u
Selected partition 1
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
New UUID (in 8-4-4-4-12 format): c12a7328-f81f-11d2-ba4b-00a0c93ec93b
Partition UUID changed from 10293DC1-DF6C-4443-8ACF-C756B81B4767 to C12A7328-F81F-11D2-BA4B-00A0C93EC93B.

Press the r key to return to the main menu:

Expert command (m for help):r
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Command (m for help):

Creare la partizione di swap

Per creare una partizione di swap: digitare n per creare una nuova partizione, poi p per dire a fdisk di creare una partizione primaria. Digitare 3 per creare una terza partizione primaria, /dev/sda3. Quando viene richiesto il settore di inizio, premere Enter. Quando viene richiesto il settore finale, digitare +512M (o qualsiasi altra grandezza sia necessaria per lo spazio di swap) così da creare una partizione grande 512 MB.

Creare la partizione di avvio

Fatto tutto questo, digitare t per impostare il tipo di partizione, 3 per selezionare la partizione appena creata e poi digitare 82 per impostare il tipo di partizione "Linux Swap".

Command (m for help):t
Partition number (1,2, default 2): 2
Partition type or alias (type L to list all): 19
 
Changed type of partition 'Linux filesystem' to 'Linux swap'.

Optionally, to have the swap partition conform to the Discoverable System Partition (DSP) specification, switch to expert mode and perform the following extra step to set the partition's UUID:

Command (m for help):x
Expert command (m for help):u
Partition number (1,2, default 2): 2
Selected partition 2
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
New UUID (in 8-4-4-4-12 format): 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
Partition UUID changed from 7529CDF6-9482-4497-B021-576745648B2A to 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F..

Press the r key to return to the main menu:

Expert command (m for help):r
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Command (m for help):

Creare la partizione radice

Infine, per creare la partizione radice (root), digitare n per creare una nuova partizione, quindi p per indicare a fdisk di creare una partizione primaria. Poi digitare 4 per creare la quarta partizione primaria, /dev/sda4. Quando viene richiesto il settore di inizio, premere Enter. Quando viene richiesto il settore finale, premere Enter per creare una partizione che occupi il rimanente spazio su disco. Dopo aver completato questi passaggi, digitando p si dovrebbe vedere una tabella delle partizioni simile a questa:

Command (m for help):n
Partition number (3-128, default 3): 3
First sector (10487808-1953525134, default 10487808):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-1953525134, default 1953523711):
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Created a new partition 3 of type 'Linux filesystem' and of size 926.5 GiB..
Nota
Setting the root partition's type to "Linux root (x86-64)" is not required and the system will function normally if it is set to the "Linux filesystem" type. This filesystem type is only necessary for cases where a bootloader that supports it (i.e. systemd-boot) is used and a fstab file is not wanted.

After creating the root partition, press t to set the partition type, 3 to select the partition just created, and then type in 23 to set the partition type to "Linux Root (x86-64)".

Command(m for help):t
Partition number (1-3, default 3): 3
Partition type or alias (type L to list all): 23
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Changed type of partition 'Linux filesystem' to 'Linux root (x86-64)'

Optionally, to have the root partition conform to the Discoverable System Partition (DSP) specification, switch to expert mode and perform the following extra step to set the partition's UUID:

Command (m for help):x
Expert command (m for help):u
Partition number (1-3, default 3): 3
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
New UUID (in 8-4-4-4-12 format): 4f68bce3-e8cd-4db1-96e7-fbcaf984b709
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Partition UUID changed from 40465382-FA2A-4846-9827-640821CC001F to 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709.

Press the r key to return to the main menu:

Expert command (m for help):r
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Command (m for help):

After completing these steps, pressing p should display a partition table that looks similar to the following:

Command (m for help):p
Disk /dev/sda: 30.0 GB, 30005821440 bytes
240 heads, 63 sectors/track, 3876 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes
  
   Device Boot    Start       End    Blocks   Id  System
/dev/sda1             1         3      5198+  ef  EFI (FAT-12/16/32)
/dev/sda2   *         3        14    105808+  83  Linux
/dev/sda3            15        81    506520   82  Linux swap
/dev/sda4            82      3876  28690200   83  Linux

Device Start End Sectors Size Type /dev/sda1 2048 2099199 2097152 1G Linux filesystem /dev/sda2 2099200 10487807 8388608 4G Linux swap /dev/sda3 10487808 1953523711 1943035904 926.5G Linux root (x86-64)

Filesystem/RAID signature on partition 1 will be wiped.

}}

Salvare lo schema delle partizioni

Per salvare la configurazione delle partizioni e uscire da fdisk, premere w.

Command (m for help):w

Ora che le partizioni sono state create, si deve procedere alla creazione di un filesystem su ciascuna di esse.

Partitioning the disk with MBR for BIOS / legacy boot

The following table provides a recommended partition layout for a trivial MBR DOS / legacy BIOS boot installation. Additional partitions can be added according to personal preference or system design goals.

Device path (sysfs) Mount point File system DPS UUID (PARTUUID) Description
/dev/sda1 /boot xfs N/A MBR DOS / legacy BIOS boot partition details.
/dev/sda2 N/A. Swap is not mounted to the filesystem like a device file. swap 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f Swap partition details.
/dev/sda3 / xfs 4f68bce3-e8cd-4db1-96e7-fbcaf984b709 Root partition details.

Change the partition layout according to personal preference.

Viewing the current partition layout

Fire up fdisk against the disk (in our example, we use /dev/sda):

root #fdisk /dev/sda

Use the p key to display the disk's current partition configuration:

Command (m for help):p
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: HGST HTS721010A9
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xf163b576
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Device     Boot    Start        End    Sectors   Size Id Type
/dev/sda1  *        2048    2099199    2097152     1G 83 Linux
/dev/sda2        2099200   10487807    8388608     4G 82 Linux swap / Solaris
/dev/sda3       10487808 1953525167 1943037360 926.5G 83 Linux

This particular disk was until now configured to house two Linux filesystems (each with a corresponding partition listed as "Linux") as well as a swap partition (listed as "Linux swap"), using a GPT table.

Creating a new disklabel / removing all partitions

Pressing o will instantly remove all existing disk partitions and create a new MBR disklabel (also named DOS disklabel):

Command (m for help):o
Created a new DOS disklabel with disk identifier 0xf163b576.
The device contains 'gpt' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.

Alternatively, to keep an existing DOS disklabel (see the output of p above), consider removing the existing partitions one by one from the disk. Press d to delete a partition. For instance, to delete an existing /dev/sda1:

Command (m for help):d
Partition number (1-4): 1

The partition has now been scheduled for deletion. It will no longer show up when printing the list of partitions (p, but it will not be erased until the changes have been saved. This allows users to abort the operation if a mistake was made - in that case, type q immediately and hit Enter and the partition will not be deleted.

Repeatedly press p to print out a partition listing and then press d and the number of the partition to delete it. Eventually, the partition table will be empty:

Command (m for help):p
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: HGST HTS721010A9
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xf163b576

The disk is now ready to create new partitions.

Creating the boot partition

First, create a small partition which will be mounted as /boot. Press n to create a new partition, followed by p for a primary partition and 1 to select the first primary partition. When prompted for the first sector, make sure it starts from 2048 (which may be needed for the boot loader) and press Enter. When prompted for the last sector, type +1G to create a partition 1 GB in size:

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): 1
First sector (2048-1953525167, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525167, default 1953525167): +1G
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Created a new partition 1 of type 'Linux' and of size 1 GiB.

Mark the partition as bootable by pressing the a key and pressing Enter:

Command (m for help):a
Selected partition 1
The bootable flag on partition 1 is enabled now.

Note: if more than one partition is available on the disk, then the partition to be flagged as bootable will have to be selected.

Creating the swap partition

Next, to create the swap partition, press n to create a new partition, then p, then type 2 to create the second primary partition, /dev/sda2. When prompted for the first sector, press Enter. When prompted for the last sector, type +4G (or any other size needed for the swap space) to create a partition 4GB in size.

Command (m for help):n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-1953525167, default 2099200):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-1953525167, default 1953525167): +4G
 
Created a new partition 2 of type 'Linux' and of size 4 GiB.

After all this is done, press t to set the partition type, 2 to select the partition just created and then type in 82 to set the partition type to "Linux Swap".

Command (m for help):t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Creating the root partition

Finally, to create the root partition, press n to create a new partition. Then press p and 3 to create the third primary partition, /dev/sda3. When prompted for the first sector, hit Enter. When prompted for the last sector, hit Enter to create a partition that takes up the rest of the remaining space on the disk:

Command (m for help):n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (10487808-1953525167, default 10487808):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-1953525167, default 1953525167):
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Created a new partition 3 of type 'Linux' and of size 926.5 GiB.

After completing these steps, pressing p should display a partition table that looks similar to this:

Command (m for help):p
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: HGST HTS721010A9
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xf163b576
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
Device     Boot    Start        End    Sectors   Size Id Type
/dev/sda1  *        2048    2099199    2097152     1G 83 Linux
/dev/sda2        2099200   10487807    8388608     4G 82 Linux swap / Solaris
/dev/sda3       10487808 1953525167 1943037360 926.5G 83 Linux

Saving the partition layout

Press w to write the partition layout and exit fdisk:

Command (m for help):w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Now it is time to put filesystems on the partitions.