Tiny Core Linux
Tiny Core Base => TCB Q&A Forum => Topic started by: Santos on December 07, 2019, 05:50:51 PM
-
Hi there!
I want to erase the end of a memory flash, by the end I mean the last blocks. Is there any way to choose one specific "block", like 100MB-250MB or just the last 10MB of the memory flash?
I've tried, but is going to work just for the first megabyte:
dd if=/dev/zero of=/dev/sdb bs=1048576 count=1
The option 'seek' works for just a file (or ignore such amount of input data, right?)
Thank you for your help.
-
Hi Santos
This should do what you want:
dd if=/dev/zero of=/dev/sdb ibs=1M obs=1M seek=200 count=10
That should skip the first 200MB and then write 10MB of zeros.
-
Thank you for answer.
So the memory flash in question it's a MMC 4GB (GPT, as per parted, 3975MB). I was messing with the B.E.E.R partition of it (last couple of KBs) and now I need to delete just that portion of memory.
dd if=/dev/zero of=/dev/sdb ibs=1M obs=1M seek=3970 count=5
So I typed the previous line in and it did not work, I got:
dd: /dev/sdb: Invalid argument
The same error is always popping up whenever I use the option 'seek' and a disk instead of a file.
-
Hi Santos
I think that error is from seeking a sector number higher than what exists on the device.
A little searching turned up this:
https://unix.stackexchange.com/questions/275243/what-does-dd-if-dev-zero-of-dev-sda-do/275260#275260
So I tried it on a 4GB thumb drive:
tc@E310:~$ dd if=/dev/zero of=/dev/sdg bs=512 count=10240 seek=$(expr `blockdev --getsz /dev/sdg` - 10240)
10240+0 records in
10240+0 records out
5242880 bytes (5.2 MB, 5.0 MiB) copied, 0.0386705 s, 136 MB/s
tc@E310:~$ sync
tc@E310:~$
And it zeroed out the last 5MB of the drive. Wait for the sync command to complete before removing the device.
Some quick notes on what's going on:
tc@E310:~$ blockdev --getsz /dev/sdg
7856127
tc@E310:~$ echo $(expr `blockdev --getsz /dev/sdg` - 10240)
7845887
The blockdev command (provided by util-linux.tcz) retrieves the number of sectors on the device.
The expr command subtracts the number of sectors you want to write (count) from the number of sectors on the device.
If you don't want to install util-linux.tcz you can use fdisk to get the number of sectors on the device:
tc@E310:~$ fdisk -l /dev/sdg
Disk /dev/sdg: 3.8 GiB, 4022337024 bytes, 7856127 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdg1 38 7839719 7839682 3.8G b W95 FAT32
And then plug in the number of sectors on the device by hand:
dd if=/dev/zero of=/dev/sdg bs=512 count=10240 seek=$(expr 7856127 - 10240)
-
Thank you very much!
This question is now solved.
-
Hi Santos
You are welcome. I will mark your original post as solved.