How to delete some zfs metadata from hard drive?
It's an old question, but just for the records:
The metadata of zfs is stored in the first and last two 256kB of each disk involved in zfs.
So you can do things like this:
sudo dd if=/dev/zero of=/dev/ada1 count=1 bs=512k
for the first bits and after you found the number of all sectors of your device, you can do this for the last metadata bits:
Assuming a sectorsize of 512 bytes, we have
262144 bytes (256kB of metadata) / 512 bytes (sectorsize) = 1024 sectors
sudo dd if=/dev/zero of=/dev/ada1 oseek=NUM_OF_SECTORS-1024
now, you should see a clean device.
Note* - /dev/ada1 is a device in freeBSD. Mounted in Linux it might be /dev/sdb, /dev/hdb etc.
Related videos on Youtube
dukasvili
Updated on September 18, 2022Comments
-
dukasvili over 1 year
I used hdd for system in Nas4free and this hdd is now system disk for Ubuntu server, but some zfs information is still there...I didnt wipe disk before installing new system. Can I remove this metadata now or I must wipe complete disk and install Ubuntu server again?
-
Kepi over 5 yearsThanks! It would be better to change
oseek
toseek
as it is synonymous on FreeBSD and doesn't exists on Linux. On Linux, you can go without manual counting with help ofblockdev
command:sh dd if=/dev/zero of="/dev/sdX1" seek=$(( $(blockdev --getsz "/dev/sdX1") - ( ( 256 * 1024 * 2) / $(blockdev --getpbsz "/dev/sdX1") ) ))
-
fabceolin almost 4 years@kepi It's appears to me the correct usage of your script on linux is /dev/sdX instead of /dev/sdX1
-
Kepi over 3 years@fabceolin I believe that /dev/sdX1 is correct as ZFS disk is always partitioned, first partition is for ZFS data - the one we need to remove metadata from. You can check that with
wipefs /dev/sdX
andwipefs /dev/sdX1
which will show you, that there are no ZFS metadata on/dev/sdX
, only partition data.