Overwriting the last bytes of a partition
Greetings, I am looking for a way to delete the last 131072 bytes of any partition. So far I have been trying to create a dd command without success, any ideas or suggestions? Thanks.
|
Hi, and welcome here, at LQ.
I would like to know what dd commands did you create and execute and how do you know if they were successful (or not). Is this your homework? |
Hi, thanks for replying, the closest I have to a working one (I think) is this [sudo dd if=/dev/urandom of=/dev/sdX bs=512 count=256 seek=$(( $(sudo blockdev --getsize64 /dev/sdX) - 256 ))]. It seems that the "seek" argument is not accepted due to its dynamic content, "skip" didn't work either.
|
how do you know it did not work?
|
I'd suggest eliminating sudo and running it as root.
|
Code:
blockdev --getsize64 /dev/sdX Code:
sudo blockdev --getsize64 /dev/sdX) - 256 How are you going to find the end of a particular partition? |
@pan64
The "seek" parameter reports the error when it contains a variable, "skip" doesn't but it doesn't work either. I verify it using veracrypt, it is an encryption software that (according to its documentation) creates a header at the beginning and a backup header at the end, each of 131072 bytes. The purpose is both to erase both master passwords and to completely hide the use of veracrypt. I easily remove the main one with [sudo dd if=/dev/urandom of=/dev/sdX bs=512 count=256] but despite my attempts I can't remove the backup one. In my different attempts or does nothing, allowing me to restore the main header successfully and without damaging the content, or simply breaks everything. @Emerson Using root didn't change anything by trying it, I also have a good relationship with sudo, but thanks. @Michaelk Oops thanks, I tried other blockdev parameters and left the wrong one saved, the others used blocks instead of bytes, I should have noted which ones I used. That did not cause any catastrophic results, nor any others that I can appreciate. Anyway using [sudo dd if=/dev/urandom of=/dev/sdX bs=512 count=256 seek=$(( $((sudo blockdev --getsize64 /dev/sdf2) - 131072 ))] didn't work either. I tried blockdev separately and it works as expected (on /dev/sdf2 in my case), I was hoping to dynamically mark the end of several partitions (and preferably disks), should I use another tool? |
Code:
seek=$(( $((sudo blockdev --getsize64 /dev/sdf2) - 131072 )) seek=$(( $(sudo blockdev --getsize64 /dev/sdf2) - 131072 )) |
@Michaelk
*faceplam* Another error I added when posting this, the original was fine. I'm pretty much a noob, I was hoping to get it the easy way. But I guess, whether it works or not, it's time to learn about bash :-/ |
in that case would be nice to post what did you try exactly, we cannot handle the differences and the "original".
And also please use code tags. Code:
sudo dd if=/dev/urandom of=/dev/sdf2 bs=512 count=256 seek=$(( $(sudo blockdev --getsize64 /dev/sdf2) - 131072 )) But only if there was no any syntactical issue with it. To make it more readable you can split it into several lines and add some debug prints like: Code:
P_SIZE=$(sudo blockdev --getsize64 /dev/sdf2) |
I previously tried the first one you just posted, without the small syntax error. My apologies for creating confusion and not using the tags.
Unfortunately neither worked (the format in which the second one is written is interesting to me and will be useful in the future, also shellcheck, thanks!) and it still says that seek= is an invalid argument. I noticed that it is also invalid if instead of using a dynamic content I directly use the number (total bytes minus the desired ones). Strangely only by providing a number two digits below the correct one it is accepted, which obviously corrupted the content. I have rechecked everything again thoroughly, blockdev gives the same results as gnome disks. In dd everything works in bytes, count= is well calculated, deleting bs= or replacing it with obs= (although both default to 512) doesn't change anything even if seek= has no dynamic content. Everything looks like it should be fine, could it be a bug in dd? Is there any other suitable tool for this? |
there is no dynamic content at all. You see something like that, but the shell itself (bash) will evaluate the text [and execute that blockdev getsize] you entered and dd will only see the result.
dd has no any idea about everything else, but the arguments passed. and I think there is no such bug in dd. |
I sometimes miss the obvious...
seek defaults to blocks but we are calculating bytes. To use bytes you need to add oflag=seek_bytes option to your dd line. |
Quote:
|
@Michaelk
Thank you so much!! It's embarrassing, I really messed up. I have done some tests and now it works perfectly :-) @pan64 Well, it really only said that it was an invalid argument in a non-English language. Now it is clear that the number entered was greater than the total blocks. Thanks for trying and especially for the other useful data. |
All times are GMT -5. The time now is 04:26 AM. |