5

When I first connected my new hard drive enclosure with 4TB drive to my Pi, the drive was not listed when I typed sudo fdisk -l. I want to mount this drive, but I think I first need to partition it and add a file system. What to do? Are there special considerations, given that this is a very large drive?

At one point I thought I had it formatted correctly, but then I noticed the Pi only knew about 2.2TB of the total space (As reported by df -H).

I should also mention that the hard disk enclosure is powered. I'm connecting it through a powered USB hub at the moment too.

Details:

  • Insignia USB 3.0 Desktop Hard Disk Drive Enclosure (NS-PCHD335)
  • Seagate 4TB SATA Desktop HDD (STBD4000400)
  • Insignia USB 3.0 Hub with power supply (NS-PCH5431)

2 Answers 2

9

There are a few things that you need to do to get this to work. First, after physically connecting the drive, run dmesg to see the name of the node in /dev. You should find something like this:

[ 5155.744879] usb-storage 1-1.4.3:1.0: USB Mass Storage device detected
[ 5155.753654] scsi host1: usb-storage 1-1.4.3:1.0
[ 5157.013418] scsi 1:0:0:0: Direct-Access     ST4000DM 000-1F2168            PQ: 0 ANSI: 6
[ 5157.015712] sd 1:0:0:0: [sda] Very big device. Trying to use READ CAPACITY(16).
[...]
[ 5157.085733] sd 1:0:0:0: Attached scsi generic sg0 type 0

sda is the /dev node above, and you can see that it is there via ls /dev/sd*.

Assuming this is a new drive, you may only see /dev/sda (or sdb or whatever the node was named), while drives with partitions will have /dev/sda, /dev/sda1, where sda1 is the node for a partition.

With an unpartitioned disk, you will not see it listed if you execute fdisk -l. So you need to add a partition. fdisk is not the easiest tool for the job in this case, because you need to use the GPT partitioning scheme. fdisk will try to use MBR. But because of the way block addresses are stored in MBR, it is only able to index 2.2TB worth of addresses. That's why your drive looked like a 2.2TB drive to the OS, rather than 4TB.

Do this next:

sudo apt-get install gdisk

gdisk will let you create a GPT partition. Type 'p' at the prompt to list any current partitions. Type 'd' to delete partitions. Type 'n' to make a new partition. Assign it the number 1 when prompted. Type 'w' to write the changes. You can see your partition now using fdisk -l. I'll assume it is named sda1.

With a partition in place you need a filesystem. To accomplish that:

sudo mkfs.ext4 /dev/sda1 -L gargantua

The -L option allows you to set a volume label. I used 'gargantua' for reasons. The .ext4 gives us an ext4 filesystem, which is recommended for the Pi.

Now that you have a partition with a file system, you can mount it:

mkdir /home/pi/drives/gargantua # or wherever...
sudo mount /dev/sda1 /home/pi/drives/gargantua/
df -H

df should show you that you have 4TB available and that the drive is mounted where you mounted it.

If you want to automount the drive at boot, you can use the GUID or the volume label. I'll use the label:

sudo cp /etc/fstab /etc/fstab.bk
sudo nano /etc/fstab

You need to add this line, or one more suited to your purposes to /etc/fstab:

LABEL=gargantua /home/pi/drives/gargantua ext4 defaults 0       2

The Wikipedia page on fstab gives decent examples and descriptions for editing fstab, if you need more information.

And that should do it, you have a very very big drive that mounts to the same location whenever it is attached to the Pi or its USB hub.

1
  • Glad it helped :)
    – Rab
    Commented Feb 23, 2019 at 5:29
0

In 2024,

I have Raspberry Pi 4B 8GB with Raspberry Pi OS lite 64bit installed on microSD 16GB and a 4TB SSD connected to USB3 port.

  1. Detect drive (in my case /dev/sda)
sudo fdisk -l
  1. Create partitions with gdisk:
sudo gdisk /dev/sda
command: o // remove existing partitions and create a new protective MBR
command: n // create new partition for bootfs
   First sector: 8192
   Last sector: 1056767
   Hex code: 0700 // for Microsoft basic data type 
command: n // create new partition for rootfs
   First sector: default
   Last sector: default // uses all available space
   Hex code: default // for Linux filesystem
command: w // write configuration to disk
  1. sudo reboot

  2. Copy bootfs and rootfs from microSD to SSD :

sudo dd if=/dev/mmcblk0p1 of=/dev/sda1 status=progress
sudo dd if=/dev/mmcblk0p2 of=/dev/sda2 status=progress
  1. Write down PARTUUIDs of relevant partitions
sudo blkid
  1. Update bootfs cmdline
sudo mount /dev/sda1 /media
sudo nano /media/cmdline.txt

Edit PARTUUID to match /dev/sda2 (rootfs)'s PARTUUID and insert rootdelay=10 before rootwait

  1. Edit fstab
sudo mount /dev/sda2 /media
sudo nano /media/etc/fstab

Edit PARTUUID for both: /boot/firmware and / accordingly, to match your /dev/sda1 (bootfs) and /dev/sda2 (rootfs) PARTUUIDs

  1. sudo poweroff, remove microSD from RPi, power on and wait to login

  2. Resize rootfs partition (in my case 7814035455 - 1056767 = 7812978688 sectors)

sudo resize2fs /dev/sda2 7812978688s
sudo poweroff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.