0

I recently had my original computer stolen so I bought a second hand one and created a boot disk for Bullseye using dd in a linux VM on the original windows OS.

This worked perfectly fine and bullseye has been working well, but I want to erase the contents of the external hard drive I created the boot disk on.

When I insert it, it does not appear on the desktop as usually occurs, so I ran

sudo fdisk -l

And the output showed that it is being recognized by my system, and lists it as "sdb"

so I tried

cd /./;cd dev;ls -a

and the output does list it, but it obviously isn't a folder as stated when I the tried

cd sdb

So my question is, can i from here use rm to simply delete sdb and its listed partitions in the dev folder?

My suspicion is that the issue is related to the fact that the contents of the drive is the boot disk I used to install the OS I am trying to delete it from. But that's the best guess I have.

I have also worked through all of the other suggestions that were proposed in this thread On the Debian Forum for the exact same problem. At the end of it, it seems they concluded that the ext hard drive is defective.

However I know mine isn't defective, because although I don't have another computer, I plugged it into my smart tv and was able to view its folder contents with no issues at all.

2 Answers 2

2

The sdb device isn't a folder or file to be erased, it is the representation of the actual disk device. You cannot use rm to erase partitions on this device.

If you want to remove the partitions, you can do so using fdisk. This will not clear the data in the partitions, it will only remove the partition information from the disk's partition table.

If you want to remove the files from the partitions, you will have mount the partitions you wish to clean up. This will be a sequence of commands, for each partition, similar to:

# mount /dev/sdb1 /mnt/scratch
# rm -rf /mnt/scratch/*
# umount /mnt/scratch

You can then use fdisk to remove the partition definitions. Please note, this procedure is destructive, and will result in unrecoverable data loss (absent some very specialized restoration facilities). Also note that erasing the contents of the boot disk will very likely render the disk not bootable, so I'm not sure that you actually want to do this.

6
  • Ok thanks John, I'm so new to computers so much terminology is almost alien to me, so apologies for the nativity regarding not exactly knowing the difference between a folder and a disk. But if I understand you correctly, I risk deleting the inbuilt file system that enables the external hard drive to interface with another device as a usb peripheral correct? That's an excellent point, and I think you just saved me having to buy another one! Am i able to somehow display the date of creation for every single file on the disk, May 17 at 21:08
  • and then use the process you suggested above to only remove those that coincide with the date i made the boot disk? May 17 at 21:10
  • I'm not sure I understand exactly what you want to achieve, so I'm not sure what to recommend. How did you create this boot disk (what was the exact dd command you used)? Why do you now want to delete the boot disk?
    – John
    May 18 at 11:48
  • sudo dd if=$ISOFILENAME of=$DRIVEPATHNAME To be honest I just want it so I can set up cron to daily back up everything on my new computer, in light of my original one that was stolen containing 10 years worth of work i had written in maple code, as well as the paid up licensing for a linux install of maple which has the exclusive benefit of having a command line version, enabling me to incorporate into bash scripts etc, and i hate begging family for money for another ext HD. I see your problem this is all things i should save for therapy instead of wasting unix dev time May 18 at 12:04
  • OK... first - I am assuming that the target of dd, the $DRIVEPATHNAME, was the external drive. Do not delete anything from the external drive. It is exactly what it needs to be to boot properly. Second, backups are an unrelated (though important) issue. Your best bet is to find a backup service that installs an agent on your computer - something like Barracuda, iDrive, Backblaze, or Acronis. Note: this is not and should not be construed as an endorsement of any of those.
    – John
    May 18 at 13:33
1

my recommendation:

alias lsblk2='lsblk -o type,name,label,partlabel,size,fstype,model,serial,wwn,uuid'

then run lsblk2 and identify the correct device... i.e./dev/sdb in your case... so you don't blow away the wrong disk

# this will blow away the existing partition table in one easy step
# change "sdb" to the correct device for you, as identified by my lsblk2 alias

parted /dev/sdb mklabel gpt

like was mentioned, simply blowing away or recreating partitions and/or tables does not wipe data from the disk, there is still the risk of data being recovered off the disk. There are various ways to deal with that if you find it necessary to do so, for example giving the disk away to someone or if you had tax info and personal info on it that you don't want any possibility of someone getting it after you have thrown the disk in the trash.

After the above parted command, you will be left with just sdb showing up with no partitions.

parted /dev/sdb mkpart primary 0 100

now you will have one partition, showing up as /dev/sdb1 that spans the entire disk, but it will not have a file system on it.

From here you can

mkfs.xfs /dev/sdb1

to create a file system that you can then mount in linux and read/write to; it will be completely empty however on the disk itself the previous data is still technically there at the disk one zero level. If you then need to wipe or secure erase the disk, whether its a hard disk drive (hdd) or solid state disk (ssd) there are various methods. When it is an ssd, I believe causing TRIM to happen will effectively wipe the ssd when it has a brand new empty file system on it and using hdparm is one method to make that happen.

Erasing the boot disk on an external hard drive

that syntax kinda doesn't make sense... but to erase the boot sector of the disk a simple

dd if=/dev/zero of=/dev/sdb bs=512 count=1

would do it, as the legacy msdos boot sector is the first 512 bytes of the disk... do bs=4096 to be super sure, but then the disk will be unusable until you recreate a proper partition table such as parted /dev/sdb mklabel gpt

2
  • Ok thanks I honestly don't know enough about this subject to select between the two answers received, I'll keep this in mind, but considering how in depth this seems to be, and considering i just wanted to use the drive for making back ups, it might be smarter to just buy another one and keep this one as it is so i can just reinstall bullseye in the event i ruin my current OS, which is statistically at least a 1 in 4 chance of happening lol May 17 at 21:33
  • i just wanted to use the drive for making back ups == do what I said up until and not including where I mentioned dd. Identify the correct disk, make a new gpt partition table that is clean and empty, make 1 partition spanning entire disk, make a file system on the disk. There are many different file systems to choose from, xfs should suit you just fine, there's also mkfs.ext3 and mkfs.ext4 which are probably the next most common and reliable like xfs. Once you've made a file system then you can mount it in linux and use it.
    – ron
    May 18 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.