how to format a storage drive from the terminal: getting a base knowledge to start

dhubs

Member
Joined
Nov 5, 2024
Messages
59
Reaction score
19
Credits
839
good evening dear friends, :cool:

well - normally - when installing linux on a notebook i leave the formate process to the automatic option.

this is due to the lack of knowledge:

therefore i need to know how to format a storage drive from the terminal.

a very helpful thing would be to dive into all that steps - and the options for commands and to get a base knowledge that i (hopefully) am able to use to extrapolate future uses.

as said above - i eagerly would like to know how to format in the different file systems such as NTFS, FAT32, EXT4:

These common formats are something that i think are the ones that are used in many many use-cases: So i think i have to get more information on how to partition the drive via terminal.

besides the notebooks i mentioned above - i sometimes want to set up a a high capacity external hard drive (HDD) from the terminal. Well - my friends often told me, that I can use gparted for this job as well as other GUI programs, Sure thing. but I still want to now how to do it from the terminal. I think that the terminal is damned powerful - and i want to learn to do more on this powerful tool.


so i conclude: it would be awesome if i know, how to format a storage drive from the terminal: i would love to get a base knowledge to start here!

look forward for any and all ideas here ...
 


Whenever I format a drive, which means to write a new file system to it, I always use ext4 so I'm really not sure how to do that for the other types of file systems. I use mke2fs. See the man page for mke2fs(8). A hard drive these days likely uses a physical sector size of 4096 bytes. /usr/sbin/fdisk can tell you. It is certainly worth learning how to use the terminal. I use XTerm for that. Try using something like:

mke2fs -b 4096 -m 0 -E quotatype=usrquota:grpquota -v -L "Volume Label" -t ext4 -U "UUID goes here" -e remount-ro /dev/drivehere

This will create an ext4 type file system with a block size of 4096 bytes, 0% reserved for root, user and group quotas, verbose output while working, a volume label of your choice, just make sure to specify instead of Volume Label, and a UUID of your choice, just make sure to specify, and do so on /dev/drivehere. Make sure to specify the correct block device. You can try it out using a file instead of a block device, like ./tmpfs instead.

It's worth noting that other options exist. You can use /usr/sbin/tune2fs to change some things later too. You will need to run /usr/sbin/e2fsck on the file system first though.

Signed,

Matthew Campbell
 
good evening dear friends, :cool:

well - normally - when installing linux on a notebook i leave the formate process to the automatic option.

this is due to the lack of knowledge:

therefore i need to know how to format a storage drive from the terminal.

a very helpful thing would be to dive into all that steps - and the options for commands and to get a base knowledge that i (hopefully) am able to use to extrapolate future uses.

as said above - i eagerly would like to know how to format in the different file systems such as NTFS, FAT32, EXT4:

These common formats are something that i think are the ones that are used in many many use-cases: So i think i have to get more information on how to partition the drive via terminal.

besides the notebooks i mentioned above - i sometimes want to set up a a high capacity external hard drive (HDD) from the terminal. Well - my friends often told me, that I can use gparted for this job as well as other GUI programs, Sure thing. but I still want to now how to do it from the terminal. I think that the terminal is damned powerful - and i want to learn to do more on this powerful tool.


so i conclude: it would be awesome if i know, how to format a storage drive from the terminal: i would love to get a base knowledge to start here!

look forward for any and all ideas here ...
To get some base knowledge for partitioning and formatting an external drive, it's worth understanding some general ideas about both processes for they are distinct and use different tools.

Following are some general observations for consideration with links since they describe in detail information that is unnecessary to repeat here.

Tools for partitioning the disk include command line tools and GUI tools. Command line tools include: fdisk, gdisk, parted, cfdisk, sfdisk. GUI partitioning tools are: Gparted, Gnome Disks Utility, KDE Partition Manager. There are others.

A commonly used command line partitioning tool is fdisk. The following links give some details in using fdisk. Note that it needs root permissions to do its work:



General info on partitioning is here:

Tools for formatting a filesystem to a partition are provided by the command: mkfs. To see the filesystems available, one can press the TAB key twice for filename completion on the mkfs command, after which the full command names for filesystems available for writing are shown:
Code:
$ mkfs<TAB><TAB>
mkfs         mkfs.bfs     mkfs.cramfs
mkfs.exfat   mkfs.ext2    mkfs.ext3
mkfs.ext4    mkfs.fat     mkfs.minix
mkfs.msdos   mkfs.ntfs    mkfs.vfat
Each of these has a manpage (e.g. man mkfs.ext4) to show what options are available. For example, to write a Fat 32 filesystem one would use:
Code:
mkfs.fat -F 32 /dev/sda1
where /dev/sda1 is the partition which has been previously created by use of one of the partitioning tools.

Aspects about partitioning and formatting filesystems include the following:

Partitioning and formatting are done on disks and partitions that are not mounted.

A common way of using the partitioning and filesystem formatting tools on an installed system, rather than an external drive, is from a live disk, or a rescue disk or specialised disk like the Gparted bootable disk. Partitioning of an external drive can be done from a live installed system as long as the external drive is not mounted, so a live disk is not needed in that situation, rather, the user needs to have the tools on the running system. The command line tools are usually included by default.

Partitioning and formatting benefit from the old rule "measure twice, cut once", that is, for optimal outcomes the user needs to make sure that the partitioning tool is accessing the intended drive, and that the formatting tool is accessing the intended partition, so double checking before writing to disk wins.
 
Last edited:
good evening dear friends, :cool:

well - normally - when installing linux on a notebook i leave the formate process to the automatic option.

this is due to the lack of knowledge:

therefore i need to know how to format a storage drive from the terminal.

a very helpful thing would be to dive into all that steps - and the options for commands and to get a base knowledge that i (hopefully) am able to use to extrapolate future uses.

as said above - i eagerly would like to know how to format in the different file systems such as NTFS, FAT32, EXT4:

These common formats are something that i think are the ones that are used in many many use-cases: So i think i have to get more information on how to partition the drive via terminal.

besides the notebooks i mentioned above - i sometimes want to set up a a high capacity external hard drive (HDD) from the terminal. Well - my friends often told me, that I can use gparted for this job as well as other GUI programs, Sure thing. but I still want to now how to do it from the terminal. I think that the terminal is damned powerful - and i want to learn to do more on this powerful tool.


so i conclude: it would be awesome if i know, how to format a storage drive from the terminal: i would love to get a base knowledge to start here!

look forward for any and all ideas here ...

You don't need to format any Drive in the Terminal...as a matter of fact you don't need to format any Drive at all.

When you buy an External SSD or Flash Drives...they already have a file table which Linux sees. The only time you need to format is installing an internal storage Drive or when installing Timeshift on an External HDD or SSD.

In Linux Mint...plug in your External SSD or Flash Drive...right click and choose format...you can choose anything you like...simple.
1732338876194.gif
 
You don't need to format any Drive in the Terminal...as a matter of fact you don't need to format any Drive at all.

When you buy an External SSD or Flash Drives...they already have a file table which Linux sees. The only time you need to format is installing an internal storage Drive or when installing Timeshift on an External HDD or SSD.

In Linux Mint...plug in your External SSD or Flash Drive...right click and choose format...you can choose anything you like...simple. View attachment 22912
Such drives are normally factory formatted for use with windows. If you want an ext4 file system then you'll need to create that.

Signed,

Matthew Campbell
 
f you want an ext4 file system then you'll need to create that.

I've seen a number of thumbdrives with exFAT as the default lately.

I'd say that's a good thing. It's perhaps to reduce customer service issues, where people who don't understand FAT32 call and complain that they can't store files greater than 4 GB in size. Or, they're just moving to open standards...

Being the pragmatic fella that I am, it's probably a move to reduce customer support costs...
 



Top