7 Linux Fdisk Command Examples To Manage Hard Disk Partition
7 Linux Fdisk Command Examples To Manage Hard Disk Partition
com/2010/09/linux-fdisk/
Home
About
Free eBook
Archives
Best of the Blog
Contact
7 Like 13 Tweet 18
1 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
Using fdisk you can create a new partition, delete an existing partition, or change existing partition.
Using fidsk you are allowed to create a maximum of four primary partition, and any number of logical
partitions, based on the size of the disk.
Keep in mind that any single partition requires a minimum size of 40MB.
In this article, let us review how to use fdisk command using practical examples.
Warning: Don’t delete, modify, or add partition, if you don’t know what you are doing. You will lose
your data!
Before you create a new partition, or modify an existing partition, you might want to view all
available partition in the system.
2 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
# fdisk -l
The above will list partitions from all the connected hard disks. When you have more than one disk
on the system, the partitions list are ordered by the device’s /dev name. For example, /dev/sda,
/dev/sdb, /dev/sdc and so on.
# fdisk -l /dev/sda
Use fdisk command m, to view all available fdisk commands as shown below.
# fdisk /dev/sda
3 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
Let us assume that you like to combine several partitions (for example, /dev/sda6, /dev/sda7 and
/dev/sda8) into a single disk partition. To do this, you should first delete all those individual partitions,
as shown below.
# fdisk /dev/sda
4 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
4. Create a New Disk Partition with Specific Size Using fdisk Command n
Once you’ve deleted all the existing partitions, you can create a new partition using all available
space as shown below.
# fdisk /dev/sda
In the above example, fdisk n command is used to create new partition with the specific size. While
creating a new partition, it expects following two inputs.
Please keep in mind that you should issue the fdisk write command (w) after any modifications.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
After the partition is created, format it using the mkfs command as shown below.
# mkfs.ext3 /dev/sda7
5 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
# fdisk -s /dev/sda7
4843566
Fdisk command displays the boot flag of each partition. When you want to disable or enable the boot
flag on the corresponding partition, do the following.
If you don’t know why are you are doing this, you’ll mess-up your system.
# fdisk /dev/sda
6 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
When you delete a logical partition, and recreate it again, you might see the “partition out of order”
issue. i.e “Partition table entries are not in disk order” error message.
For example, when you delete three logical partitions (sda6, sda7 and sda8), and create a new
partition, you might expect the new partition name to be sda6. But, the system might’ve created the
new partition as sda7. This is because, after the partitions are deleted, sda9 partition has been
moved as sda6 and the free space is moved to the end.
To fix this partition order issue, and assign sda6 to the newly created partition, execute the expert
command f as shown below.
$ fdisk /dev/sda
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
7 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
Syncing disks.
Once the partition table order is fixed, you’ll not get the “Partition table entries are not in disk order”
error message anymore.
# fdisk -l
8 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
thanxs ……
sir , you provides very good tuts….i use to save every single page of your articles… thanxs
again..
The “Warning Message” in this article reminds me of the mistake I did while teaching linux to a
group of students.
There ends the story of my LINUX OS of that machine and my session on Disk management.
Now a days, I first enter the device details and options, only then the command
Conclusion:
No Playing with linux, at times it is merciless
9 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
s/loose/lose/
@Chris,
good tips.
how to add new space on the existing partition using fdisk without losing data?
Add new space w/o loosing data with fdisk….? i think that’s not posible.
@raralee
Thanks a lot!
After restoring a Windows installation to a new harddisk, i found that i had made a mistake with
10 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
the partition-order, causing a non-boot. After reordering the partitions, it boots again (although i
won’t use it, not my machine .
It will be better if you add how to change the partition type too in this.
Change the partition type on the newly created partition from Linux to LVM (8e).
# fdisk /dev/sda
Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Unknown)
Command (m for help): w
i had grub15 error so i read that using fdisk will adjust order of sda. so i did fdisk -l then fdisk
/dev/sda then x f showed only two partitions and did w. now i am having problem that my
home is not loading system in root emergency mode. i can see my data after using ctrl D and
then home and then my data but i cant backup or copy my data to a usb drive plz tell what to
do after doing fdisk -l i can see all partitions i.e. 6 partiions
Leave a Comment
Name
Website
Previous post: 6 Perl File Handle Examples to Open, Read, and Write File
11 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
Next post: VMWare ESXi 4: How to Add Virtual Hard Disk (from Datastore) to a VM Using vSphere
Client
Search
COURSE
Linux Sysadmin CentOS 6 Course - Master the Tools, Configure it Right, and be Lazy
EBOOKS
Linux 101 Hacks 2nd Edition eBook - Practical Examples to Build a Strong
Foundation in Linux
Bash 101 Hacks eBook - Take Control of Your Bash Command Line and Shell Scripting
Sed and Awk 101 Hacks eBook - Enhance Your UNIX / Linux Life with Sed and Awk
Vim 101 Hacks eBook - Practical Examples for Becoming Fast and Productive in Vim Editor
Nagios Core 3 eBook - Monitor Everything, Be Proactive, and Sleep Well
POPULAR POSTS
12 Amazing and Essential Linux Books To Enrich Your Brain and Library
50 UNIX / Linux Sysadmin Tutorials
50 Most Frequently Used UNIX / Linux Commands (With Examples)
How To Be Productive and Get Things Done Using GTD
30 Things To Do When you are Bored and have a Computer
Linux Directory Structure (File System Structure) Explained with Examples
12 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
CATEGORIES
Linux
Vim
Sed
Awk
Bash
Nagios
OpenSSH
IPTables
Apache
13 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
MySQL
Perl
Google
Ubuntu
PostgreSQL
Hello World
C Programming
C++ Programming
DELL
Oracle
VMware
Support Us
Contact Us
14 of 15 07-Jun-13 12:58 AM
7 Linux fdisk Command Examples to Manage Hard Disk Partition http://www.thegeekstuff.com/2010/09/linux-fdisk/
Email Me : Use this Contact Form to get in touch me with your comments, questions or
suggestions about this site. You can also simply drop me a line to say hello!.
Follow us on Twitter
Copyright © 2008–2013 Ramesh Natarajan. All rights reserved | Terms of Service | Advertise
15 of 15 07-Jun-13 12:58 AM