Check a Drive For Bad Sectors with Badblocks

At home I have a pfSense firewall, the thing about my firewall is that I did a full installation on a Compact Flash card. Because, I want the benefits of a full installation like not loosing RRD graphs in case someone accidentally pulls the plug. The downside of using Compact Flash cards or Flash memory is the finite number of writes before wearing down and resulting in damaged sectors (unusable ones).

The advantages of Flash memory are: no moving parts, creates little heat, low power, and no noise. This is why Flash memory is ideal for my needs, and I know of other full installs on Compact Flash cards that have worked for up to three years and even longer.

You can take some precautions to reduce wear on a Compact Flash like:

  • Use the embedded version of pfSense
  • With enough RAM the system may not have to use the swap partition at all.
  • Remove the swap partition.

And it doens’t hurt to know that SLC Flash will last longer than MLC Flash.

Flash Cell Endurance: For Multi-Level Cell (MLC) Flash, up to 10,000 write cycles per physical sector. For Single-Level Cell (SLC) Flash, up to 100,000 write cycles per physical sector.

Source: Kingston Flash Memory Guide

Because, I have 512MB of RAM in my Firewall which is more than enough, I did not remove the swap partition.

Still, I worry about the finite number of writes on Flash memory, which prompted me to use badblocks. Badblocks is a tool capable of scanning a drive and report back on any damaged sectors it encounters. Modern drives can handle damaged sectors by seamlessly ignoring damaged sectors and only working with the remaining good sectors. This may sound great at first, but the truth is that the card is in the process of deteriorating(more to come) and the drive may need to be replaced.

Tools of the trade

For this tutorial I will be using Parted Magic a Live distribution which includes badblocks. However, you will find badblocks on any Linux distributions. Also, make sure the target drive is unmounted before running badblocks.

First you need the name of the drive you wish to scan, for this we can use lshw or Hardware Lister. The command is lshw -C disk.

root@PartedMagic:~# lshw -C disk
  *-disk                  
       description: ATA Disk
       product: ELITE PRO CF CAR
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sda
       version: Ver3
       serial: 5B021A040
       size: 3639MiB (3816MB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 signature=8f800000
  *-cdrom
       description: DVD reader
       physical id: 0.1.0
       bus info: scsi@3:0.1.0
       logical name: /dev/scd0
       logical name: /dev/sr0
       capabilities: audio dvd
       configuration: status=nodisc
  *-disk
       description: SCSI Disk
       physical id: 0.0.0
       bus info: scsi@4:0.0.0
       logical name: /dev/sdb
       size: 492MiB (515MB)
       capabilities: partitioned partitioned:dos
       configuration: signature=795b8ead

Fortunately, the Compact Flash card I am using provides more than enough information about its location /dev/sda. With that information in mind we can continue to the second step of this tutorial.

Let’s search for bad blocks

The command is very simple to understand badblocks -options /target_drive. The graphic below should help explain the meaning of the parameters.

Result

From the output below you can see that badblocks checks every block from 0 all the way to 3727079.

root@PartedMagic:~# badblocks -nvs /dev/sda
Checking for bad blocks in non-destructive read-write mode
From block 0 to 3727079
Checking for bad blocks (non-destructive read-write test)
Testing with random pattern: done                                
Pass completed, 0 bad blocks found.

After three months of use my 4GB Kingston Compact Flash card is performing like expected with zero bad blocks.

If you plan on doing a full installation on a Compact Flash then you should use badblocks to monitor the health of the Compact Flash over time. Remember to unmount the drive you wish to scan with badblocks.

Video

I also made a video of the process.

Links

Parted Magic Home Page
Badblocks
lshw

Parted Magic: Erase A Hard Drive

I have blogged several times before about Parted Magic the open source live distribution that can do pretty much anything(test, backup, partition) when dealing with drives. This time I will focus on a specific tool found on Parted Magic meant to provide a method for the secure wipe or deletion of data from a hard drive by overwriting with generated data.

Erase Disk is simple to use tool thanks to its easy to understand interface, you can choose the method with which the data will be erased. Keep in mind that we are overwriting the drive, any attempt to recover data after an accidental overwrite will not be possible.

Thanks to Parted Magic you now have an operating system independent tool for erasing disks.

Its recommended you disconnect all drives except the one you wish to overwrite.

Let’s Start…

  1. First download Parted Magic from the Parted Magic website and burn the ISO to a CD/DVD or create a bootable USB flash drive.
  2. Remember to set the BIOS to boot from removable media, may vary depending on the BIOS, and boot in to Parted Magic.

Let’s Erase

Once you are presented with the Parted Magic desktop go to the left bottom corner of the screen and click on the Parted Magic icon.

Go to Parted Magic > System Tools > and click on Erase Disk

A new window will open, this window contains the options available for erasing the drive. Which are:

  • External (dd disk): Employs ‘dd’ to write zeroes to the selected drive.
  • External (dd part): Zeroes out (with ‘dd’) the selected partition.
  • External (shred disk): Uses ‘shred’ (versus ‘dd’) to write zeroes.
  • Internal: Secure Erase command writes zeroes to entire data area.

The first option should be enough to completely overwrite the drive. Choose the option you are comfortable with and click on Continue….

Remember to choose the correct drive, otherwise you will not be able to recover the data from an accidental wipe.

Click on OK to confirm and start the process.

You can actually see the command used to erase the data dc3dd log=/tmp/dd_log.sdb status=noxfer sizeprobe=on of=/dev/sdb bs=4096 count=104857600.

Success, remember that it may take a considerable amount of time anywhere from minutes to hours depending on the size of the drive and data.

Overwriting a drive will not cost you anything since the tools needed are available free of cost. Formating a drive will only leave you vulnerable to recovery software.

Links

Parted Magic Site

VMware – Mouse problem when using a live cd

I had this recurring problem with VMware Workstation and Player whenever I tried to use a live cd like Parted Magic to partition a VMware virtual machine the mouse would not respond or stay of course the whole time, meaning I could never click on what I intended. The problem only seemed to happend when I tried to use a live CD.

vmware_1

The problem seems to be with VMware and the way it appears the mouse is connected when in reality it’s not. The solution is an easy that can be solved with a few clicks.

For some reason trying to use Crtl + Alt won’t work. You have to shutdown or reboot the virtual machine in order to release the mouse.

The instruction can be used on both VMware Workstation and Player.

  • Start VMware Workstation or Player and go to: VM > Settings
  • vmware_2

  • In the new window you are presented with several options. Click on the Hardware tab and then on USB Controller under Connections check the box Show all USB input devices and click on Save
  • vmware_3

  • Start the virtual machine and on the bottom right of the window you will see a new set of icons, one of them represents represents your actual mouse. As you can see it’s actually disconnected which is the whole reason behind the problem.
  • vmware_4

  • Right click on the icon and select Connect. The virtual machine will immediately take control of the mouse.
  • vmware_5

  • In order to release the mouse you have to either reboot or shutdown the virtual machine.