Ubuntu 19.10 (Eoan Ermine)

I recently set a goal to upgrade my personal laptop from Linux Mint to the latest Ubuntu version. By the time I made that decision, I was running Ubuntu under a VM, and even though Ubuntu & Mint share – more or less – the same code base (the latter one being derived from the first), I had decided I want to switch to Ubuntu – permanent!

And so I did!

Initially, I was going to make this a HOWTO guide, documenting everything I do to set my system the way I like it. Little did I expect I would run into major problems (which because of my stubbornness (or persistence – depending how I feel I want to portray it :)), had cost me 2 weeks of HDD testing, identifying bad blocks and marking them so they cannot be used.

First of all – what happened?

My laptop hosts 3 hard drives – an SSD one (basically where my / was mounted) and two 1TB magnetic hard drives (one where my  /home was mounted and the other one simply serving as extra disk space where I would normally set my VM pool to).

Now, for whatever reason,  the swap partition was set as the first logical partition on the 2nd magnetic drive. I could live with that, BUT for some reason, I decided it would be best if I recreate the swap partition on my SSD or my 1st magnetic drive and claim those petty 16GB off of my 2nd 1TB drive!?

I ran parted off a bootable USB (can’t remember if it was the actual live Ubuntu USB or SystemRescueCD), but it froze in the middle of the process, and there was nothing I could do to recover from that but forcefully power off the laptop. I’m pretty sure this is what caused the bad blocks on my – (until then) well performing drive. I tried recovering the partition, but in vain – nothing helped.

My reaction after that was probably natural, but definitely not needed:

  • If you have a relatively “new” magnetic HDD, chances are 99.999% it comes with S.M.A.R.T. technology, which in essence will take care of identifying and marking any bad blocks so they won’t be used by the underlying OS – until it cannot find anymore any good blocks. BTW, SMART does a lot more than just identifying bad blocks. It takes care of monitoring your HDD overall health.
  • The more bad blocks are being identified, the slower R/W operations become, thus affecting the overall HDD performance – and trust me, it becomes noticeable.

My circumstances were different though. But even under these circumstances, I went to unnecessary lengths:

  • I had created a detailed backup before I began the process, so pretty much I was covered (which was probably the best thing I could do, despite the fact I was sure of what I was doing)
  • I was dealing with an empty partition, hence most of the commands I ran were completely unnecessary
  • When in a similar situation, best thing to do is identify and mark any bad blocks as the file system is being created
  • In my case, I had an ext4 partition, so all I had to do was run this in the terminal mode:
sudo mkfs.ext4 -cc /dev/sdb1

Besides formatting the file system, the command uses 4 different patterns (0xaa, 0x55, 0xff, 0x00) to test each block (read, write, compare). Naturally, this process takes “a while” for a HDD of 1TB.

If you’re working with a non-empty partition with (valuable!) data already on it, and you’re suspecting bad blocks (or your S.M.A.R.T enabled HDD tells you so!) then the best course of action (that I recommend) would be:

  • make an image of the partition (or the entire drive) – if possible
  • use badblocks to identify any bad blocks (in a non-destructive read/write mode) and store them in a file:
sudo badblocks -nsv -o /home/jeps/Temp/badblocks-sdb.txt /dev/sdb1
  • then “feed” this file to the fsck command:
sudo fsck -t ext4 -l /home/jeps/Temp/badblocks-sdb.txt /dev/sdb1

And this should do it – unless you want to torture your self and run the smart tools twice:

  • once as a terminal command:
sudo smartctl -t long /dev/sdb
  • and a second time (in my case at least) from Ubuntu’s Disks tool:

SMART_01

SMART_02

It is my understanding if the Reallocated Sector Count doesn’t increase over time, you should be safe.

Still, if you really value your data – do yourself a favor and buy a brand new HDD. Now that I’ve gone through the pain of running (unnecessary) different terminal commands, I plan to listen to my own advice!