Skip to content

Instantly share code, notes, and snippets.

@keithmorris
Last active May 7, 2026 02:01
Show Gist options
  • Select an option

  • Save keithmorris/b2aeec1ea947d4176a14c1c6a58bfc36 to your computer and use it in GitHub Desktop.

Select an option

Save keithmorris/b2aeec1ea947d4176a14c1c6a58bfc36 to your computer and use it in GitHub Desktop.
Partition, format, and mount a drive on Ubuntu

Partition, format, and mount a drive on Ubuntu

Reference:

List logical disks and partitions

sudo fdisk -l

Partition the disk

sudo fdisk /dev/sdb

  • Press n to create a partition
  • Press p or l to create primary or logical partitions
  • Press w to write your changes or q to quit

Format the partition

  • sudo mkfs -t ext4 /dev/sdb1
  • sudo mkfs -t ext4 -N 2000000 /dev/sdb1 - This will manually set the number of inodes to 2,000,000

Mount disk

  • mount - Shows what is mounted
  • mkdir /mnt/mydrive
  • mount -t ext4 /dev/sdb1 /mnt/mydrive

Get disk's UUID

ls -al /dev/disk/by-uuid/
or
blkid

Mount at boot

Add the following line to your /etc/fstab file adjusting the UUID to your device's id and the directory to where you want to mount:

UUID=811d3de0-ca6b-4b61-9445-af2e306d9999 /mnt/mydrive ext4 defaults 0 0

mount -a - remounts filesystems from /etc/fstab

@moeiscool
Copy link
Copy Markdown

lifesaver should hire you because this saved my life.

@noah2121
Copy link
Copy Markdown

Easiest and simplest guide, thanks :)

@dimmduh
Copy link
Copy Markdown

dimmduh commented Mar 2, 2020

Easy and clean guide. Thx!

@moeiscool
Copy link
Copy Markdown

just letting you know im still using this, thanks!

@YourAKShaw
Copy link
Copy Markdown

Thank you @keithmorris for this! 🙏

@IntrovertedFL
Copy link
Copy Markdown

Life saver! 💯

@kkyucon
Copy link
Copy Markdown

kkyucon commented Jan 15, 2023

Nice work. Quit handy if your drive is small and you prefer the MBR partitions versus GPT.

For large drives and GPT partitions you want to take a look here.

@javib94
Copy link
Copy Markdown

javib94 commented Sep 25, 2024

Never delete this please, using it since 2022.

@easymoney322
Copy link
Copy Markdown

On newer versions of ubuntu you can also use /dev/disk/by-uuid/811d3de0-ca6b-4b61-9445-af2e306d9999 to select source uuid.
Great post tho

@Rockstar5645
Copy link
Copy Markdown

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment