NVMe SSD Partitioning, Formatting, and Mounting Documentation

This document describes the complete process of partitioning, formatting, mounting, and performance testing an NVMe solid-state drive (using /dev/nvme0n1 as an example) in a Linux system, applicable to QuecPi Alpha.

Partitioning Operations (Using fdisk)

Partition the NVMe device using the fdisk tool with the following steps:

Enter the Partitioning Interactive Interface

Execute the following command to launch fdisk and specify the target NVMe device:

fdisk /dev/nvme0n1

Interactive Interface Operation Steps

After entering fdisk interactive mode, execute commands in the following order:

Create a GPT Partition Table

Enter g and press Enter to create a GUID Partition Table (GPT), suitable for large-capacity devices (recommended):

Command (m for help): g
Created a new GPT disklabel (GUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)

Create a New Partition

Enter n and press Enter to create a new partition. Keep the subsequent parameters (partition number, start sector, end sector) as default (the entire available space will be used by default):

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-xxxxxxxxx, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-xxxxxxxxx, default xxxxxx): 
Created a new partition 1 of type 'Linux filesystem' and of size XX GiB.

Write the Partition Table and Exit

Enter w and press Enter to write the partition configuration to the device and exit fdisk:

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

After completion, the system will generate a new partition /dev/nvme0n1p1 (where p1 indicates the first partition).

Formatting the Partition (EXT4 Format)

Use the mkfs.ext4 tool to format the new partition into the EXT4 file system (suitable for most Linux environments):

mkfs.ext4 /dev/nvme0n1p1

After execution, the formatting progress will be displayed, and similar information will be output upon completion:

mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 12345678 4k blocks and 3456789 inodes
Filesystem UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Superblock backups stored on blocks: 
  32768, 98304, 163840, ...
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done

Manually Mounting the Partition

Create a Mount Directory

Use the mkdir command to create a directory for mounting the SSD (example path: /mnt/myssd):

mkdir -p /mnt/myssd

Mount the Partition

Mount the /dev/nvme0n1p1 partition to the /mnt/myssd directory:

mount /dev/nvme0n1p1 /mnt/myssd

You can verify the mounting success using the df -h command. If the output contains /dev/nvme0n1p1 and /mnt/myssd, the mounting is normal:

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1  100G   5G   95G   5% /mnt/myssd

Configuring Automatic Mounting (Effective After Reboot)

Implement automatic mounting of the partition during system startup by modifying the /etc/fstab file:

Edit the fstab File

Open /etc/fstab using the nano editor (other editors like vim can also be used):

Add Mount Configuration

Add the following line at the end of the file to specify the partition, mount point, file system type, and mount parameters:

/dev/nvme0n1p1  /mnt/myssd  ext4  defaults  0  2

Performance Testing (Read/Write Speed Verification)

Use the dd command to test the read/write performance of the SSD (ensure the partition is mounted during testing):

Read Speed Test

Create a temporary test file (if it already exists) and test the read speed by reading the file to the null device (/dev/null):

dd if=/mnt/myssd/testfile of=/dev/null bs=1G iflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.852345 s, 1.3 GB/s

Write Speed Test

Generate a 1GB empty file (/dev/zero as the source of zero data) to test the write speed:

dd if=/dev/zero of=/mnt/myssd/testfile bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.245678 s, 862 MB/s

After testing, you can delete the temporary file:

rm /mnt/myssd/testfile