- Linux Hard Disk Format Command
- Step #1 : Partition the new disk using fdisk command
- Step#2 : Format the new disk using mkfs.ext3 command
- Step#3 : Mount the new disk using mount command
- Step#4 : Update /etc/fstab file
- Task: Label the partition
- 10 fdisk Commands to Manage Linux Disk Partitions
- 1. View all Disk Partitions in Linux
- 2. View Specific Disk Partition in Linux
- 3. Check all Available fdisk Commands
- 4. Print all Partition Table in Linux
- 5. How to Delete a Partition in Linux
- 6. How to Create a New Partition in Linux
- 7. How to Format a Partition in Linux
- 8. How to Check Size of a Partition in Linux
- 9. How to Fix Partition Table Order
- 10. How to Disable Boot Flag (*) of a Partition
- If You Appreciate What We Do Here On TecMint, You Should Consider:
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
🐧 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:
- 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.
- 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.
Источник
10 fdisk Commands to Manage Linux Disk Partitions
fdisk stands (for “fixed disk or format disk“) is an most commonly used command-line based disk manipulation utility for a Linux/Unix systems. With the help of fdisk command you can view, create, resize, delete, change, copy and move partitions on a hard drive using its own user friendly text based menu driven interface.
This tool is very useful in terms of creating space for new partitions, organising space for new drives, re-organising an old drives and copying or moving data to new disks. It allows you to create a maximum of four new primary partition and number of logical (extended) partitions, based on size of the hard disk you have in your system.
fdisk command to manage disk partition
This article explains 10 basic fdisk commands to manage a partition table in Linux based systems. You must be root user to run fdisk command, otherwise you will get a “command not found” error.
1. View all Disk Partitions in Linux
The following basic command list all existing disk partition on your system. The ‘-l‘ argument stand for (listing all partitions) is used with fdisk command to view all available partitions on Linux. The partitions are displayed by their device’s names. For example: /dev/sda, /dev/sdb or /dev/sdc.
2. View Specific Disk Partition in Linux
To view all partitions of specific hard disk use the option ‘-l‘ with device name. For example, the following command will display all disk partitions of device /dev/sda. If you’ve different device names, simple write device name as /dev/sdb or /dev/sdc.
3. Check all Available fdisk Commands
If you would like to view all commands which are available for fdisk. Simply use the following command by mentioning the hard disk name such as /dev/sda as shown below. The following command will give you output similar to below.
Type ‘m‘ to see the list of all available commands of fdisk which can be operated on /dev/sda hard disk. After, I enter ‘m‘ on the screen, you will see the all available options for fdisk that you can be used on the /dev/sda device.
4. Print all Partition Table in Linux
To print all partition table of hard disk, you must be on command mode of specific hard disk say /dev/sda.
From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter ‘p‘, it will print the specific /dev/sda partition table.
5. How to Delete a Partition in Linux
If you would like to delete a specific partition (i.e /dev/sda9) from the specific hard disk such as /dev/sda. You must be in fdisk command mode to do this.
Next, enter ‘d‘ to delete any given partition name from the system. As I enter ‘d‘, it will prompt me to enter partition number that I want to delete from /dev/sda hard disk. Suppose I enter number ‘4‘ here, then it will delete partition number ‘4‘ (i.e. /dev/sda4) disk and shows free space in partition table. Enter ‘w‘ to write table to disk and exit after making new alterations to partition table. The new changes would only take place after next reboot of system. This can be easily understood from the below output.
Warning : Be careful, while performing this step, because using option ‘d‘ will completely delete partition from system and may lost all data in partition.
6. How to Create a New Partition in Linux
If you’ve free space left on one of your device say /dev/sda and would like to create a new partition under it. Then you must be in fdisk command mode of /dev/sda. Type the following command to enter into command mode of specific hard disk.
After entering in command mode, now press “n” command to create a new partition under /dev/sda with specific size. This can be demonstrated with the help of following given output.
While creating a new partition, it will ask you two options ‘extended‘ or ‘primary‘ partition creation. Press ‘e‘ for extended partition and ‘p‘ for primary partition. Then it will ask you to enter following two inputs.
- First cylinder number of the partition to be create.
- Last cylinder number of the partition to be created (Last cylinder, +cylinders or +size).
You can enter the size of cylinder by adding “+5000M” in last cylinder. Here, ‘+‘ means addition and 5000M means size of new partition (i.e 5000MB). Please keep in mind that after creating a new partition, you should run ‘w‘ command to alter and save new changes to partition table and finally reboot your system to verify newly created partition.
7. How to Format a Partition in Linux
After the new partition is created, don’t skip to format the newly created partition using ‘mkfs‘ command. Type the following command in the terminal to format a partition. Here /dev/sda4 is my newly created partition.
8. How to Check Size of a Partition in Linux
After formatting new partition, check the size of that partition using flag ‘s‘ (displays size in blocks) with fdisk command. This way you can check size of any specific device.
9. How to Fix Partition Table Order
If you’ve deleted a logical partition and again recreated it, you might notice ‘partition out of order‘ problem or error message like ‘Partition table entries are not in disk order‘.
For example, when three logical partitions such as (sda4, sda5 and sda6) are deleted, and new partition created, you might expect the new partition name would be sda4. But, the system would create it as sda5. This happens because of, after the partition are deleted, sda7 partition had been moved as sda4 and free space shift to the end.
To fix such partition order problems, and assign sda4 to the newly created partition, issue the ‘x‘ to enter an extra functionality section and then enter ‘f‘ expert command to fix the order of partition table as shown below.
After, running ‘f‘ command, don’t forget to run ‘w‘ command to save and exit from fdisk command mode. Once it fixed partition table order, you will no longer get error messages.
10. How to Disable Boot Flag (*) of a Partition
By default, fdisk command shows the boot flag (i.e. ‘*‘) symbol on each partition. If you want to enable or disable boot flag on a specific partition, do the following steps.
Press ‘p‘ command to view the current partition table, you see there is a boot flag (asterisk (*) symbol in orange color) on /dev/sda1 disk as shown below.
Next enter command ‘a‘ to disable boot flag, then enter partition number ‘1‘ as (i.e. /dev/sda1) in my case. This will disable boot flag on the partition /dev/sda1. This will remove the asterisk (*) flag.
I’ve tried my best to include almost all basic commands of fdisk commands, but still fdisk contains a variety of other expert commands you can use them by entering ‘x‘. For more detailed information, check out ‘man fdisk‘ command from the terminal. If I’ve missed any important command, please do share with me via comment section.
Read Also :
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник