5

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.

2 Answers 2

5

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
1
  • 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. Sep 21, 2012 at 17:31
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .