From owner-freebsd-current@freebsd.org Mon Sep 26 13:48:22 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7EC3DBE8C28 for ; Mon, 26 Sep 2016 13:48:22 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: from mail-it0-x22f.google.com (mail-it0-x22f.google.com [IPv6:2607:f8b0:4001:c0b::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 468BD1D3B for ; Mon, 26 Sep 2016 13:48:22 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: by mail-it0-x22f.google.com with SMTP id n143so75152011ita.1 for ; Mon, 26 Sep 2016 06:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-transfer-encoding; bh=R7Nq4QVbjvOYAp4V4VK4haEvYLPyh0wFJcfhhgnkkx4=; b=l23L9TJwy6QrsBCgyX2jbUfKautPPuyyhylcbrh9e1zXx18oCyx3ASmUYVxnBPRi0I rrPcJfzcvJZbm7cR4QakNYM7JWJDb/WJjt0HeL0cMB5oVv7siP8WaV+AvwIcQ4Mt0Wkz o82foN9oo8VhbagtUtP4bzxmXMONAGuVC1yUV/we6YB+n5X51F0qD7+vYSpTFULJp79l moXXu9u2LVO2wnUv62gMkk8fmvcMqZ9hd9Up6eMmCQCNlffviN32finRWO9Hgb3fNbBg rRT6o86JhYqhhJ9tpzFdme1Dt3XIiU+v4JHeE2NlTqZqO8E+V/Y+F62Va3mZY5X/dzK/ oMxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-transfer-encoding; bh=R7Nq4QVbjvOYAp4V4VK4haEvYLPyh0wFJcfhhgnkkx4=; b=IibKiMKZAbRx/wpDmBRAuIBMjCOgiHUbqvc5vot1DVoNutYR1yvjIux5VZLkSzdgg5 4+uoFiixzgc4gJwXm2K5pOzA1hmUbIcVV5S9bKU7F9fssQK8q9rXCdxJ9XzIydrUzWVs t2VEGyzC0+0PsSm5w/rzyE4jxDetO85kPp//Yb3RxDFhqxylCp4CI4g5BD8y890NXoup EsDjXW8ILC4SDuqsJksdUcdnLfcQWpCAJ/BpHvQ2y2T5YPq1/Qsw6PTzADREZ6xaBWAu 5HcW2FLWpANrU7btBj7cUG2alvh09+l0P1+NztJTpuhdPkufik/gqOPX+SurVN/aOfNn V1nw== X-Gm-Message-State: AA6/9RkKAwtB3lPJ5myA6KHwKgfBhEddsbEPDFCqXHVSfBpUIkHpnxv1Y8lGsLO+EBZQzA== X-Received: by 10.36.107.211 with SMTP id v202mr18228820itc.51.1474897701561; Mon, 26 Sep 2016 06:48:21 -0700 (PDT) Received: from [10.0.10.3] (cpe-24-165-201-26.neo.res.rr.com. [24.165.201.26]) by smtp.googlemail.com with ESMTPSA id i80sm3894102ita.5.2016.09.26.06.48.20 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Sep 2016 06:48:21 -0700 (PDT) Message-ID: <57E92726.2020605@gmail.com> Date: Mon, 26 Sep 2016 09:48:22 -0400 From: Ernie Luzar User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: "Hartmann, O." CC: FreeBSD CURRENT Subject: Re: Destroy GPT partition scheme absolutely, how? References: <20160926150109.0d0d793e@hermann> In-Reply-To: <20160926150109.0d0d793e@hermann> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Sep 2016 13:48:22 -0000 Hartmann, O. wrote: > I ran into a very nasty and time consuming problem. Creating a NanoBSD > image with a modified script framework creating GPT partitions, I put > the imaes via "dd(1)" on USB flash or SD flash. Because the images are > usually much smaller than the overall capacity of the USB or SD, the OS > (FreeBSD CURRENT, recently built as of this morning) complains about > the second GPT header isn't in the last LBA. Sometimes, my PCengines > APU2 doesn't boot then, a relief is to issue the command > > gpart recover da1 > > (in that case, the USB flash drive or SD flash is recognized > as /dev/da1). > > But I run into a nasty situation, if the image put to the flash is > somehow corrupted. Then I tried to write a second, repaired image over > the first one using dd(1) again and do a recovering as mentioned above > - but this is fatal in two ways. First, the corrupted/broken GPT seems > to be "recovered" and put in replacement of the correct one - so I > guess. Performing no recover leaves the image on flash corrupted > anyway. > > Well, to be honest, I didn't exactly know what is going on here. The > phenomenon is that I had a problem creating a NANO_DATASIZE= DATA > partition with an empty NANO_DATASIZE which somehow corrupted the > whole image. The image then never booted, complaining, > that /foo/bar/_.mnt was unmounted unleanly. > > This happened multiple times, even if I tried to overwrite the SD or > USB flash with /dev/zero or /dev/random data, but I do stop such a dd > after a couple f minutes, since the SD is 32GB in size and the USB > flash drive is 32 GB, 64 GB and 128 GB - a pain in the ass if you want > to write via USB 2.0. But even with overwriting with a good image then > results in a corrupt image on flash drive, complaining about the GPT > second header not in last LBA and the issue with the uncleanly > unmount _.mnt (from the creation process of the NanoBSD image)! > > So I guess there is something magic happening. Some informations are > not lost and I suspect the "recovery" moving those foul data into > active places. > > Using a fresh/new SD or USB resolves the problem. But the question > remains: how can I destroy any relevant GPT information on a Flash > drive (or even harddisk) to avoid unwanted remains of an foul image > installation? > > First guess was to write the last couple of bytes on such a flash drive > by letting dd(1) counting backwards, but I couldn't figure out how to > let dd(1) do such a procedure. The nightmare didn't end, while trying, > the SD flash card died :-( > > thank you very much for your help and thoughts. > > Kind regards, thanks in advance, > > This little script has been posted before. Maybe it will be what your looking for. Called gpart.nuke #! /bin/sh echo "What disk do you want" echo "to wipe? For example - da1 :" 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 and partition table. dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} count=1 # Delete GEOM metadata. dd if=/dev/zero of=/dev/${disk} bs=${sectorsize} oseek=`expr $sectors - 2` count=2 done