Linux Basic Partitioning

From WikiMLT
Revision as of 12:56, 12 September 2022 by Spas (talk | contribs) (Spas moved page Fdisk Basic Partitioning to Linux Basic Partitioning with Fdisk and Mkfs without leaving a redirect)

In this guide we are as­sum­ing that, we want to pre­pare the de­vice /​​​dev/​​​nvme0n1 for Lin­ux UE­FI in­stal­la­tion with LVM and GPT par­ti­tion ta­ble. So the par­ti­tions that will be cre­at­ed are as fol­low:

  • /​​​dev/​​​nvme0n1p1 – EFI Sys­tem (for: /​​​boot/​​​efi),
  • /​​​dev/​​​nvme0n1p2 – Lin­ux filesys­tem (for: /​​​boot),
  • /​​​dev/​​​nvme0n1p3 – Lin­ux LVM (for: /, /​​​home, etc.).

We can use fdisk or gdisk with­in the com­mand line or gpart­ed or oth­er sim­i­lar tool for ma­nip­u­la­tion the par­ti­tion ta­ble via the graph­i­cal user in­ter­face. Note this op­er­a­tion will wipe all par­ti­tions and cre­ate new par­ti­tions you need. In this guide we will use the tool fdisk to ac­com­plish this task.

sudo fdisk /dev/nvme0n1
# Create a new empty GPT partition table:
Command (m for help): g
# Add a new partition:
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-1951473664, default 2048): [Press Enter]
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1951473664, default 1951473664): +512M
Created a new partition 1 of type 'Linux filesystem' and of size 512 MiB.
# Add a new partition:
Command (m for help): n
Partition number (2-128, default 1): 2
First sector (1050624-1951473664, default 1050624): [Press Enter]
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-1951473664, default 1951473664): +488M
Created a new partition 2 of type 'Linux filesystem' and of size 488 MiB.
# Add a new partition:
Command (m for help): n
Partition number (3-128, default 1): 3
First sector (2050048-1951473664, default 2050048): [Press Enter]
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2050048-1951473664, default 1951473664): [Press Enter]
Created a new partition 3 of type 'Linux filesystem' and of size 930.54 GiB.
# Change a partition type:
Command (m for help): t
Partition number (1-3, default 3): 1
Partition type (type L to list all types): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.
# Change a partition type:
Command (m for help): t
Partition number (1-3, default 3): 3
Partition type (type L to list all types): 31
Changed type of partition 'Linux filesystem' to 'Linux LVM'.
# Print the partition table:
Command (m for help): p
Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 1TB                     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: E5B93AC4-141D-4174-B94D-07FCBB074D5C

Device           Start        End    Sectors   Size Type
/dev/nvme0n1p1    2048    1050623    1048576   512M EFI System
/dev/nvme0n1p2 1050624    2050047     999424   488M Linux filesystem
/dev/nvme0n1p3 2050048 1953523711 1951473664 930.5G Linux LVM
#  Verify the partition table
Command (m for help): v
No errors detected.
Header version: 1.0
Using 2 out of 128 partitions.
A total of 0 free sectors is available in 0 segments (the largest is (null)).
# Write the table to the disk and exit:
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.