Home arrow Latest Tutorials arrow Gpart Quick Guide
Gpart Quick Guide PDF
Wednesday, 15 June 2011
Gpart utility is used to control disk partitioning with GEOM class in FreeBSD.

The main advantage of using gpt is that you can create  more than 4 partition, up to 128.

Here is a quick tutorial on using gpart.

Creating GPT table
-----------------------
Will create GPT partition table, instead of MBR:

  gpart create -s gpt ad0


Display partitions
--------------------
Display partition for disk ad0:

  gpart show ad0


Delete a partition
--------------------
Next command will delete partition number 3 from disk ad0. Counting start from 1 and not from 0 for partitions, couning start from 0 for drive name.

  gpart delete -i3 ad0


Create a partition
---------------------
Next command will create a partition of size 5G, of type freebsd-ufs, on drive ad0:

  gpart add -s 5G -t freebsd-ufs ad0


Create a FAT32 partition
-----------------------------

You can create and format an DOS/Windows FAT32 partition with:

  gpart create -t mbr ad0
  newfs_msdosfs -F32 /dev/ad0p1

Dealing with errors
-------------------------

If there are logical errors (because of bad partitioning) on your drive is better to overwrite everything on your drive with zeroes using dd:

  dd if=/dev/zero of=/dev/ad0 bs=1M

And then you will create partitions. If you see an "Operation not permitted" error message just set the following sysctl variable:

  kern.geom.debugflags=0x10

If you just completely zeroed your drive and this sysctl variable is set to 0x10 (16)  and you cannot create new partitions because GPT kernel module seems to still see partitions but with erros like this example:

gpart show ada2
=>        34  1953525101  ada2  GPT  (931G) [CORRUPT]
          34  1950351360     1  freebsd-ufs  (930G)
  1950351394     3173741        - free -  (1.5G)


then it is a good idea to reboot your machine. After reboot there will be no partition seen on hard drive:

  gpart show ada2
  gpart: No such geom: ada2



If you get the following error: "Device Busy" when you try to delete GPT from drive with gpart delete ad0 , you can succesfully delete GPT if you turn of the safety with sysctl variable:

  sysctl kern.geom.debugflags=16


- If you want to destroy GPT table from the drive with gpart delete ad0 command you must first delete all partitions (otherwise you might get "Device Busy" error).

Last Updated ( Friday, 29 June 2012 )
 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?