Gpart CheatSheet - wiping drives, partitioning, & formating

Greetings,
I don't know about you. But with all the other things I do, when I do need to (re)format a drive, so I can add, or replace one I already have commissioned on a FreeBSD system. Seems I can never remember the correct incantation. Sure, I could just (re)read the man() pages. But, seems to me, it'd be a whole lot faster, and easier. If I just jotted down the only switches I ever seem to use. Then just call them up, for a "refresher course". This page will undoubtedly help me. But, hopefully, you too. :)
Quick note before I start;
A big thanks go out to @wblock@. Who helped me with just this problem.

OK. Let's get to it;
This is just a "quickie" wipe > (re)slice (partition) > format.
I'll cover platters, and SSD's. If you aren't already familiar with gpart(), FreeBSD partitioning schemes (slices),
DO read the gpart() pages, as well as the http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ handbook. See also: newfs(), and dd().

Wiping a drive, and adding a GPT partitioning scheme
(http://en.wikipedia.org/wiki/GUID_Partition_Table)

First off. This assumes you already have the platter plugged in, and ready to go. If you don't already know the "devices" BSD style name, ls /dev/ looking for device names not already listed in fstab()
Code:
# SCSI / USB platters
# dev name da0
# (S)ATA platters
# dev name ad0
#
# WIPE THE PARTITION
gpart destroy -F da0

# CREATE GPT style SLICE (partition)
gpart create -s gpt da0

# CREATE FFS SLICE (filling entire platter)
gpart add -t freebsd-ufs da0

# FORMAT THE NEW FFS SLICE
newfs -U /dev/da0p1
The above example was for a SCSI drive, and also works for external USB platters. Substitute the dev() name for your type of platter. The above GPT style partitioning scheme will be invisable to older OS's, and Hardware. Most notably Window$. If you need to work with "legacy" Hardware/Operating systems. You will probably be better off choosing the following proceedure/scheme.

MSDOS style partitioning scheme:
Code:
# WIPE THE PLATTER
gpart destroy -F da0

# PLACE A BLANK PARTITION ON IT
gpart create -s mbr da0

# FILL THE MSDOS PARTITION
gpart add -t \!12 da0

# FORMAT IT MSDOS STYLE (fat32)
newfs_msdos -F32 /dev/da0s1
Again, the above was for SCSI, and external USB platters. Simply replace the dev() with the correct one for your system.

We can also choose a "legacy" BSD formatting scheme. But while this type of scheme works with anything reasonably modern. MSDOS,WINDOWS95, and older hardware may (will probably) have trouble recognizing it.
Code:
# WIPE THE PLATTER
gpart destroy -F da0

# PLACE A BLANK BSD STYPE PARTITION ON IT
gpart create -s bsd da0

# DEDICATE THE ENTIRE PLATTER FOR FFS(2)
gpart add -t freebsd-ufs da0

# NOW FORMAT IT (ffs(2))
newfs -U /dev/da0p1
NOTE: The device names for "old-style" BSD slices were actually da0s1 (note the s1 appended).
And, yes again, this was for a SCSI, or USB external drive. Substitute the dev() listed in the example, for the correct one listed on your system.

Yes. But what about SSD/USB "flash drives"?
Glad you asked. Here's the approach I use:
Code:
# NOTE THAT DEV NAMES ARE IMPORTANT - CHOOSE WISELY
# CLEAR THE MBR
dd if=/dev/zero of=/dev/da0 bs=2m count=0

# FORMAT IT
newfs /dev/da0

# DID IT WORK?
mount -t ufs /dev/da0 /mnt

# note da0 may, or may NOT be the correct device - check messages

The above example has always worked without fail for me.
But here's a perhaps more conservative/traditional approach:
Code:
# WIPE MBR
dd if=/dev/zero of=/dev/da0 count=2

# PUT A TRADITIONAL LABEL ON IT
disklabel /dev/da0 | disklabel -B -R -r da0 /dev/stdin

# We only want one partition, so using slice 'c' should be fine:
# FORMAT IT
newfs /dev/da0c

USB flash drives can be flakey. But I've found the above to "fix" a number of otherwise nearly, or completely unusable flash drives.
YMMV!

Standard disclaimer applies to all the above. ;)
If you have anything you'd like to add, or critique about the above; PLEASE feel free to "chime in". :)

--Chris
 
Last edited by a moderator:
Dear Chris,

I managed to break my pfSense and unable to get it working again.

I got the following errors in log:

Can't stat /dev/da0p1: No such file or directory
THE FOLLOWING FILE SYSTEM HAD AN UNEXPECTED INCONSISTENCY:
ufs: /dev/da0p1 (/data/)
Stopping boot is recommended because filesystem manual action is needed, nevertheless automated repair of the filesystem will be attempted.
WARNING: Trying to recover filesystem from inconsistency...
Can't stat /dev/da0p1: No such file or directory

ERROR: Impossible to mount filesystem, use interactive shell to attempt to recover it

Wiping the partition, recreating and formatting it again, did the trick.

I just wanted to thank you.

Alex
 
Back
Top