Skip to content

Instantly share code, notes, and snippets.

@kpb
Last active November 7, 2020 16:09
Show Gist options
  • Save kpb/5de0714348e0c6cab2c96e69c4eb5446 to your computer and use it in GitHub Desktop.
Save kpb/5de0714348e0c6cab2c96e69c4eb5446 to your computer and use it in GitHub Desktop.

Formatting and labeling an ext4 disc

Writing this down because I have to look it up every damn time.

Assuming the drive is /dev/sdb.

Unmount the Drive (if needed)

$ umount /dev/sdb1

Partition With fdisk

$ fdisk /dev/sdb

Wipe the existing file system

Command (m for help): d

Create a new primary partition using the entire disk

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-976773167, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-976773167, default 976773167): 

Created a new partition 1 of type 'Linux' and of size 465.8 GiB

Write the partition and exit

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

Create an Ext4 Filesystem

mkfs.ext4 /dev/sdb

Label the disk

e2label /dev/sdb <label name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment