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 have what is surely a remedial question for anyone with more Linux experience. I need to check if an operating system is already installed in my kickstart script, and if so, prompt the user if they would like to continue (basically reinstall) or to exit.

What is the most efficient way to do this?

I was thinking of doing something like the following:

%pre
#!/bin/sh
if [ -f some_file ]; then
  read -p "An OS already exists, do you want to re-install?" yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
fi

I'm not sure what file would be best to use in place of "some_file" in my example, or if this is even a good way to go about it.

Note that the reason I need to do this is because this Linux installation is part of a much larger automated installation so a user is not there to manually check if the OS exists already.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Where would the / filesystem reside, if an operating system were installed? Would it be in the same place on all the nodes you intend to install?

You could test for the presence of a partition:

[ -b /dev/sdXY ] && { do something ; }

Or a logical volume:

[ -b /dev/mapper/vg00/lvXYZ ] && { do something ; }

You could attempt to mount it, and test for the presence of a certain file:

mkdir /tmp/mt
if mount /dev/sdXY /tmp/mt && [ -f /tmp/mt/filename ]; then
      do something
fi
share|improve this answer
    
Thank you, Patrick, that looks like it should work for me. I was originally planning on handling the case where any OS of any flavor was installed, but my task does not require that so I will try your suggestion. –  MsStarlifter Sep 21 '12 at 17:31
add comment

We simply set the BIOS boot order to HD followed by PXE.

This means the system will install from PXE at first boot, subsequent boots are from the installed OS.

When we need to reinstall, we just wipe the boot sector from within the OS then reboot.

share|improve this answer
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.