Logo

CharlesTech.net

Formatting A Large HDD Linux In The Command Line

The following process below can be used to format a large HDD via the CLI, and also includes a portion to change the reserved blocks which I'd only suggest using on an HDD that isn't part of a critical workflow/workload. I pulled most of this information from one of my favorite youtuber's, Jeff Geerling, blog article found here. I would also highly, highly recommend Mr. Geerling's Youtube Channel.

How to format a large disk:
$ sudo parted /dev/sda
(parted) mklabel gpt             # to create a partition table
(parted) print                   # to verify parition info
(parted) mkpart primary 0% 100%  # create primary partition filling entire disk
(parted) quit

$ sudo fdisk -l /dev/sda                                        
Disk /dev/sda: 7.3 TiB, 8001563222016 bytes, 15628053168 sectors
Disk model: Samsung SSD 870 
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: 44C96693-5B5E-4ABB-AEEC-A60C613E7EC6

Device     Start         End     Sectors  Size Type
/dev/sda1   2048 15628052479 15628050432  7.3T Linux filesystem

$ sudo mkfs.ext4 /dev/sda1
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done                            
Creating filesystem with 1953506304 4k blocks and 244191232 inodes
Filesystem UUID: c597dcb4-83b2-4a93-a8a0-34d17af17729
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848, 512000000, 550731776, 644972544, 1934917632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done 

MODIFY THE EXISTING BLOCK RESERVATION TO 2% VIA TUNE2FS:
# tune2fs -m2 /dev/sda1