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.

Suppose I have a set of brand new servers that boot from PXE.

What I want to do is automatically detect that the internal HDD is not formatted and therefore create the partition and format it automatically at boot. Followed by adding the appropriate entry to fstab and mounting it. After that, it will be left alone. The drive is used for caching data only.

The bits I'm stuck on are 1) Recognize whether a disk has partitions or not. i.e. check if disk has a partition table. Can I just test for presence of file /dev/sda and not /dev/sda1? 2) recognizing which disk I booted from so I can ignore it. 3) Creating the partition from the command line.

So, what I'm hoping to put together is a script I can put into the boot process.

share|improve this question
    
Will a local OS be installed or will they netboot? –  Andrew Mar 22 '12 at 1:04
    
The servers will netboot only. –  Matt Mar 22 '12 at 1:24
add comment

2 Answers

up vote 2 down vote accepted

1) Recognize whether a disk has partitions or not. i.e. check if disk has a partition table. Can I just test for presence of file /dev/sda and not /dev/sda1?

I don't see why that wouldn't work, but you could also fdisk -l /dev/sda to list the partitions of a disk.

2) recognizing which disk I booted from so I can ignore it.

mtab should be enough to tell you mounted filesystems. That should be enough to avoid system disks. You could also look for the bootable flag.

But, if your goal is create a partition on raw disks - I don't really see why you'd need to specially ignore "system" partitions.

3) Creating the partition from the command line

I don't think fdisk has a way of handling this. There is sfdisk, though, which should be able to. Parted can also take a script.

Once the partition is made, you'll probably also need to refresh the partition table and then put a filesystem on it.

share|improve this answer
    
Thanks for the tips on mtab and parted. It's probably enough information to go on. –  Matt Mar 22 '12 at 2:06
add comment

You could achieve the same thing by tweaking your BIOS boot order so hard drive comes before network/PXE. This way if you have a working OS it will boot, otherwise it will then try PXE.

share|improve this answer
    
These hard drives are never going to have a OS installed on them. They will be cache only. The server will always be set to network boot. –  Matt Mar 22 '12 at 1:15
    
Sorry - didn't think of that - I was about to delete my answer but I've thought I may as well leave this here to stop anyone else from posting the same. –  Robin Gill Mar 22 '12 at 1:28
add comment

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.