Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm crafting up a shell script (to be called by cron) that runs smartctl on the booted disk on a weekly basis. Is there a fairly universal way to determine what the boot block device is (IE - /dev/sda, /dev/hdb, etc)? The expected install would be standard, I think I could get away with using grep " / " on /etc/fstab, I'm just wondering if there's a more graceful way.

This script will specifically be deployed on Fedora and possibly Ubuntu boxes.

share|improve this question
1  
Are you really looking for the boot device, or are you looking for the root device? If you are looking for / in fstab, and your boot device is different from your root device then you may not get the results you want. –  Zoredache Dec 8 '11 at 19:13
    
That is a valid point. For my specific needs, it will always be the same device. –  Chris Weiss Dec 8 '11 at 20:17
    
What boot-loader are you using on these machines? –  Zoredache Dec 8 '11 at 20:24
    
Grub currently, but the best solution should be future-proofed against alternatives. –  Chris Weiss Dec 8 '11 at 20:55

2 Answers 2

df -P / | tail -n 1 | awk '/.*/ { print $1 }'

Will return the root FS block device. Not necessarily the boot device though.

Better question might be why you're not scanning SMART on all the disks in the server?

share|improve this answer
    
In my specific case, this is a script that will be deployed to hundreds of single-disk kiosk machines with either a SATA or PATA disk (so 99% of them would be /dev/sda or /dev/hda, I just want to make sure I don't miss the 1% that somehow ended up being /dev/sdb or something). Your solution almost works. Unfortunately, what I need is the boot device (That returns /dev/sda3, I just need /dev/sda). –  Chris Weiss Dec 8 '11 at 20:07
cat /proc/mounts |grep /boot |awk '{print $1}'

Will return something like /dev/sda1 if your /boot is not on the root device.
Combine this with the answer from Chris S.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.