2017-07-25

Unable to GPT format the disk "da3": gpart: geom \'da3\': Operation not permitted on FreeNAS 11

While configuring my FreeNAS virtual appliance for iSCSI I encountered a problem with re-creating device volumes [1]. A pop-up appeared in the FreeNAS GUI with the message:

[MiddlewareError: b'Unable to GPT format the disk "da3": gpart: geom \'da3\': Operation not permitted\n']

As there was no data I decided to try wiping the device (Storage > Volumes > View Disks, "Wipe"). Even a full wipe of the device didn't make a difference. I then tried removing the device and replacing it with a new (HDD) device and that made the symptom go away. I then encountered the same symptom on a different device so I tried a different approach. After doing some research [2][3][4][5] I came up with this:

topolhnas01mg# diskdevice=da8
topolhnas01mg# disksizeblocks=$( dmesg | grep -i "byte sectors" | grep -i "^$diskdevice[:].*" | head -1 | cut -d"(" -f 2 | cut -d" " -f 1 )
topolhnas01mg# partitionsizeblocks=34
topolhnas01mg# seekblocks=$( echo $disksizeblocks - $partitionsizeblocks | bc )
topolhnas01mg# sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16
topolhnas01mg# dd if=/dev/zero of=/dev/$diskdevice bs=512 count=$partitionsizeblocks
34+0 records in
34+0 records out
17408 bytes transferred in 0.002115 secs (8232582 bytes/sec)
topolhnas01mg# dd if=/dev/zero of=/dev/$diskdevice bs=512 seek=$seekblocks
dd: /dev/da8: end of device
35+0 records in
34+0 records out
17408 bytes transferred in 0.002137 secs (8145309 bytes/sec)
topolhnas01mg#


After running this the FreeNAS virtual appliance was rebooted and I was able to create the volumes. Later I was able to successfully format the iSCSI devices with VMFS.

This is a super quick way of overwriting the GPT partition table at the beginning and and of the disk device. The key to the speed is that only 34 blocks at the beginning and end of the HDD are overwritten. I suspect that this would work equally well for other operating systems (FreeBSD, Linux) that implement 'dmesg' but haven't tried. This method in no way attempts to address issues of bad blocks or media issues.

I suspect that the reason for this happening was due to upgrading and then down grading my physical ESXi host -- trying to get the "ESXi MAC Learn DvFilter"[5] working. That is another story.



[1] Ungraceful error if volume create fails if disk needs wipe
[2] This is where I got the idea of overwriting the GPT partition tables. (Unable to GPT format the disk ada0; unable to wipe ada0)
[3] Comment from DBronx highlighted the importance of "sysctl kern.geom.debugflags=16" for this to work. (Error: [MiddlewareError: Unable to GPT format the disk "ada0"])
[4] Another page that suggests overwriting the GPT partition table and clue as to size of partition table (GPT Rejected - how to wipe for ZFS?)
[5] First hint at how to overwrite GPT partition table at and of HDD device (How to completely wipe a hard drive?)
[5] ESXi Learnswitch – Enhancement to the ESXi MAC Learn DvFilter

No comments: