Friday, October 19, 2012

Erase (Discard) all data on an SSD in Linux

A little background:
I had a 60 GB OCZ SSD that had Windows on it and some apps. I wanted to erase it to start fresh to test out Fedora 18 Alpha on it in a laptop. I didn't need to securely erase anything, I just wanted the SSD to know it can erase everything.

Here's what I did.

First I had a Fedora LiveUSB drive. That's not important but what is important is hdparm installed. I had to yum install hdparm from a terminal. Single user runlevel is a good idea for the rest of this...

First I needed to see how large the SSD is in sectors.
gdisk told me what what I wanted to know.

(The following is retyped, not copy and pasted and parts are omitted)

gdisk /dev/sda
Command (? for help): p
Disk /dev/sda: 117231408 sectors

So now know the size, 117231408 sectors which is important because hdparm will need input in sectors.

I found out that the --trim-sector-ranges option of hdparm will not do more than 65535 sectors at a time so I needed to use --trim-sector-ranges-stdin so I could specify all at once.

First I needed to generate a sector list.

for ((i = 0; $i < 117231408; i = $i + 65535)) do echo $i:65535 >> sectors.txt; done

Warning about that, I typed that from memory. The important part is you're looping from Sector 0 up untill the end before 11723140 (for my drive). Then it's stepping by 65535. I feel like I should have stepped by 65536 but I didn't so each line might have overlapped by 1 sector. In practice it wasn't an issue. Also, the very last entry in sectors.txt will be wrong. I didn't care enough to special case it or manually calculate the correct length.

So now sectors.txt looks like

Then I did the actual (well nearly the actual) trim command.

hdparm --trim-sector-ranges-stdin /dev/sda < sectors.txt

Actually there's another --option thing but it will tell you and warn you what you're about to do is dangerous to your data. I'll omit it for the people copy and pasting to make the stop and think.

I ended up getting an error about a few of the sectors at the end (the error on the last entry basically) but nothing bad. Rebooting is now a good idea. And you're done!

If you follow these instructions be warned I might be doing it wrong and I only looked at about the first 1K of data on the drive to see it was blanked.

Good luck.

Thursday, October 18, 2012

Dell PERC 5/e on Fedora 16 and an MD1000 Enclosure

For various reasons I have a Dell PERC 5/e hooked up to an MD1000 enclosure on a workstation running Fedora 16 64 bit. All is fine with the already configured raid but I can't edit it at all when I add or remove drives. For a long time I lacked a way to edit arrays without rebooting to bios.

Now no more.

Thanks to the following links:

Download link for MegaCli:

Ah-ha moment link (a.k.a how to make it work):

How to use it:

So first download the zip, unzip the zip, unzip the zip that was in the zip, yum localinstall the rpm and you're done installing. You'll find the program in /opt/MegaRAID/MegaCli/

Now for the magic to make it work, lets make a shell script wrapper. It's not mandatory but it's a good idea. Just look at the ah-ha moment's link about 2/3rds down the page right after the part where they "Test it out..." Actually, just read the whole page. In case that's down the magic is that the program checks the kernel version and only runs on 2.6.
setarch x86_64 --uname-2.6 /opt/MegaRAID/MegaCli/MegaCli64
Will make it work. The script sticks all that in a wrapper for less typing.