Spoofing S.M.A.R.T. in a Virtual Environment


What is This?

Setting up virtual environments can be essential to troubleshooting hardware and software problems. Unfortunately, if your software relies on SMART data to function properly, you’re out of luck, since virtual disks do not have SMART functionality.   Since I was attempting to setup a hardware configuration in a virtual environment and the software needed SMART data to function, I was disappointed in finding that every forum I encountered basically said I was dead in the water.   So I looked for an alternative. When I developed a workaround, I decided to write a tutorial in case there are others out there looking for a way to get SMART data in a virtual environment.

First, you will need to know what commands will need to respond with spoofed data. In my case, I needed the following commands to work, followed by their expected results:

1. smartctl –scan

/dev/sda -d scsi # /dev/sda, SCSI device

2. smartctl -A /dev/sda

2014-06-18 08_26_19-Edit Post ‹ The Powerbase — WordPress










3. smartctl -A /dev/sda1

***- Same as /dev/sda

4. smartctl -i /dev/sda

Model Family:     Western Digital RE4 Serial ATA
Device Model:     VBOX HARDDISK
Serial Number:    VB45d8dc08-eb70cc2e
LU WWN Device Id: 5 0014ee 208702935
Firmware Version: 1.0
User Capacity:    8,589,934,592 bytes [8.58 GB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   8
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Wed May 21 10:31:27 2014 EDT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

5. smartctl -i /dev/sda1

***- Same as /dev/sda

6. smartctl -H /dev/sda

SMART overall-health self-assessment test result: PASSED

7. smartctl -H /dev/sda1

***- Same as /dev/sda

Now we need to save these responses as text files to be called later by a bash script.

1. In a terminal, make a directory to place your new script:

sudo mkdir -p ~/scripts/spoofsmart

2. Change directory to your new folder:

cd ~/scripts/spoofsmart

3. Make a text file for each SMART response you need from above

sudo touch scan Adevsda Adevsda1 Hdevsda Hdevsda1 idevsda idevsda1

4. Open up permissions for each file with:

sudo chmod 775 *

5. With your favorite text editor, paste the responses from above into each text file as necessary (make sure to put the right data into the right file, i.e. the response from “smartctl -i /dev/sda1” should go into the text file “idevsda1”. Also, feel free to modify the data to fit your environment.

Now, we need to create a bash script named “smartctl” which will respond to all the variables and concatenate the proper files.

1. Create the script with:

sudo touch spoofsmart.sh

2. Open up permissions with:

sudo chmod 775 spoofsmart.sh

3. Using a text editor copy the text below into the spoofsmart.sh file.

#Spoofing smartctl response from drives in a virtual environment.
#Author - Isaac Penrod
#Date - 05/21/2014

#This script will spoof smartctl commands with data as if there were physical
#drives present. Make a backup of your "smartctl" before overwriting with
#this one!

##### smartctl --scan
if [ $1 = "--scan" ]
cat ~/scripts/spoofsmart/scan


###### Device sda

#smartctl -A /dev/sda
if [ $1 = "-A" ] && [ $2 = "/dev/sda" ]
    cat ~/scripts/spoofsmart/Adevsda

#smartctl -H /dev/sda
if [ $1 = "-H" ] && [ $2 = "/dev/sda" ]
    cat ~/scripts/spoofsmart/Hdevsda

#smartctl -i /dev/sda
if [ $1 = "-i" ] && [ $2 = "/dev/sda" ]
    cat ~/scripts/spoofsmart/idevsda


###### Device sda Partition 1

#smartctl -A /dev/sda1
if [ $1 = "-A" ] && [ $2 = "/dev/sda1" ]
   cat ~/scripts/spoofsmart/Adevsda1

#smartctl -H /dev/sda1
if [ $1 = "-H" ] && [ $2 = "/dev/sda1" ]
    cat ~/scripts/spoofsmart/Hdevsda1

#smartctl -i /dev/sda1
if [ $1 = "-i" ] && [ $2 = "/dev/sda1" ]
    cat ~/scripts/spoofsmart/idevsda1

Again… feel free to modify to fit your environment. Also, if you chose to add more responses for sdb, sdc, etc… make sure to add sections for each to the script.

Now comes the dangerous part.  (cont.)


Isaac Penrod

Related posts