HowTo Create A GPT Disk With EFI System And exFAT Partitions Using Parted

From NST Wiki
Jump to navigationJump to search

Overview

The purpose of this article is to create a disk that can be read / written to by all major operating systems (i.e., macOS, Windows and Linux). A removable USB storage device containing SSD SATA or NVMe media formatted with an exFAT partition can be used to accomplish this. At the time of this writing, January 02, 2020, a removable USB-C drive containing a CORSAIR FORCE Series MP500 120GB NVMe storage device will be demonstrated.

The USB drive is attached to an NST system as device: "/dev/sdc". The parted disk utility will be used to create a GUID Partition Table (GPT) disk label, the EFI System Partition and the exFAT partition. GPT partitioning allows one to use all available disk space for disk drives that exceed 2TB in size. The is one of the limitations for legacy MBR partitioning.

The following diagram is an example GUID Partition Table layout:

Wikipedia Reference: The layout of a disk with the GUID Partition Table. In this example, each logical block is 512 bytes in size and each entry has 128 bytes. The corresponding partition entries are assumed to be located in LBA 2–33. Negative LBA addresses indicate a position from the end of the volume, with −1 being the last addressable block.

Zero Out Previous Disk Label - Optional

This optional step will zero out any previous disk label. We will use the dcfldd utility. The first 1GB of the disk will be zeroed out:

[root@shopper2 ~]# dcfldd if=/dev/zero of=/dev/sdc statusinterval=64 bs=1M count=1k;
1024 blocks (1024Mb) written.
1024+0 records in
1024+0 records out
[root@shopper2 ~]#

We can now used parted to examine the disk and see that we are starting out with an "unrecognized" disk structure:

[root@shopper2 ~]# /sbin/parted -s /dev/sdc print;
Error: /dev/sdc: unrecognised disk label
Model: JM583  (scsi)
Disk /dev/sdc: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
[root@shopper2 ~]#

Create GPT Disk Label

The GPT disk label will now be created:

[root@shopper2 ~]# parted /dev/sdc;
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) quit
Information: You may need to update /etc/fstab.

[root@shopper2 ~]# /sbin/parted -s /dev/sdc print;                        
Model: JM583  (scsi)
Disk /dev/sdc: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags

[root@shopper2 ~]#

Create EFI System Partition

A new EFI System Partition will be created using the following commands (the recommended size is at least 260 MiB):

[root@shopper2 ~]# parted /dev/sdc;
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart primary fat32 1MiB 261MiB                                 
(parted) set 1 esp on                                                     
(parted) print                                                            
Model: JM583  (scsi)
Disk /dev/sdc: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  274MB  273MB  fat32        primary  boot, esp

(parted) quit                                                             
Information: You may need to update /etc/fstab.

[root@shopper2 ~]#

Create exFAT Partition

A new exFAT partition will now be created using the remaining unused disk area:

[root@shopper2 ~]# parted /dev/sdc;                        
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: JM583  (scsi)
Disk /dev/sdc: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  274MB  273MB               primary  boot, esp

(parted) mkpart primary ntfs 261MiB 100%
(parted) print                                                            
Model: JM583  (scsi)
Disk /dev/sdc: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  274MB  273MB               primary  boot, esp
 2      274MB   120GB  120GB  ntfs         primary

(parted) quit                                                             
Information: You may need to update /etc/fstab.

[root@shopper2 ~]# /sbin/parted -s /dev/sdc print;                        
Model: JM583  (scsi)
Disk /dev/sdc: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  274MB  273MB               primary  boot, esp
 2      274MB   120GB  120GB               primary  msftdata

[root@shopper2 ~]#

Format exFAT Partition

Use the "mkfs.exfat" command to format the exFAT file system:

[root@shopper2 ~]# mkfs.exfat -L NVMe /dev/sdc2
mkexfatfs 1.3.0
Creating... done.
Flushing... done.
File system created successfully.
[root@shopper2 ~]#

The "lsblk" command shows the newly created exFAT file system with label:

[root@shopper2 ~]# /bin/lsblk -a -o name,label,size,fstype,model /dev/sdc;
NAME                     LABEL   SIZE FSTYPE      MODEL
 sdc                            111.8G             USB3.1_NVME_DISK
├─sdc1                           260M             
└─sdc2                   NVMe  111.5G exfat       
[root@shopper2 ~]#

Summary

The newly formatted disk should now be read / written to by all major operating systems (i.e., macOS, Windows and Linux). If not use the method below: Alternate exFat Partition Creation For OS Interoperability.

Alternate exFat Partition Creation For OS Interoperability

This section will show the steps on how to create an entire exFAT partition on a USB 64GB flash drive so that all major OSs (i.e., i.e., macOS, Windows and Linux) can mount and use the data on the drive.

1) Discover the target USB drive to create the exFAT partition with fdisk. In this case it will be "/dev/sda"

[root@dell7480 ~]# fdisk -l;
Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: FPI512MWR7                              
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: gpt
Disk identifier: B276CCFE-BD35-4510-9E92-B6E44CEEFAE8

Device           Start        End   Sectors   Size Type
/dev/nvme0n1p1    2048    1230847   1228800   600M EFI System
/dev/nvme0n1p2 1230848    3327999   2097152     1G Linux filesystem
/dev/nvme0n1p3 3328000 1000214527 996886528 475.4G Linux filesystem

Disk /dev/zram0: 8 GiB, 8589934592 bytes, 2097152 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/sda: 57.3 GiB, 61530439680 bytes, 120176640 sectors
Disk model:  SanDisk 3.2Gen1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@dell7480 ~]# 

2) Make sure the USB flash drive is not mounted. Example: USB drive mounted at: "/run/media/nst/59DF-5291"

[root@dell7480 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.8G     0  7.8G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           3.1G  2.0M  3.1G   1% /run
/dev/nvme0n1p3  476G  8.1G  467G   2% /
tmpfs           7.8G  2.1M  7.8G   1% /tmp
/dev/nvme0n1p3  476G  8.1G  467G   2% /home
/dev/nvme0n1p2  976M  248M  662M  28% /boot
/dev/nvme0n1p1  599M   17M  583M   3% /boot/efi
tmpfs           1.6G   96K  1.6G   1% /run/user/1000
tmpfs           1.6G   72K  1.6G   1% /run/user/0
/dev/sda1        58G   12M   58G   1% /run/media/nst/59DF-5291
[root@dell7480 ~]# 
[root@dell7480 ~]# umount -v /run/media/nst/59DF-5291
umount: /run/media/nst/59DF-5291 (/dev/sda1) unmounted

[root@dell7480 ~]# 

3) Use fdisk to remove any previously created partitions, create a GPT partition table and then make a new partition (i.e., "/dev/sda1") for exFAT using the entire USB drive.

[root@dell7480 ~]# fdisk /dev/sda;

Welcome to fdisk (util-linux 2.36.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 0x997a9a9d.

Command (m for help): d
No partition is defined yet!

Command (m for help): g

Created a new GPT disklabel (GUID: 7D769FCD-8E49-9944-B4BA-C418633F0C4E).

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-120176606, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-120176606, default 120176606): 

Created a new partition 1 of type 'Linux filesystem' and of size 57.3 GiB.

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

[root@dell7480 ~]#

4) Show partition creation progress using parted.

[root@dell7480 ~]# /sbin/parted -s /dev/sda print;
Model:  USB  SanDisk 3.2Gen1 (scsi)
Disk /dev/sda: 61.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  61.5GB  61.5GB

[root@dell7480 ~]#

5) Make sure the boot record is converted to GPT.

[root@dell7480 ~]# gdisk /dev/sda;
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

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.
The operation has completed successfully.

[root@dell7480 ~]#

6) Set the partition type to: "msftdata" - Microsoft Basic Data

[root@dell7480 ~]# parted /dev/sda;
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) set 1 msftdata on                                                
(parted) q                                                                
Information: You may need to update /etc/fstab.

[root@dell7480 ~]#

7) Show partition progress.

[root@dell7480 ~]# parted -s /dev/sda print;                        
Model:  USB  SanDisk 3.2Gen1 (scsi)
Disk /dev/sda: 61.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  61.5GB  61.5GB                     msftdata
 
[root@dell7480 ~]#

8) Now format partition: "/dev/sda1" as an exFAT file system using: mkfs.exfat with label: "THUNDER2-1" with verbose mode on.

[root@dell7480 ~]# mkfs.exfat -v -L THUNDER2-1 /dev/sda1;
exfatprogs version : 1.1.2
[exfat_get_blk_dev_info: 202] Block device name : /dev/sda1
[exfat_get_blk_dev_info: 203] Block device offset : 1048576
[exfat_get_blk_dev_info: 204] Block device size : 61529374208
[exfat_get_blk_dev_info: 205] Block sector size : 512
[exfat_get_blk_dev_info: 206] Number of the sectors : 120174559
[exfat_get_blk_dev_info: 208] Number of the clusters : 469431
[exfat_zero_out_disk: 516] zero out written size : 3538944, disk size : 61529374208
Creating exFAT filesystem(/dev/sda1, cluster size=131072)

Writing volume boot record: [exfat_setup_boot_sector:  81] Volume Offset(sectors) : 2048
[exfat_setup_boot_sector:  83] Volume Length(sectors) : 120174559
[exfat_setup_boot_sector:  85] FAT Offset(sector offset) : 2048
[exfat_setup_boot_sector:  87] FAT Length(sectors) : 3840
[exfat_setup_boot_sector:  89] Cluster Heap Offset (sector offset) : 6144
[exfat_setup_boot_sector:  91] Cluster Count : 469407
[exfat_setup_boot_sector:  93] Root Cluster (cluster offset) : 4
[exfat_setup_boot_sector:  95] Volume Serial : 0xff393695
[exfat_setup_boot_sector:  96] Sector Size Bits : 9
[exfat_setup_boot_sector:  98] Sector per Cluster bits : 8
done
Writing backup volume boot record: [exfat_setup_boot_sector:  81] Volume Offset(sectors) : 2048
[exfat_setup_boot_sector:  83] Volume Length(sectors) : 120174559
[exfat_setup_boot_sector:  85] FAT Offset(sector offset) : 2048
[exfat_setup_boot_sector:  87] FAT Length(sectors) : 3840
[exfat_setup_boot_sector:  89] Cluster Heap Offset (sector offset) : 6144
[exfat_setup_boot_sector:  91] Cluster Count : 469407
[exfat_setup_boot_sector:  93] Root Cluster (cluster offset) : 4
[exfat_setup_boot_sector:  95] Volume Serial : 0xff393695
[exfat_setup_boot_sector:  96] Sector Size Bits : 9
[exfat_setup_boot_sector:  98] Sector per Cluster bits : 8
done
Fat table creation: [exfat_create_fat_table: 307] Total used cluster count : 5
done
Allocation bitmap creation: done
Upcase table creation: done
Writing root directory entry: done
Synchronizing...

exFAT format complete!

[root@dell7480 ~]#

9) Show final format using parted.

[root@dell7480 ~]# parted -s /dev/sda print;
Model:  USB  SanDisk 3.2Gen1 (scsi)
Disk /dev/sda: 61.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  61.5GB  61.5GB                     msftdata

[root@dell7480 ~]#

10) Use the system storage manager (ssm) to show the completed exFAT partition.

[root@dell7480 ~]# ssm list
---------------------------------------------------------------------
Device               Free      Used      Total  Pool      Mount point
---------------------------------------------------------------------
/dev/nvme0n1                         476.94 GB            PARTITIONED
/dev/nvme0n1p1                       600.00 MB            /boot/efi  
/dev/nvme0n1p2                         1.00 GB            /boot      
/dev/nvme0n1p3  465.33 GB  10.02 GB  475.35 GB  dell7480             
/dev/sda                              57.30 GB            PARTITIONED
/dev/sda1                             57.30 GB                       
/dev/zram0                             8.00 GB            SWAP       
---------------------------------------------------------------------
---------------------------------------------------------
Pool      Type   Devices       Free     Used      Total  
---------------------------------------------------------
dell7480  btrfs  1        467.30 GB  8.05 GB  475.35 GB  
---------------------------------------------------------
--------------------------------------------------------------------------------------
Volume          Pool      Volume size  FS       FS size       Free  Type   Mount point
--------------------------------------------------------------------------------------
dell7480        dell7480    475.35 GB  btrfs  475.35 GB  467.30 GB  btrfs             
dell7480:home   dell7480    475.35 GB  btrfs  475.35 GB  467.30 GB  btrfs  /home      
dell7480:root   dell7480    475.35 GB  btrfs  475.35 GB  467.30 GB  btrfs  /          
/dev/nvme0n1p1              600.00 MB  vfat                         part   /boot/efi  
/dev/nvme0n1p2                1.00 GB  ext4     1.00 GB  677.35 MB  part   /boot      
/dev/sda1                    57.30 GB  exfat                        part              
--------------------------------------------------------------------------------------

[root@dell7480 ~]#

11) Just in case, always synchronize cached writes to persistent storage prior to removing the USB flash drive.

[root@dell7480 ~]# sync;sync;

[root@dell7480 ~]#