Your hard drive with very important family pictures has just failed, and now all data is lost forever. Could you have prevented this from happening? This article is a quick walk though of how to detect hard drive errors before the disk is unusable.
Recently I decided it was time to grab up a spare computer that I could use for tinkering as well as back up files from my other machine in the event that it goes down. The one big thing I wanted to do was to install a Linux OS and experience everything that comes with it. This would be my first time installing a Linux OS. I chose to install Ubuntu since it is the most widely used and has the most extensive documentation and help available.
When I bought this machine it had a fresh install of Windows XP and came with the recovery disk which was excellent because I had to use it multiple times before I got things just the way I wanted them. Since this computer didn’t have any files I didn’t have to worry about backing anything up but it would be a must if considering putting Ubuntu on an everyday machine. To install Ubuntu you need the install CD. Ubuntu community can mail you one if you so request online, but why not be a DIYer and burn it yourself? I downloaded the Ubuntu 9.10 Desktop version for a graphical install and then went straight to burning it onto a CD. This was a mistake. I didn’t figure that the piece of the installation instructions regarding running the checksum was all that important, but it absolutely is. If the download is the least bit wrong the installation will not work. I burned several CDs of a bad image. Eventually I followed the installation documentation more closely and actually downloaded winMd5Sum. With this free tool I was able to compare the checksum of the downloaded image with the correct checksum from the Ubuntu site. It took several attempts and switching to a Canadian mirror before getting a successful download. Finally I could burn it to a disc.
Recently I had the heartbreaking experience of having to reboot a Linux server. Normal usage should almost never require you to reboot the OS like you have to so frequently in Windows. In this case I had an external USB drive partitioned with LVM humming along on a Linux server. I needed to pull the drive, so like I’ve done with other drives I unmounted all partitions on the drive. Then proceeded to unplug it from the USB port. All well and good. But when I plugged it back in, the lvs command was showing error messages on the partitions and I was unable to mount them.
Some Google searches later I found that when it comes to LVM partitions the OS keeps references to it unless you explicitly tell it to unhook them. Only then can you tell the OS to hook the LVM partitions back up when you’ve plugged the drive back in. In my case I had to resort to rebooting the server in order for the OS to hook all the pieces together for the LVM partitions. Short of this I would have to manually delete certain files and move things around to get the LVM partitions to work again. So here are the magic incantations that will save you the headache.
Before you unplug an LVM partitioned USB drive, you must run the following commands:
#!/bin/bash lvchange -an /dev/your_volume_group_name vgexport -a
Use the man command to explore what these commands do.
Now you should be able to unplug the drive. When you are ready to plug it back in, stick it back in the USB port and run the following commands:
#!/bin/bash vgimport -a lvchange -ay /dev/your_volume_group_name
You should now be able to run lvs and see you LVM partitions on the USB drive without any errors and proceed to mount the partitions.
Hope you found this useful. Are there other or different ways of doing this? Please add your comments below and Happy Holidays!