0

I am using Kubuntu 22.04.3 LTS x86_64.

While re-purposing a disk using:

neofetch --stdout |grep 'OS:'

Instead of long process of dd zero the whole disk just dd zero some first bytes of disk and then dd zero some last bytes of disk and leave the middle bytes of disk as they are.

I understand this command below starts at the front of disk or Location 000000 and then can confirm a zero filled disk or
if disk is not all zeros then stop command and output at first non-zero location:

time sudo dd if=/dev/sdb bs=1M status=progress | od | head  #verify_disk_zero_filled_statusProgress  
  
132120576 bytes (132 MB, 126 MiB) copied, 5 s, 26.3 MB/s  
  
   0000000 000000 000000 000000 000000 000000 000000 000000 000000
*
1004000000 060000 000014 071000 000061 074346 000002 006072 000060
1004000020 057765 000014 000000 000000 000002 000000 000002 000000
1004000040 100000 000000 100000 000000 020000 000000 000000 000000
1004000060 012736 060472 000000 177777 167523 000000 000001 000000
1004000100 012735 060472 000000 000000 000000 000000 000001 000000
1004000120 000000 000000 000013 000000 000400 000001 000074 000000
1004000140 001102 000000 000173 000000 147441 013053 117027 110110
1004000160 002275 160114 106464 074723 000000 000000 000000 000000

real    0m5.224s

Question:

What is the command?

How to do the same as above command but start at back of disk, start at end of disk, and then output in MB (Megabytes) from the back of disk as to the first non-zero location?

Said differently, If disk was:

128.0 GB and disk was all zeros until 127.9 GB the command starts at disk end and scans towards disk front and will output 000.1 GB or 100 MB from end of disk, occurs the first non-zero byte.

For above example, the desired command would output 100 MB.

Thus allowing script change of
m_b from 32 MB to 128 + MB in script:

m_b=32  # Megabytes from disk end, for dd command.   
time sudo dd if=/dev/zero  of=/dev/sd_  bs=512  count=$(( 2048 * $m_b )) seek=$(( $(sudo blockdev --getsz /dev/sd_) - 2048 * $m_b )) status=progress     #lastbytes_zero 

sd_=sdb or sdc ...

Output from above dd command:

33047040 bytes (33 MB, 32 MiB) copied, 14 s, 2.4 MB/s
65536+0 records in
65536+0 records out
33554432 bytes (34 MB, 32 MiB) copied, 15.0554 s, 2.2 MB/s
  
real    0m15.089s

From disk end, how to count MB (Megabytes) to the first non-zero location?

1 Answer 1

0

This is the accepted answer by user psusi from the post Wipe last 1MB of a Hard drive :

The simplest way on Linux to get the size of the disk is with blockdev --getsz:

sudo -s
dd bs=512 if=/dev/zero of=/dev/sdx count=2048 seek=$((`blockdev --getsz /dev/sdx` - 2048))

An alternative answer by user Gilles is :

The size of every partition is available in /proc/partitions. The following command shows the size of sdx (in kB units):

awk '$4 == "sdx" {print $3}' </proc/partitions

Thus:

dd if=/dev/zero of=/dev/sdx bs=1k count=1024 \
   seek=$(($(awk '$4 == "sdx" {print $3}' </proc/partitions) - 1024))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .