Formatting a drive in linux
To partition and format your drive in Linux
Open the parted utility and then you will work inside (parted) that.
To partition and format your drive in Linux after zeroing, follow these steps. Replace `sdX` with your drive’s identifier (check with `lsblk`). Ensure the drive is unmounted (`sudo umount /dev/sdX*`) and data is backed up, as these steps will erase existing structures.
1. Create a Partition Table and Partition:
sudo fdisk /dev/sdX
- Press `g` to create a new GPT partition table. (MBR is for booting drive)
- Press `n` to create a new partition:
- Select default partition number (e.g., 1). If you want all space of the drive (one partition)
- Select default first sector.
- Select default last sector (or specify size, e.g., `+100G` for 100GB).
- Press `w` to write changes and exit.
**2. Format the Partition:**
sudo mkfs.ext4 /dev/sdX1
- This formats the first partition (`sdX1`) as ext4. Replace `ext4` with `vfat` for FAT32, `ntfs` for NTFS, etc.
- Progress is shown during formatting.
**3. Verify:**
lsblk -f
- Confirms the new partition and filesystem.
**Notes:**
- Check drive with `lsblk` to confirm `sdX`.
- For multiple partitions, repeat `n` in `fdisk` for each partition, then format each (e.g., `mkfs.ext4 /dev/sdX2`).
- If errors occur, ensure the drive is not mounted (`umount /dev/sdX*`).