Before using the M.2 HAT+ with your Raspberry Pi 5, you'll need to follow some steps to setup the hat. Raspberry Pi has steps laid out on their site on how to install the hat on Raspberry Pi OS. These steps are more than likely subject to change depending on updates with Raspberry Pi OS.
M.2 Drive
Before using an M.2 Drive with the hat, you'll need to format and partition it for the Raspberry Pi to recognize it. You can use a USB to M.2 drive adapter to connect the drive to another computer. Use your operating system's drive format utility (Disk Utility on macOS, Disk Management on Windows, etc) to format the drive. Multiple formats are acceptable, exFAT and NTFS were tested.
After formatting the drive, insert the drive into the hat and attach the hat to the Raspberry Pi as described in the Raspberry Pi documentation.
Automatic Mounting
To make sure that your M.2 drive mounts properly to your Raspberry Pi every time on boot, you can configure it to have a mount point in your OS. First, boot into Raspberry Pi OS and open your File Manager. You should see your M.2 drive listed. Click on the drive. You'll be asked to enter your password to allow access to the drive.
In a terminal, enter the command:
sudo blkid
This lists the connected drives on your Raspberry Pi. You should see a drive listed called /dev/nvme0n1p2
. This is your M.2 drive. Make note of your drive's UUID number. You will need this later when you edit the fstab file.
Next, you'll create a mounting point for the drive. In the terminal, enter:
sudo mkdir /mnt/movie_disk
This creates a folder target called /movie_disk. Then, you'll mount the M.2 drive to this mount point:
sudo mount /dev/nvme0n1p2 /mnt/movie_disk
Edit fstab
Next, you'll edit the fstab file to add the M.2 drive to the list of disks that mount on boot. In the terminal, enter:
sudo nano /etc/fstab
Then add this line to the fstab file, changing the UUID
to your drive's UUID that was listed after running sudo blkid
. Replace fstype
with the file system type (NTFS, exFAT, etc).
UUID=YOUR-UUID-HERE /mnt/movie_disk fstype defaults,auto,users,rw,nofail,umask=000 0 0
Edit config.txt
In the next step, you'll edit the config.txt file to add a device tree overlay for the M.2 drive. In the terminal, enter:
sudo nano /boot/firmware/config.txt
At the bottom of the file, add the lines:
dtparam=nvme
dtparam=pciex1_gen=3
Depending on your drive, you may need to adjust the pciex1_gen
value. 3
is the highest recognized by the Raspberry Pi and most drives use this speed, but refer to your drive's documentation to be sure.
ls /mnt/movie_disk
This lists the files in the movie_disk mount point aka on your M.2 drive. You should see all of the files on your M.2 drive listed.
Text editor powered by tinymce.