With my recent experience setting up a Pi400 with an external drive and network installation, I decided I wanted to try setting up a Pi4 to boot from a Seagate Backup+ Hub 8TB drive. What I found was that the default Raspbian installation can’t expand the root filesystem on a drive larger than 2TB because it configures the disk to use MBR partitioning scheme. What follows is how I worked around that to get the system working the way I wanted.
After going through the network installation process, I logged in and looked at the current state of the filesystem:
Linux WimPi4-Backup 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon May 8 09:47:19 2023 from 192.168.0.57
wim@WimPi4-Backup:~ $ cat /boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=aeb14624-02 rootfstype=ext4 fsck.repair=yes rootwait
wim@WimPi4-Backup:~ $ cat /etc/fstab
proc /proc proc defaults 0 0
PARTUUID=aeb14624-01 /boot vfat defaults 0 2
PARTUUID=aeb14624-02 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that
wim@WimPi4-Backup:~ $ ls -alF /dev/disk/by-partuuid/
total 0
drwxr-xr-x 2 root root 80 May 8 09:48 ./
drwxr-xr-x 7 root root 140 May 8 09:48 ../
lrwxrwxrwx 1 root root 10 May 8 09:48 aeb14624-01 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 8 09:48 aeb14624-02 -> ../../sda2
wim@WimPi4-Backup:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 7.3T 0 disk
├─sda1 8:1 0 256M 0 part /boot
└─sda2 8:2 0 1.7G 0 part /
wim@WimPi4-Backup:~ $ lsusb
Bus 002 Device 003: ID 0bc2:ab38 Seagate RSS LLC Backup Plus Hub (Mass Storage)
Bus 002 Device 002: ID 0bc2:ab45 Seagate RSS LLC Backup+ Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 045e:0768 Microsoft Corp. Sidewinder X4
Bus 001 Device 004: ID 045e:0025 Microsoft Corp. IntelliEye Mouse
Bus 001 Device 003: ID 0bc2:ab44 Seagate RSS LLC Backup Plus Hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
wim@WimPi4-Backup:~ $ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
|__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/3p, 5000M
|__ Port 1: Dev 3, If 0, Class=Mass Storage, Driver=uas, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/3p, 480M
|__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 4: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 4: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 12M
I ran the gdisk command to create a GUID Partition Table
wim@WimPi4-Backup:~ $ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.6
Warning: Partition table header claims that the size of partition table
entries is 0 bytes, but this program supports only 128-byte entries.
Adjusting accordingly, but partition table may be garbage.
Caution: invalid main GPT header, but valid backup; regenerating main header
from backup!
Warning: Invalid CRC on main header data; loaded backup partition table.
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.
Warning! Main partition table CRC mismatch! Loaded backup partition table
instead of main partition table!
Warning! One or more CRCs don't match. You should repair the disk!
Main header: ERROR
Backup header: OK
Main partition table: ERROR
Backup partition table: OK
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: damaged
Found valid MBR and corrupt GPT. Which do you want to use? (Using the
GPT MAY permit recovery of GPT data.)
1 - MBR
2 - GPT
3 - Create blank GPT
Your answer: 1
Command (? for help): p
Disk /dev/sda: 15628053167 sectors, 7.3 TiB
Model: Backup+ Hub BK
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): E7CBB654-BC7B-49D9-839E-0067FF1C3A83
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 15628053133
Partitions will be aligned on 2048-sector boundaries
Total free space is 15623957100 sectors (7.3 TiB)
Number Start (sector) End (sector) Size Code Name
1 8192 532479 256.0 MiB 0700 Microsoft basic data
2 532480 4104191 1.7 GiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
I looked to see the new partition ids of the volumes.
wim@WimPi4-Backup:~ $ ls -alF /dev/disk/by-partuuid/
total 0
drwxr-xr-x 2 root root 80 May 8 10:00 ./
drwxr-xr-x 8 root root 160 May 8 10:00 ../
lrwxrwxrwx 1 root root 10 May 8 10:02 3ecc3350-be31-438c-8876-76a6067d814e -> ../../sda2
lrwxrwxrwx 1 root root 10 May 8 10:02 74fb4bbc-f03a-4501-9b49-13b324f40a64 -> ../../sda1
wim@WimPi4-Backup:~ $ cat /boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=aeb14624-02 rootfstype=ext4 fsck.repair=yes rootwait
I had to modify the /boot/cmdline.txt and /etc/fstab files to update the PARTUUID values to the new vales in the GUID Partition Table. After modifying the files they now appear:
wim@WimPi4-Backup:~ $ sudo nano /boot/cmdline.txt
wim@WimPi4-Backup:~ $ cat /boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=3ecc3350-be31-438c-8876-76a6067d814e rootfstype=ext4 fsck.repair=yes rootwait
At this point I rebooted the device to make sure it still boots and the existing partitions get mounted correctly. I rebooted the Pi many times during this setup because I wanted to make sure each step was done properly.
wim@WimPi4-Backup:~ $ sudo systemctl reboot
wim@WimPi4-Backup:~ $ Connection to 192.168.0.66 closed by remote host.
Connection to 192.168.0.66 closed.
C:\Users\Wim>ssh 192.168.0.66
Linux WimPi4-Backup 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon May 8 10:10:44 2023 from 192.168.0.57
wim@WimPi4-Backup:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.7G 1.4G 213M 87% /
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.2M 1.6G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/sda1 255M 31M 225M 13% /boot
tmpfs 782M 0 782M 0% /run/user/1000
So far so good. The issue now is that the root partition is only 1.7G in size. To fix this, I’m going to run fdisk, delete the root partition, and create it again in the same starting location but with the size I want.
wim@WimPi4-Backup:~ $ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 7.28 TiB, 8001563221504 bytes, 15628053167 sectors
Disk model: Backup+ Hub BK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: E7CBB654-BC7B-49D9-839E-0067FF1C3A83
Device Start End Sectors Size Type
/dev/sda1 8192 532479 524288 256M Microsoft basic data
/dev/sda2 532480 4104191 3571712 1.7G Linux filesystem
Command (m for help): i
Partition number (1,2, default 2):
Device: /dev/sda2
Start: 532480
End: 4104191
Sectors: 3571712
Size: 1.7G
Type: Linux filesystem
Type-UUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
UUID: 3ECC3350-BE31-438C-8876-76A6067D814E
Name: Linux filesystem
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): n
Partition number (2-128, default 2):
First sector (34-15628053133, default 532480):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-15628053133, default 15628053133): +500G
Created a new partition 2 of type 'Linux filesystem' and of size 500 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N
Command (m for help): p
Disk /dev/sda: 7.28 TiB, 8001563221504 bytes, 15628053167 sectors
Disk model: Backup+ Hub BK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: E7CBB654-BC7B-49D9-839E-0067FF1C3A83
Device Start End Sectors Size Type
/dev/sda1 8192 532479 524288 256M Microsoft basic data
/dev/sda2 532480 1049108479 1048576000 500G Linux filesystem
Command (m for help): w
The partition table has been altered.
Syncing disks.
wim@WimPi4-Backup:~ $ ls -alF /dev/disk/by-partuuid/
total 0
drwxr-xr-x 2 root root 80 May 8 10:21 ./
drwxr-xr-x 8 root root 160 May 8 10:08 ../
lrwxrwxrwx 1 root root 10 May 8 10:21 4178f32f-bc1b-474a-99b7-b750ce89fdd7 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 8 10:21 74fb4bbc-f03a-4501-9b49-13b324f40a64 -> ../../sda1
wim@WimPi4-Backup:~ $ sudo nano /boot/cmdline.txt
wim@WimPi4-Backup:~ $ sudo nano /etc/fstab
wim@WimPi4-Backup:~ $ sudo systemctl reboot
wim@WimPi4-Backup:~ $ Connection to 192.168.0.66 closed by remote host.
Connection to 192.168.0.66 closed.
The GUID for the partition I changed has been changed, so I now need to update both the /boot/cmdline.txt and /etc/fstab files appropriately. I chose to only have the root partition set to 500 gigabytes instead of filling the entire drive because I wanted to have the majority of my drive formatted using the exFat filesystem to be able to plug the drive into a windows machine if I want to recover files directly from the drive.
After changing the partition table with fdisk and changing the /boot/cmdline.txt and /etc/fstab files I rebooted the machine once more to make sure it was operating from the new partition table, and then I ran the resize2fs command to resize the file system.
wim@WimPi4-Backup:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.7G 1.4G 213M 87% /
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.2M 1.6G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/sda1 255M 31M 225M 13% /boot
tmpfs 782M 0 782M 0% /run/user/1000
wim@WimPi4-Backup:~ $ sudo resize2fs /dev/sda2
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 32
The filesystem on /dev/sda2 is now 131072000 (4k) blocks long.
wim@WimPi4-Backup:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 493G 1.4G 471G 1% /
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.2M 1.6G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/sda1 255M 31M 225M 13% /boot
tmpfs 782M 0 782M 0% /run/user/1000
wim@WimPi4-Backup:~ $ sudo systemctl poweroff
wim@WimPi4-Backup:~ $ Connection to 192.168.0.66 closed by remote host.
Connection to 192.168.0.66 closed.
You can see that the filesystem has been resized from 1.7G to 493G. At this point I wanted to test my ssytem by plugging the drive into my windows machine. It all looked good, with a large amount of unalocated space on the drive. I used the windows Disk Managment tool to allocate that free space to a new volume and quick format it to exFat. I ejected it and restarted the Pi from the drive and reconnected.
wim@WimPi4-Backup:~ $ ls -alF /dev/disk/by-partuuid/
total 0
drwxr-xr-x 2 root root 100 May 8 10:34 ./
drwxr-xr-x 8 root root 160 May 8 10:34 ../
lrwxrwxrwx 1 root root 10 May 8 10:34 0a14a02f-ce46-4797-81dc-81e476205906 -> ../../sda3
lrwxrwxrwx 1 root root 10 May 8 10:34 4178f32f-bc1b-474a-99b7-b750ce89fdd7 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 8 10:34 74fb4bbc-f03a-4501-9b49-13b324f40a64 -> ../../sda1
wim@WimPi4-Backup:~ $ sudo mkdir /media/`hostname`
wim@WimPi4-Backup:~ $ sudo nano /etc/fstab
wim@WimPi4-Backup:~ $ cat /etc/fstab
proc /proc proc defaults 0 0
PARTUUID=74fb4bbc-f03a-4501-9b49-13b324f40a64 /boot vfat defaults 0 2
PARTUUID=4178f32f-bc1b-474a-99b7-b750ce89fdd7 / ext4 defaults,noatime 0 1
PARTUUID=0a14a02f-ce46-4797-81dc-81e476205906 /media/WimPi4-Backup exfat defaults,uid=1000,gid=1000 0 2
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that
wim@WimPi4-Backup:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 493G 1.4G 471G 1% /
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 1.6G 1.2M 1.6G 1% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/sda1 255M 31M 225M 13% /boot
tmpfs 782M 0 782M 0% /run/user/1000
/dev/sda3 6.8T 10M 6.8T 1% /media/WimPi4-Backup
I edited the /etc/fstab file to include a third line for the new partition I wanted mounted with some extra options since it doesn’t support the ext4 file permissions and I wanted to make it easier to access.
Pingback: SNMP on Raspberry Pi and missing information | WimsWorld