Skip to content
Published on

Adding an NVMe SSD on Ubuntu

Authors
  • Name
    Twitter

Background

Steps

Installing the SSD

Power off the machine, install the NVMe SSD into the correct slot, and reboot.

Verifying Disk Detection

Confirm that the newly installed 465 GiB NVMe SSD has been properly detected.

root@latte01:~# sudo fdisk -l

...

Disk /dev/nvme0n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: SHGP31-500GM
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

...

Checking Currently Used Disks

You can see that the NVMe SSD (/dev/nvme0n1) installed above has not yet been mounted.

root@latte01:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           777M  2.0M  775M   1% /run
/dev/mmcblk2p2   57G   39G   16G  72% /
tmpfs           3.8G     0  3.8G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/mmcblk2p1  511M  5.3M  506M   2% /boot/efi
tmpfs           777M   88K  777M   1% /run/user/1000

Creating a Disk Partition

Follow the steps below to create a partition on the disk identified above.

root@latte01:~# sudo fdisk /dev/nvme0n1

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x66336a6e.

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

Created a new partition 1 of type 'linux' and of size 465.8 GiB.

Command (m for help): p
Disk /dev/nvme0n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: SHGP31-500GM
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x66336a6e

Device         Boot Start       End   Sectors   Size Id Type
/dev/nvme0n1p1       2048 976773167 976771120 465.8G 83 Linux

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

The message Created a new partition 1 of type 'linux' and of size 465.8 GiB. will appear, and you must type w to actually write the partition.

Checking Disk Status

If you check with fdisk -l, you can see that the disk is now listed as a device, unlike before.

root@latte01:~# sudo fdisk -l

Disk /dev/nvme0n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: SHGP31-500GM
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x66336a6e

Device         Boot Start       End   Sectors   Size Id Type
/dev/nvme0n1p1       2048 976773167 976771120 465.8G 83 Linux

Formatting the Partition

Use the following command to check how other file systems are formatted.

root@latte01:~# sudo blkid
/dev/mmcblk2p2: UUID="aa495c97-2344-4d43-a689-b619820a0210" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="f60e2f86-337d-4890-bfbd-fc6555e075f0"
/dev/loop1: TYPE="squashfs"
/dev/nvme0n1p1: PARTUUID="66336a6e-01"
/dev/mmcblk2p1: UUID="986C-B2FC" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="995635dd-2919-4051-9388-abfd4e42d81e"

root@latte01:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           777M  2.1M  775M   1% /run
/dev/mmcblk2p2   57G   39G   16G  72% /

We want to match the format of /dev/mmcblk2p2, which uses the most storage. Therefore, we will format the new disk with ext4 as well.

Proceed with formatting.

root@latte01:~# sudo mkfs.ext4 /dev/nvme0n1
mke2fs 1.46.5 (30-Dec-2021)
Found a dos partition table in /dev/nvme0n1
Proceed anyway? (y,N)  y
Discarding device blocks: done
Creating filesystem with 122096646 4k blocks and 30531584 inodes
Filesystem UUID: 482ee0df-9d2d-4959-9026-de7206de5aaf
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
	102400000

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

Running sudo blkid will show the disk formatted as ext4.

root@latte01:~# sudo blkid

#AS IS
# /dev/nvme0n1p1: PARTUUID="66336a6e-01"

#TO BE
/dev/nvme0n1: UUID="482ee0df-9d2d-4959-9026-de7206de5aaf" BLOCK_SIZE="4096" TYPE="ext4"

Mounting the Disk

Create a folder to use the disk.

root@latte01:~# mkdir -p /data1

Add the auto-mount information for the new disk to /etc/fstab.

# data1
UUID=482ee0df-9d2d-4959-9026-de7206de5aaf   /data1  ext4    defaults    0   0

After adding:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/mmcblk1p2 during installation
UUID=aa495c97-2344-4d43-a689-b619820a0210 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/mmcblk1p1 during installation
UUID=986C-B2FC  /boot/efi       vfat    umask=0077      0       1
# data1
UUID=482ee0df-9d2d-4959-9026-de7206de5aaf   /data1  ext4    defaults    0   0
/swapfile                                 none            swap    sw              0       0

Applying the Mount

sudo mount -a

Verifying the Result

root@latte01:~# sudo mount -a
root@latte01:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           777M  2.0M  775M   1% /run
/dev/mmcblk2p2   57G   39G   16G  72% /
tmpfs           3.8G     0  3.8G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/mmcblk2p1  511M  5.3M  506M   2% /boot/efi
tmpfs           777M   88K  777M   1% /run/user/1000
/dev/nvme0n1    458G   28K  435G   1% /data1

You can confirm that 458 GiB of storage is now available at the mount point data1.

Reference