LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 11-19-2012, 07:33 PM   #1
MrsBalurdo
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Rep: Reputation: Disabled
Determine if operating system already exists via kickstart %pre%


Hello everyone,

I am trying to check if an operating system already exists in the %pre% section of my kickstart file (for Red Hat). If it does, I need kickstart to quit. I have figured out how to make kickstart quit in my %pre% section, but I'm now having trouble determining in the first place if an OS already exists.

My idea is to check if a particular directory (such as /etc/httpd, or anything really) exists, and if so, quit. The problem is I can't directly access /etc/httpd from the %pre% section.

I thought maybe I needed to mount /dev/sda1, but it does not let me, so my questions are:

1) What is the best way to access the hard disk from the %pre% section?
2) Is there an entirely different and better way to accomplish what I need?


Thank you!
 
Old 11-20-2012, 10:51 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604
Quote:
Originally Posted by MrsBalurdo View Post
What is the best way to access the hard disk from the %pre% section?
The best method would be the one using commonly used commands are available in the pre-installation environment and use those in away that doesn't leave much root for error.


Quote:
Originally Posted by MrsBalurdo View Post
Is there an entirely different and better way to accomplish what I need?
As you can see the toolkit includes dd, grep and fdisk so you could check for media that represents attached storage, and string search for (absence of) evidence like PC98, GPT, MIPS and other disk label or partition tables types, LUKS, etc, etc.
 
2 members found this post helpful.
Old 12-03-2012, 02:05 PM   #3
MrsBalurdo
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you, I was able to use the fdisk command and then search the result for "sda1". If it was not found, then an OS didn't exist, but if it was, then it did.

The code I used for the check was the following in case it helps anyone:

var=`fdisk -l |grep -c "sda1"`
if [ "$var" -ge 1 ]; then
...desired handling goes here...
 
Old 12-03-2012, 02:25 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,328
Blog Entries: 33

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
You're assuming that the disk isn't using GPT.
 
Old 12-03-2012, 03:42 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604
Quote:
Originally Posted by MrsBalurdo View Post
Thank you, I was able to use the fdisk command and then search the result for "sda1". If it was not found, then an OS didn't exist, but if it was, then it did.
IMHO your match is way too specific and there's a whole range of things it doesn't address, GPT being just one aspect. On the one hand I'm wondering why you would want OS detection and on the other hand I'm wondering how detailed or conclusive OS detection should be to be successful. If you assert kickstart kicks in after stage 2 is loaded then maybe you have an environment with /proc loaded (check that), in which case you could grep /proc:
Code:
grep -e "[h,s]d[a-z]1$" /proc/partitions
Note that's the current installer kernels interpretation, which may not know everything. Another way may be to use 'fdisk'. Here it only returns the first partition of a disk and only if it has the 0x83 Linux signature:
Code:
fdisk -l | awk '/[h,s]d[a-z]1/ {if ($6 == "83") print $1}'
another more elaborate way could be to extract partition names like above but examine them with dd:
Code:
for PARTITION in $(fdisk -l | awk '/[h,s]d[a-z]1/ {if ($6 == "83") print $1}'); do
 dd if=${PARTITION} bs=2M count=1|egrep -qm1ai "(MSDOS|LDR|BSD|LILO|syslinux|GRUB|EF00)";
and use the exit code to do Something Completely Different (if you dig MPFC, that is). Mind you that egrep isn't all-encompassing and whatever you do YMMV(VM).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PXE Netboot Operating System (Network OS Booting/running) NOT Kickstart installation ajr-tech Linux - Server 4 01-28-2011 10:39 AM
'Operating system not found' Any operating system installed wont work. TechniSlave Linux - Newbie 55 02-09-2009 11:02 AM
Bash scripting and trying to determine whether a directory exists? obelxi Programming 9 04-18-2005 11:22 PM
where does 'su' look to determine if a user exists? MisterESauce Linux - Software 5 04-13-2005 09:18 AM
Does anyone know of a bash script that will determine if RPM exists on a system? jimwelc Linux - Software 3 12-28-2004 03:01 PM


All times are GMT -5. The time now is 03:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration