So if you want to erase a drive with custom data you can do yes "text here" > /dev/sdX but I was wondering if this is a secure way to do so?
- 229
- 2
- 5
1 Answers
Not directly, I guess, but possible.
running this:
sudo yes "ruslansendthistothedisk1gb" > /dev/sdb
I got
bash: /dev/sdb: Permission denied
Then I decided to it with dd:
yes "ruslansendthistothedisk1gb" > file.txt
and
sudo dd if=file.txt of=/dev/sdb
this worked:
167424+0 records in
167424+0 records out
85721088 bytes (86 MB) copied, 27.073 s, 3.2 MB/s
As for being secure, I only thought what if you send data with size more than a device capability, would not it be damaging anything else.
Then I decided to feed the device with file which is knowingly more than my /dev/sdb disk.
sudo fdisk -l /dev/sdb
as can be seen size is 1015808000 byte
Disk /dev/sdb: 1015 MB, 1015808000 bytes 32 heads, 61 sectors/track, 1016 cylinders, total 1984000 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
Disk identifier: 0x6874646e
Disk /dev/sdb doesn't contain a valid partition table
the file size:
ls -la file.txt
as can be seen is 1103699968
-rw-rw-r-- 1 shiva shiva 1103699968 Jun 21 15:00 file.txt
and copy it to the device:
sudo dd if=file.txt of=/dev/sdb
after several minutes it said:
dd: writing to `/dev/sdb': No space left on devicel
and in short time
1984001+0 records in
1984000+0 records out
1015808000 bytes (1.0 GB) copied, 451.234 s, 2.3 MB/s
As it can be seen, partition disappeared even after copying short fragment to the device, I assume it is enough to send just one random byte to destroy file system and it will not show partition, but still can be dumped by dd. So if you want do erase all your device with no chance to find any data on it, then it is better to "overwrite" it completely, with full size of the device.
- 2,186
-
If you run
sudo yes "text" > /dev/sdbor just run it as root, it works. I was wondering about the security of it. – dsadsads Jun 21 '14 at 14:35 -
I did try to run it with
sudoit gavebash: /dev/sdb: Permission denied, I did not try as root. – Ruslan Gerasimov Jun 21 '14 at 22:20 -
Odd, just sudo works great for me. I was just curious about this as a funny way to erase something so if anyone ever tried recovery they would get a good laugh.
For true security, I would zero it and then
– dsadsads Jun 22 '14 at 01:54yes "stuff" > /dev/sdX
shred. Writing data using yes would probably be pretty secure, butshred's three passes on the drive would be better. – MetaNova Jun 21 '14 at 17:01