HOW TO: Manage Partitions and Format a Drive:
What is a Partitioning?
What is Formatting?
- Erasing Data: Formatting a drive wipes out all existing data stored on it. This includes files, folders, and any other information stored on the drive’s storage media. Once the formatting process is complete, the drive will appear empty, as if it were brand new.
- Creating a File System: A file system is a method used by operating systems to organize and store data on a storage device. When you format a drive, you choose a specific file system to use, such as FAT32, NTFS (Windows), exFAT, HFS+ (macOS), or ext4 (Linux). The file system you choose determines how data is organized, accessed, and stored on the drive.
- Partitioning (Optional): In addition to creating a file system, you can also partition a drive during the formatting process. Partitioning involves dividing the physical storage space of the drive into separate sections, each of which behaves like a separate drive with its own file system. This allows you to organize and manage your data more efficiently, such as having separate partitions for the operating system and user data.
- Quick Format vs. Full Format: When formatting a drive, you typically have the option to perform a quick format or a full format. A quick format only erases the file system metadata, making the drive appear empty, but it doesn’t actually erase the data stored on the drive. A full format, on the other hand, performs a more thorough erasure of the drive, including overwriting all sectors with zeros. A full format takes longer but ensures that all existing data is securely erased from the drive.
- Compatibility: The choice of file system and partitioning scheme can affect the drive’s compatibility with different operating systems and devices. For example, FAT32 is widely compatible across different platforms but has limitations on file size and partition size. NTFS is commonly used in Windows environments for its advanced features and security capabilities. exFAT is suitable for use with both Windows and macOS systems and supports large file sizes and partitions.
Overall, formatting a drive is a crucial step in preparing it for use, whether you’re setting up a new drive, repurposing an existing one, or troubleshooting storage-related issues. However, it’s important to note that formatting permanently erases all data on the drive, so it’s essential to back up any important files before proceeding with the formatting process.
Partitioning and Formatting Options:
Partition Schemes: A partition scheme is a method used to divide a physical storage device, such as a hard drive or SSD, into separate sections called partitions. Each partition behaves like a distinct storage unit, with its own file system and directory structure. Partitioning allows you to organize and manage your data more efficiently, as you can allocate different partitions for different purposes, such as storing the operating system, applications, user data, and system backups. Common partition schemes include MBR (Master Boot Record) and GPT (GUID Partition Table). These schemes define how partition information is stored on the disk and how the operating system accesses and manages partitions.
- MBR (Master Boot Record): MBR is an older partitioning scheme that has been widely used for many years. It supports up to four primary partitions or three primary partitions and one extended partition containing multiple logical partitions. MBR is compatible with both BIOS-based and UEFI-based systems, but it has limitations, such as a maximum partition size of 2TB and compatibility issues with drives larger than 2TB.
- GPT (GUID Partition Table): GPT is a newer partitioning scheme designed to overcome the limitations of MBR. It supports up to 128 partitions and can handle drives larger than 2TB. GPT is required for booting from drives larger than 2TB on UEFI-based systems. It also provides redundancy and resilience against data corruption through the use of backup partition tables.
File System Formats: A file system format (or simply file system) is a method used by operating systems to organize and store data on a storage device. File systems define how data is structured, accessed, and managed on the storage device, including how files and directories are organized, how data is stored and retrieved, and how file metadata (such as permissions and timestamps) is managed. Different operating systems support different file system formats, and each format has its own features, limitations, and performance characteristics. Common file system formats include FAT32, NTFS, exFAT, ext4, and XFS. Each format is optimized for specific use cases and platforms, and the choice of file system format depends on factors such as the operating system being used, compatibility requirements, and the intended use of the storage device.
- FAT32 (File Allocation Table): FAT32 is a widely compatible file system format supported by various operating systems, including Windows, macOS, and Linux. It is suitable for USB flash drives, memory cards, and other removable storage devices. However, FAT32 has limitations, such as a maximum file size of 4GB and a maximum partition size of 2TB.
- NTFS (New Technology File System): NTFS is the default file system format used by Windows operating systems. It offers support for large file sizes, file compression, encryption, and access control lists (ACLs). NTFS is suitable for internal hard drives and external storage devices used primarily with Windows systems.
- exFAT (Extended File Allocation Table): exFAT is a file system format designed to overcome the limitations of FAT32, such as the maximum file size and partition size. It is supported by Windows, macOS, and Linux and is suitable for external storage devices, especially those used to transfer large files between different operating systems. However, exFAT may not be as widely supported on older systems.
- ext4 (Fourth Extended File System): ext4 is the default file system format used by many Linux distributions. It offers improvements over its predecessor, ext3, including larger file sizes, faster file system checking, and better performance with large directories. ext4 supports features such as journaling, file system encryption, and extended attributes.
- ZFS (Zettabyte File System): While not native to Linux, ZFS is a powerful file system originally developed by Sun Microsystems (now Oracle). It offers features such as data integrity protection, data compression, and built-in RAID-like capabilities. ZFS is commonly used in FreeBSD and other Unix-like operating systems, and there are projects to bring ZFS support to Linux.
This Turotial is split into 4 Parts, Index:
- >Part I Finding Drive name and Unmounting.
- >Part II Changing Partition Schemes.
- >Part III Creating Partition tables. If you want to Create a Partition or Multiple Partitions.
- >Part IV Formatting. If you just want to Format a drive.
Part I: Finding Drive name and Unmounting:
Step 1: Finding Drive information.
First we need to find the drive name for the drive we are working with. To do this, in terminal type:
sudo lsblk
This is going to list all the drives located on your system. If you do not see your drive, make sure it’s plugged in.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 465.8G 0 disk
sdb 8:16 0 465.8G 0 disk
nvme0n1 259:0 0 465.8G 0 disk
nvme2n1 259:1 0 931.5G 0 disk
└─nvme2n1p1 259:2 0 931.5G 0 part
nvme1n1 259:3 0 232.9G 0 disk
├─nvme1n1p1 259:4 0 512M 0 part /boot/efi
└─nvme1n1p2 259:5 0 232.4G 0 part /
For a clearer understanding of which drive is which, use:
sudo fdisk -l
This will give you the Device manufacture name which should give you a better idea of which drive you’re looking for. eg:
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Samsung SSD 860
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” /dev/sda, is a 512 GB(465.76 GiB) Samsung 860 SSD, is located at /dev/sda and, has a Partition Scheme of MBR. We will change the Partition Scheme to GPT, create a new Partition, and create an ext4 filesystem.
Step 2: Unmount Partitions:
If your drive has multiple partitions, we need to first unmount each partition sdX1, sdX2, etc..:
sudo umount /dev/sdX1
sudo umount /dev/sdX2
### Remember to replace /sdX with the drive you are working with!!!
Part II: Change Partition Schemes:
After each Partition has been unmounted, run fdisk with the drive you are working with:
sudo fdisk /dev/sdX
### Remember to replace /sdX with the drive you are working with!!!
This will open drive sda in fdisk “fdisk”: is a command-line utility used in Unix-like operating systems, including Linux, for disk partitioning tasks. It enables users to create, delete, resize, and manage partitions on storage devices such as hard drives, SSDs, and USB drives, offering low-level access to disk partitioning functionality.
sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
g
Created a new GPT disklabel (GUID: A9CA981E-647B-2242-9173-E92F69EF752A).
The device contains 'dos' 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):
w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Here we are using:
g
This creates a new empty GPT partition table. If you want to change from GPT to MBR use “o” instead of “g”
Then:
w
This will write the new GPT table to disk and exit (saves and exits)
Part III: Create a New Partition Table:
Step 1: Create a Partition, Or Multiple Partitions:
To Create a Partition or Multiple Partitions open fdisk
with the drive you are working with.
sudo fdisk /dev/sdX
### Remember to replace /sdX with the drive you are working with!!!
sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
n
Partition number (1-128, default 1):
[Enter] (leave blank)
First sector (2048-976773134, default 2048):
[Enter] (leave blank)
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-976773134, default 976773134):
[Enter] (leave blank to use *full drive space)
Created a new partition 1 of type 'Linux filesystem' and of size 465.8 GiB.
Command (m for help):
w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
This time we are using:
n
This will create a new partition. *If you want to create multiple partitions, make sure to leave some space for the other partitions.
If you want to create another partition, use “n” again:
n
Go though the steps again, this time the Partition number will be 2.
w
To write (save and exit).
The Partition or Partitions have now been created. If you run another lsblk
you will see the new partitions listed under your drive:
sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 465.8G 0 disk
└─sda1 8:1 0 465.8G 0 part
We now have to create a Filesystem for storage. See Part IV Formatting,
Part IV: Formatting, How to Format a drive:
To be able to store data, we have to create a filesystem. We do this by formatting the drive:
To format with an ext4 filesystem:
sudo mkfs.ext4 /dev/sdX1
### Remember to replace /sdX with the drive you are working with!!!
To format with a NTFS:
sudo mkfs.ntfs /dev/sdX1
It will notify you if there’s a filesystem currently on the drive, and ask if you want to proceed anyways(delete and create new), answer yes.
The Drive is now ready to use. Just mount to a directory and that’s all she wrote:
sudo mount /dev/sdX1 /mount/point