Format drive command line linux

How to Format a Drive in Linux

This guide shows you how to format a drive in Linux.

Formatting a Drive in Linux

There are two primary ways of formatting a drive in Linux: using the CLI and using the GUI. For general users, using a GUI tool may be more comfortable, whereas advanced or professional users may find the CLI method better suits them.

Either way, performing a disk format requires root access or sudo privileges. However, in certain situations, a different user can perform drive format if there is write permission for that drive. This article was written with the assumption that you have root access to your system.

The drive formatting process can be a bit tricky. To use the device storage, a drive must have a partition table with or without partitions. The partitions will allow the OS to access the storage. By formatting the drive, we are formatting the partition. If there are multiple partitions, then you have to perform the formatting process for all of them.

Formatting a Partition using the GUI Method

For managing disks and partitions (and related functions), GParted is the best option. GParted is a free and open-source tool used for managing disk partitions. This tool comes with tons of features and support for numerous file systems.

There are two ways to use GParted. You can install GParted on the running system or use the bootable image to perform the disk format. Both methods come with their own pros and cons. The good part is, whichever method you follow, the UI of GParted works the same.

First, we will show you how to install GParted onto your system. Depending on the Linux distro that you are running on your system, use the appropriate one.

For Debian/Ubuntu and derivatives:

For Fedora and derivatives:

For openSUSE and derivatives:

To use GParted from the boot, download the GParted bootable ISO here. You can also make a bootable CD, DVD, or USB flash drive. Check out how to make a bootable USB flash drive on Linux here. Once you have prepared the system, boot into the CD, DVD, or USB flash drive.

From this point on, GParted behaves the same. For convenience, I will be demonstrating using GParted installed on Ubuntu.

Launch GParted, and it will ask for the root password.

From the top-right corner, select the device on which the operation is to be performed.

Next, you must decide the target partition. For an in-depth guide on how to create and manage partitions using GParted, check out how to use GParted here. In this case, the target partition is the /dev/sda5 partition.

As you can see, the partition is currently mounted. Before performing any action, the partition must be unmounted. Right-click and select “Unmount.”

Now, the partition is ready to be formatted. If the device is a USB flash drive, then file systems like FAT32, NTFS, and EXT4 are generally the best option. If the device is an HDD, then it is better to go for EXT4. You can also go for a different format if there is a need for a specific file system. In my case, I will right-click and select “Format to” >> “fat32.”

Читайте также:  Как проверить валидацию windows

An interesting feature of GParted is that it does not write the changes to the drive instantly. This way, even if you misconfigure the drive, you can easily discard the changes. To make the changes permanent, click “Apply All Operations.”

GParted will now ask you for confirmation. In this example, after performing the formatting, the partition will lose all its data. Click “Apply” to confirm.

Voila! The partition has been formatted successfully!

Formatting a Partition Using the CLI method

This method is relatively shorter than the previous one. However, this method is only recommended for advanced users, as it comes with a higher chance of damage to the system. This method is less failsafe than GParted, so you must be super careful.

Connect the device to the computer. By default, most Linux distros will mount all the partitions of the device. Assuming it hosts a single partition, it will be mounted automatically. Check out the list of mounted filesystems below.

It is not allowed to format a partition that is currently mounted. To unmount the partition, run the following command.

Now, you can format the partition with your desired filesystem. Run the command that suits your needs.

Источник

Linux Hard Disk Format Command

Q. I’ve installed a new 250GB SATA hard disk on our office CentOS Linux server. How do I format a hard disk under Linux operating system from a shell prompt?

A. . There are total 4 steps involved for hard disk upgrade and installation procedure:

Step #1 : Partition the new disk using fdisk command

Following command will list all detected hard disks:
# fdisk -l | grep ‘^Disk’
Output:

A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.
To partition the disk – /dev/sdb, enter:
# fdisk /dev/sdb
The basic fdisk commands you need are:

  • m – print help
  • p – print the partition table
  • n – create a new partition
  • d – delete a partition
  • q – quit without saving changes
  • w – write the new partition table and exit

Step#2 : Format the new disk using mkfs.ext3 command

To format Linux partitions using ext2fs on the new disk:
# mkfs.ext3 /dev/sdb1

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Step#3 : Mount the new disk using mount command

First create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H

Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab
Append as follows:

Save and close the file.

Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup
You can use label name insted of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

Читайте также:  Чистая установка mac os high sierra с флешки

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

yah thats good for understand………

i have 48TB storage server in raid 5, how do i format this server?

to format the corresponding hdd you need a RAM(Random Access Memory) 1 YB(yota byte)
1YB=1024 ZB
1ZB=1024 XB
1XB=1024 PB
1PB=1024 TB

LOL, I’ve got 1 UB (UnniByte) RAM on my Server

1UB=1024YB
1YB=1024 ZB
1ZB=1024 XB
1XB=1024 PB
1PB=1024 TB

Is it possible to format my 1.4 MB floppy now?

I have 90’90 power of per zylions! So what? You’ve only got a pint of milk. does your processor register .

Use LVM directly or read this tutorial which explains how to create partition larger than 2TB

How do I format a harddisk using linux system call

thank you fro valuable information

how to format a disk by cpp programe?is there any sample code ?

Thank you very much this valuable information.

/dev/sdb1 /disk1 ext3 defaults 1 2

The above line what is mean by defaults and what is 1 2 ?

can u explain those two things !

This is directly from the arch linux (amazing) documentation:

  1. The first number is “dump”: used by the dump utility to decide when to make a backup. Dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system; if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the entry.
  2. The second number is “pass”: used by fsck to decide which order filesystems are to be checked. Possible entries are 0, 1 and 2. The root file system should have the highest priority 1 – all other file systems you want to have checked should have a 2. File systems with a value 0 will not be checked by the fsck utility.

IN my system both WINDOWS-XP and LINUX , I’ve installed. after that
I want to format the linux OS from my system.
so please send to me tricks or method on Email addr., so i can remove LUNUX OS from my system.
BY both method (i)Text command and
(ii)without Text command.

Hey man I also have same problem .did u got any methods to remove . please help man

verrrrrrrrry useful i’ve searched for 2 days for this thanks

Thank you very much this valuable information. Very useful this

Thanks
B. Sathish.

I have installed CentOS ..
now i want my disk to be fully formatted like a new one. with no files on it..

i remember doing it by booting in DOS mode in Win98..
Please tell how can i do it..

Thank you.
nice and clear.

Excellent and easy. Thanx

Nice information and esp. the link that you posted for Anikat. Information really useful pal. Thanks a ton..

Regards
Charanjit Singh Cheema

Thank you, this is the kind of fast reference that one is always looking for

Well, this saved me an hour of banging my head against the wall… well written! thanks!

Yes. Very useful. Thanks.

help me to see the out put of the php programe, i have php 2007 developer

Very simple and useful, thanks 🙂

Great. Searched for a long time to find this, very well done. Thanks!

Can any one tell me what the mean by 1,2 in default and when i create a raid partition is there any change in default charcter or it is sama as ” default” .

IN my Laptop both WINDOWS-XP and LINUX, i’ve safe the problem in windows hal.dll file is corrupted.
so please send to me tricks or method on Email addr.

Good Recipe for what I did in UNIX for years with the simple format command.
You boiled it down to an excellent example…

very helpfull , thanks.

very first command (fdisk /dev/sdb) failed. message is “Unable to open /dev/sdb”. any suggestions?

Is there any software to bound two NIC to use on ip address for both NICs.

Thank you very much these are very good and easy way commands to understand for the people.

how to format linex form my system plz reply solution at my email

thanks alot . that was really usefull

how many formatting for window and linux
plz sand ams on my email address

I deleted the panel in ubuntu by mistake.. how can i get the default panels?

The above steps are so good and easy to format

Thank u Very much for your Formating steps.

a very nice article. thank you for sharing.

how do installed linux …. with command . tell me all command….

IN my system both WINDOWS-XP and LINUX , I’ve installed. after that
I want to format the linux OS from my system.
so please send to me tricks or method on Email addr., so i can remove LUNUX OS from my system.
BY both method (i)Text command and
(ii)without Text command.

Good article.
Note: this works on centos 5.5 … fyi.

This is beautiful. There are some who care out there..

IN my system both WINDOWS-XP and LINUX , I’ve installed. after that
I want to format the linux OS from my system.
so please send to me tricks or method on Email addr., so i can remove LUNUX OS from my system.
BY both method
(i)Text command and
(ii)without Text command.

Источник

Читайте также:  Windows phone размер системы
Оцените статью