Tool Battle Royale - FDISK vs. PARTED

Latest response

In this exciting world of "The Linux" people have lots of options and tools to get their jobs done.   Folks take tool choice VERY seriously.  Sometimes it's nice to peek at one of two and compare and contrast maybe learn a thing or two about different ways of getting the same job done.  So I'm curious to hear: what's YOUR favourite tool of choice to work with disks: fdisk or parted?  Both have great features, but which one do YOU choose to use?  We'd love to hear your opinions on which tool makes you a better, stronger, faster admin.
 

Responses

Hey Chris and Everyone else,

So I always used to switched between the two.  However, I recently had a sev1 incident where a customer accidentally wiped the first 1mb of /dev/sda.  That's when I found that in a moment of crisis I chose fdisk.  

Using fdisk and switching from cylinders to sectors we used the info in /sys/block/sda/sda1/start and /sys/block/sda/sda1/size to rebuild the partition table.  While I'm sure parted has the same functionality, fdisk seemed to come to me eaiser while under pressure.  I didn't realize that I had a preference prior to that.

- Nick Greene

Cool discussion. For me it's not so much the tool, but the reporting method with which it's used.

 

fdisk's default to "cylinders" is useless, no hard drive has used CHS addressing for almost 20 years. "Cylinder 1" in the partition list means "anywhere within cylinder 1". On large enterprise-grade storage you end up with the kernel guessing a "cylinder" of 8Mb or more, and you have no accuracy in your partition reporting.

 

Running fdisk in sector mode with the -u switch gets around this. View partitions with the fdisk -ul /dev/sdX command.

 

Parted's default "compact" reporting mode is equally as frustrating, as it defaults to "1000 kilobytes = 1 megabyte" and not "1024 kilobytes = 1 megabyte" like it should. So if you start a partition on sector 2048 (1 megabyte into the disk) then parted will report it as "1049kB" or "1.05MB".

 

Starting parted in sector mode with the "unit s" option gets around this. View partitions with the parted /dev/sdX "unit s" "print" command.

 

As far as other functionality, you can script with parted which is handy - parted mklabel, parted mkpart, and so on.

I'm firmly undecided.

 

Today I was working on a reproducer/test case for a support case that deals with LVM, partitioning/disk labeling and resizing LUNs. This involved a fair amount of steps (especially as being a poor remotee, I don't happen to have a SAN around for testing purposes, so I had to fake LUNs by loop-mounting a sparse file), so I ended up writing a script. For this, the parted --script functionality was very helpful. As far as I know, fdisk doesn't have this type of scripting capability, so scripting something similar with fdisk would likely have been a lot more complex (using expect or somesuch to script an interactive program). On the other hand, fdisk allows me to use just about every partition type ever invented, whereas parted's mkpart only supports a very limited list of partition types.

I use fdisk, not because I prefer it over parted based on functionality. More because I started some 12 years ago using fdisk and never took the time to learn parted.

Ha.  Yes, that's really what it boils down to sometimes, what was the stuff you started out using.  Thanks for sharing Jan!

 

-Chris

For me it's a question of context. If I'm doing interactive partitioning, I use `fdisk`. If I'm writing KickStarts designed to create storage-aligned partitions, I use `parted` in the %pre section of my KickStart file.

For me, `fdisk`s interface is just more "intuitive" and easier from an interactive standpoint. Though, that may be more from decades of habit rather than legitimate ease-of-use differentials. At any rate, if I'm worrying about aligning disks, I just ad an 'x' and a 'b' to my normal partitioning process.

`parted` is too much like trying to lay down a partition table in Solaris using `fmthard`. Great for scripting and kickstarts but kinda ugly as an interactive tool.

I have a related question:

Since every disk we create now, except under very rare circumstances, will be managed as a volume, is there a utility which can be configured to create 8e (Linux LVM) partitions by default when used from the command line?

I like fdisk--it's quick and simple--but I'll learn to use about any utility to keep that step from being skipped ever again.

Anyone landing here, know this discussion was originally started in 2012. It was resurrected with a continuing question on LVM

Hello John Adams, welcome to the RH discussion forum

An LVM guide is at this link which in principle gives LVM examples in creating partitions.

If you intend to build LVM from a RHEL 8 kickstart, I'd recommend initially starting with the kickstart generator at Red Hat Labs.

Note, adjust the sizes for the below to something you require Note2: Is this required for all systems? treat the partitioning below as a buffet. Take the lines you require, adjust as required, omit the reset The intention of what some may call excessive partitions is that it protects / and /var and other partitions from getting overwhelmed. our environment has enough storage to use something such as below, and of course tailored for a specific server No, we do not blanket use the below for every server, this is just an example.
# NOTE: THIS BLOCK OF TEXT IS INTENDED AS A ROUGH EXAMPLE FOR A KICKSTART FILE
# ADJUST AS NECESSARY for your own requirements.
# yes, some is overkill, we're good with overkill where we work.
zerombr
clearpart   --all
part        pv.221          --fstype="lvmpv"  --ondisk=sda   --size=570751
part        /boot           --fstype="xfs"    --size=4000
volgroup    osdisk          --pesize=4096     pv.221
logvol      /               --fstype="xfs"    --size=86665   --name=slash                --vgname=osdisk
logvol      /var/log/audit  --fstype="xfs"    --size=25000   --fsoptions="nodev,nosuid"  --name=varlogaudit  --vgname=osdisk
logvol      /home           --fstype="xfs"    --size=8096    --fsoptions="nodev"         --name=home         --vgname=osdisk
logvol      /tmp            --fstype="xfs"    --size=37000   --fsoptions="nodev,nosuid"  --name=tmp          --vgname=osdisk
logvol      /var            --fstype="xfs"    --size=100     --fsoptions="nodev"         --name=var          --vgname=osdisk
logvol      /var/log        --fstype="xfs"    --size=58000   --fsoptions="nodev"         --name=varlog       --vgname=osdisk
logvol      /var/tmp        --fstype="xfs"    --size=21000   --fsoptions="nodev"         --name=vartmp       --vgname=osdisk
logvol      /var/spool      --fstype="xfs"    --size=13000   --fsoptions="nodev"         --name=varspool     --vgname=osdisk
logvol      /usr            --fstype="xfs"    --size=27288   --name=usr                  --vgname=osdisk
logvol      swap            --fstype="swap"   --size=16064   --name=swap                 --vgname=osdisk
logvol      /opt            --fstype="xfs"    --size=260000  --name=opt                  --vgname=osdisk
# so many people ask for additional storage after build that we routinely have this as a backup for additional space.
logvol      /growlvmsda     --fstype="xfs"    --size=100     --grow                      --name=growlvm      --vgname=osdisk

Now if you are using disks over 2tb or so, you will end up using the parted command. If you have a graphical interface, you can install EPEL's gparted. Both have useful man pages, the gparted edition is graphical and somewhat straightforward. For the parted command, see the man page.

Regards,

RJ

Hi, RJ,

That's a great summary! I have a slightly different question:

I would like to make sure that whatever disk partitioning utility we use on our machines always defaults to an 8e (Linux LVM) partition when initiated from the command line. I've only forgotten to change it once, but that once was Not Good.

Thanks,

John A

Hi,

Great comments from others. Very dignified and respectful to others. That way it should be.

Personally, when in deep trouble, I refer to fdisk or its equivalent (sfdisk).

Somebody mentioned that fdisk cannot be used for scripting easily. I think it can, actually. Some simple examples used by me or found by quick search on the internet (I cannot take credit for them!):

# (echo n; echo p; echo 1; echo 1; echo 512; echo w) | fdisk /dev/sdb

# fdisk /dev/sdb < /tmp/fdisk-sdb.cmd

# (
echo o # Create a new empty DOS partition table
echo n # Add a new partition
echo p # Primary partition
echo 1 # Partition number
echo   # First sector (Accept default: 1)
echo   # Last sector (Accept default: varies)
echo w # Write changes
) | fdisk /dev/sdb

# sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk /dev/sdb
  o # clear the in memory partition table
  n # new partition
  p # primary partition
  1 # partition number 1
    # default - start at beginning of disk 
  +100M # 100 MB boot parttion
  n # new partition
  p # primary partition
  2 # partion number 2
    # default, start immediately after preceding partition
    # default, extend partition to end of disk
  a # make a partition bootable
  1 # bootable partition is partition 1 -- /dev/sda1
  p # print the in-memory partition table
  w # write the partition table
  q # and we're done
EOF

In addition, sfdisk is a scripted version of fdisk.

In the end, the power of Linux is in freedom of choice...

Regards,

Dusan Baljevic (amateur radio VK2COT)