User Tools

Site Tools


faq:0129

Q: Why can't I format my disk / hard drive or create a ZFS pool with it?
Q: How can I easily, quickly and completely wipe / prepare a disk for use?
A:
Sometimes there is old MetaData on drives preventing you from re-using them. You should wipe the drives clean. For an explanation, please read:

GPT partitioning writes to the start and end sectors, GEOM RAID writes to the end and ZFS writes 512 kilobytes to the start and end sectors of your drives. Sometimes all of this data does not co-exist happily, but it must always be completely erased before you can use a drive in XigmaNAS and other OS's. There are several good ways of doing this, one is to do

gpart destroy -F adax

, other is to just erase the beginning and ending sectors of the drive using the CLI or a script run at the CLI. If you are prepared to wait you can just wipe the whole drive using something like the popular DBAN, or you can use dd from a command line, see: The power of dd, thanks to Dan Merschi and his original Knowledge Base.

If you want to do it with a script or with the CLI, remember that the disk cannot be mounted or otherwise be in use. If you have a few disks to wipe, it will save time in the long run if you use a script like the one shown below. This script wipes the first and last 4096 kilobytes of data from a drive ensuring that any partitioning or MetaData is gone and you can then reuse your drive. Warning, all other data on the drive will become inaccessible!:

#!/bin/sh
echo "What disk do you want"
echo "to wipe? For example - ada1 :"
read disk
echo "OK, in 10 seconds I will destroy all data on $disk!"
echo "Press CTRL+C to abort!"
sleep 10
diskinfo ${disk} | while read disk sectorsize size sectors other
do
        # Delete MBR, GPT Primary, ZFS(L0L1)/other partition table.
        /bin/dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} count=8192
        # Delete GEOM metadata, GPT Secondary(L2L3).
        /bin/dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} oseek=`expr $sectors - 8192` count=8192
done

or

#!/bin/bash
echo "What disk do you want"
echo "to wipe? For example - ada1 :"
read disk
echo "OK, in 10 seconds I will destroy all data on $disk!"
echo "Press CTRL+C to abort!"
sleep 10
diskinfo ${disk} | while read disk sectorsize size sectors other
do
    # Delete MBR, GPT Primary, ZFS(L0L1)/other partition table.
    /bin/dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} count=8192
    # Delete GEOM metadata, GPT Secondary(L2L3).
    /bin/dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} oseek=$(expr $sectors - 8192) count=8192
done

Save it to file named, /mnt/wipe.sh. Make sure you preserve the integrity of each line if you copy and paste the script. If you are doing this in Windows make sure the saved script uses *nix line feeds. Make /mnt/wipe.sh executable and then execute it either at the console or via SSH. You will be prompted to enter the device you want to wipe, do not enter the wrong device! If you make a mistake you can kiss your data goodbye!

Advanced Basic storage concept ⇒9.0.0.1
faq/0129.txt · Last modified: 2018/08/12 02:42 by zoon01