2021-09-07-Formatting-Drives-Greater-Than-512GB.txt

	Anything greater than 32GB needs to be erased so it can have a FAT32 partition on the drive media, using the rpi-imager program. Then installing the OS to the drive. MicroSDHC U1 Cards have a rating of (100 MB/s Read speed, and 10 MB/s Write speed), while microSDXC U3 Cards have a rating of (100MB/s Read speed, and 50MB/s Write speed), 5 times faster on the writes. My 128GB microSDXC U3 Card was rapidly reaching max, and I had several "Seagate, Backup Plus Slim 1TB USB 3.0 drives, (~ 4 3/8" x 3" x 1/2"), of course the erase program failed! But I found an easy solution! The simple solution was using "fdisk" to set the drive up so "rpi-imager" could use it.

*****See man fdisk(8)*****

frank@frank-desktop:~$ 
frank@frank-desktop:~$ sudo fdisk -l
[sudo] password for frank: 
...

Disk /dev/mmcblk0: 116.48 GiB, 125069950976 bytes, 244277248 sectors
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: 0x3ed6f865

Device         Boot  Start       End   Sectors   Size Id Type
/dev/mmcblk0p1 *      2048    526335    524288   256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      526336 244277214 243750879 116.2G 83 Linux


Disk /dev/sda: 28.64 GiB, 30752636928 bytes, 60063744 sectors
Disk model: Ultra Trek      
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: 0x3ed6f865

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   526335   524288  256M  c W95 FAT32 (LBA)
/dev/sda2       526336 60063710 59537375 28.4G 83 Linux


Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: 99662D3C-3EC0-42F7-BCC0-F26415849DC6

Device      Start        End    Sectors   Size Type
/dev/sdb1      40     409639     409600   200M EFI System
/dev/sdb2  411648 1953523711 1953112064 931.3G Microsoft basic data
frank@frank-desktop:~$ 

*********

Device         Boot  Start       End   Sectors   Size Id Type
/dev/mmcblk0p1 *      2048    526335    524288   256M  c W95 FAT32 (LBA)	# The 128GB microSDXC U3 Card.
/dev/sda1      *      2048    526335    524288   256M  c W95 FAT32 (LBA)	# A 32GB USB 3.0 Flash Drive.
	The first partition is the same on both of these drives, and the new 1TB Hard Drive is /dev/sdb. The numbers are the partitions.

frank@frank-desktop:~$ 
frank@frank-desktop:~$ mount
...
/dev/sda2 on /fd type ext4 (rw,relatime)
/dev/sdb2 on /media/frank/Backup Plus type exfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro,uhelper=udisks2)
frank@frank-desktop:~$ 

*********

	At this point I should have umounted /dev/sdb but everything worked when I umounted it later:

frank@frank-desktop:~$ sudo umount /dev/sdb2
[sudo] password for frank: 
frank@frank-desktop:~$ sudo umount /dev/sdb1
umount: /dev/sdb1: no mount point specified.
frank@frank-desktop:~$ 

*********

frank@frank-desktop:~$ 
frank@frank-desktop:~$ sudo fdisk /dev/sdb		#(The 1 TB hard drive.)
[sudo] password for frank: 

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): m

Help:

  GPT
   M   enter protective/hybrid MBR

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): p
Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: 99662D3C-3EC0-42F7-BCC0-F26415849DC6

Device      Start        End    Sectors   Size Type
/dev/sdb1      40     409639     409600   200M EFI System
/dev/sdb2  411648 1953523711 1953112064 931.3G Microsoft basic data

******
   o   create a new empty DOS partition table	#This will replace the old (gpt) partition or an older partition.	
******

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x8c74d306.
The device contains 'gpt' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.

Command (m for help): p

Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x8c74d306

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-1953525166, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525166, default 1953525166): 526335		#(instead one can write: "+256M" without the ""s.)

Created a new partition 1 of type 'Linux' and of size 256 MiB.

Command (m for help): p
Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x8c74d306

Device     Boot Start    End Sectors  Size Id Type
/dev/sdb1        2048 526335  524288  256M 83 Linux

Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): l

00 Empty            24 NEC DOS          81 Minix / old Lin  bf Solaris        
01 FAT12            27 Hidden NTFS Win  82 Linux swap / So  c1 DRDOS/sec (FAT-
02 XENIX root       39 Plan 9           83 Linux            c4 DRDOS/sec (FAT-
03 XENIX usr        3c PartitionMagic   84 OS/2 hidden or   c6 DRDOS/sec (FAT-
04 FAT16 <32M       40 Venix 80286      85 Linux extended   c7 Syrinx         
05 Extended         41 PPC PReP Boot    86 NTFS volume set  da Non-FS data    
06 FAT16            42 SFS              87 NTFS volume set  db CP/M / CTOS / .
07 HPFS/NTFS/exFAT  4d QNX4.x           88 Linux plaintext  de Dell Utility   
08 AIX              4e QNX4.x 2nd part  8e Linux LVM        df BootIt         
09 AIX bootable     4f QNX4.x 3rd part  93 Amoeba           e1 DOS access     
0a OS/2 Boot Manag  50 OnTrack DM       94 Amoeba BBT       e3 DOS R/O        
0b W95 FAT32        51 OnTrack DM6 Aux  9f BSD/OS           e4 SpeedStor      
0c W95 FAT32 (LBA)  52 CP/M             a0 IBM Thinkpad hi  ea Linux extended 
0e W95 FAT16 (LBA)  53 OnTrack DM6 Aux  a5 FreeBSD          eb BeOS fs        
0f W95 Ext'd (LBA)  54 OnTrackDM6       a6 OpenBSD          ee GPT            
10 OPUS             55 EZ-Drive         a7 NeXTSTEP         ef EFI (FAT-12/16/
11 Hidden FAT12     56 Golden Bow       a8 Darwin UFS       f0 Linux/PA-RISC b
12 Compaq diagnost  5c Priam Edisk      a9 NetBSD           f1 SpeedStor      
14 Hidden FAT16 <3  61 SpeedStor        ab Darwin boot      f4 SpeedStor      
16 Hidden FAT16     63 GNU HURD or Sys  af HFS / HFS+       f2 DOS secondary  
17 Hidden HPFS/NTF  64 Novell Netware   b7 BSDI fs          fb VMware VMFS    
18 AST SmartSleep   65 Novell Netware   b8 BSDI swap        fc VMware VMKCORE 
1b Hidden W95 FAT3  70 DiskSecure Mult  bb Boot Wizard hid  fd Linux raid auto
1c Hidden W95 FAT3  75 PC/IX            bc Acronis FAT32 L  fe LANstep        
1e Hidden W95 FAT1  80 Old Minix        be Solaris boot     ff BBT            

Aliases:
   linux          - 83
   swap           - 82
   extended       - 05
   uefi           - EF
   raid           - FD
   lvm            - 8E
   linuxex        - 85
Hex code or alias (type L to list all): 0c
Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.

Command (m for help): p
Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x8c74d306

Device     Boot Start    End Sectors  Size Id Type
/dev/sdb1        2048 526335  524288  256M  c W95 FAT32 (LBA)

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (526336-1953525166, default 526336): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (526336-1953525166, default 1953525166): 

Created a new partition 2 of type 'Linux' and of size 931.3 GiB.

Command (m for help): p
Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x8c74d306

Device     Boot  Start        End    Sectors   Size Id Type
/dev/sdb1         2048     526335     524288   256M  c W95 FAT32 (LBA)
/dev/sdb2       526336 1953525166 1952998831 931.3G 83 Linux

Command (m for help): v
No errors detected.

Command (m for help): w
The partition table has been altered.	# The following lines show I forgot to: sudo umount /dev/sdb2 /dev/sdb1 before I entered fdisk.
Failed to remove partition 2 from system: Device or resource busy
Failed to add partition 1 to system: Device or resource busy
Failed to add partition 2 to system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

frank@frank-desktop:~$ 
frank@frank-desktop:~$ 
frank@frank-desktop:~$ 

frank@frank-desktop:~$ 
frank@frank-desktop:~$ mount
...
/dev/sda2 on /fd type ext4 (rw,relatime)
/dev/sdb2 on /media/frank/Backup Plus type exfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro,uhelper=udisks2)
frank@frank-desktop:~$ 

frank@frank-desktop:~$ sudo umount /dev/sdb2
[sudo] password for frank: 
frank@frank-desktop:~$ sudo umount /dev/sdb1
umount: /dev/sdb1: no mount point specified.
frank@frank-desktop:~$ 

frank@frank-desktop:~$ 
frank@frank-desktop:~$ sudo fdisk /dev/sdb

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): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): p
Disk /dev/sdb: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x8c74d306

Device     Boot  Start        End    Sectors   Size Id Type
/dev/sdb1         2048     526335     524288   256M  c W95 FAT32 (LBA)
/dev/sdb2       526336 1953525166 1952998831 931.3G 83 Linux

Command (m for help): v
No errors detected.

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

frank@frank-desktop:~$ 

*****************************

	Now I will restart, but I will pull the 32GB USB 3.0 Flash Drive, since the USB 3.0 ports seem to have priority over the microSD port. (power off, remove drive, power on). (The USB 3.0 Flash Drive runs extreamely HOT! I don't think it would last very long at those temperatures!)
	
frank@frank-desktop:~$ 
frank@frank-desktop:~$ mount
...
/dev/mmcblk0p2 on / type ext4 (rw,relatime)
...
/dev/mmcblk0p1 on /boot/firmware type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
...
frank@frank-desktop:~$ 

frank@frank-desktop:~$ 
...

Disk /dev/mmcblk0: 116.48 GiB, 125069950976 bytes, 244277248 sectors
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: 0x3ed6f865

Device         Boot  Start       End   Sectors   Size Id Type
/dev/mmcblk0p1 *      2048    526335    524288   256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      526336 244277214 243750879 116.2G 83 Linux


Disk /dev/sda: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x8c74d306

Device     Boot  Start        End    Sectors   Size Id Type
/dev/sda1         2048     526335     524288   256M  c W95 FAT32 (LBA)
/dev/sda2       526336 1953525166 1952998831 931.3G 83 Linux
frank@frank-desktop:~$ 

**************

	Now it is time to start "rpi-imager" and load "ubuntu-21.04-preinstalled-desktop-arm64+raspi.img.xz" onto /dev/sda since it is now sda and no longer sdb.
	We have basically erased /dev/sda so the next step is select "Use custom" and select our "OS" and "Storage" "Seagate BUP_Slim - 1000.2 GB" then "WRITE". Continue? Yes.
	"ubuntu-21.04-preinstalled-desktop-arm64+raspi.img.xz has been written to Segate BUP_Slim"
	"You can now remove the SD card from the reader" Continue, press "continue" and close "rpi-imager"

frank@frank-desktop:~$ 
frank@frank-desktop:~$ sudo fdisk -l
[sudo] password for frank: 
...

Disk /dev/mmcblk0: 116.48 GiB, 125069950976 bytes, 244277248 sectors
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: 0x3ed6f865

Device         Boot  Start       End   Sectors   Size Id Type
/dev/mmcblk0p1 *      2048    526335    524288   256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      526336 244277214 243750879 116.2G 83 Linux


Disk /dev/sda: 931.51 GiB, 1000204885504 bytes, 1953525167 sectors
Disk model: BUP Slim        
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: dos
Disk identifier: 0x3ed6f865

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   526335   524288  256M  c W95 FAT32 (LBA)
/dev/sda2       526336 17629039 17102704  8.2G 83 Linux				#(Notice the Linux partition is now just 8.2 GB)
frank@frank-desktop:~$ 

	SUCESS!!! When this drive starts it will expand partition 2 to the full drive capacity! Power off! Leave the Hard Drive still plugged into a USB 3.0 port, remove the microSD card, "Power on" the Pi 400. The new hard drive can be the only "OS" plugged in or there will be errors and part of the initialization will be missing. Been there, done that!

*****************************

	Now you will be running the instillation of the new hard drive.
	
Recap:

	When the new large drive is plugged into a USB 3.0 port, it should come up as a drive mounted on something like: "/dev/sdb2 on /media/(frank)/Backup Plus type exfat (rw,nosuid, ...)"
	Take note of the "/dev/sdb2" device address. At this point one can "sudo umount /dev/xxxx" where "xxxx" is your new large drive and partition number.
	Next, "sudo fdisk /dev/xxx" where "xxx" is the complete drive without the partition number.
	Command (m for help): m		Command (   p   print the partition table), (   o   create a new empty DOS partition table), (   n   add a new partition), (Primary, 1), (Size, accept start address, end address "+256M") (   t   change a partition type (Hex code or alias (type L to list all): 0c)), (   n   add a new partition), (Primary, 2), (Size, accept start address, accept end address), (   p   print the partition table), (   v   verify the partition table), (   w   write table to disk and exit).

	At this point you are ready to restart the computer, so it can see your new drive with a "256M, 0c W95 FAT32 (LBA)" partition and the rest of the drive in an "83 Linux" partition. Restart (power off, Power on) and then use "Raspberry Pi Imager" to copy your OS of choice onto your new large drive.

Enjoy!
Frank Anderson, AC0Xl
	
