2

I'm installing CentOS 7 using the ks option. Example:

ks=http://10.0.0.100:8080/anaconda-ks.cfg

From within this configuration file, how can I "dynamically" fetch the URL of its location?

In this case, I want this: "http://10.0.0.100:8080/"

EDIT: Ultimately, what am doing is I match the MAC address of the machine against a Python dictionary (JSON file) in order to determine which hostname to set during installation. And I would like to avoid hard-coding the URL to the JSON file into the kickstart configuration script.

fredrik
  • 731
  • 15
  • 20

2 Answers2

2

The only thing that is exposed to the kickstart script that is useful is the kernel command line. You can access this at

/proc/cmdline

If you're using the solution I provided here then you can read the ks=... parameter. You can pass /proc/cmdline to a pipe, something like

url=`sed 's/=/ /g' /proc/cmdline | awk '{for(i=1; i<=NF; i++) if ($i~/ks/) print $(i+1)}'`

would return the field following ks to url once we have converted the = to spaces.

I don't have access to a kickstart environment not to test this so uyou may need to tweek it a bit with paths.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • I just realised that this returns the full file path. It should be pretty easy to modify it to remove the last bit. – user9517 Dec 28 '15 at 21:21
  • Excellent, I used Python's `subprocess.check_output( ['cat', '/proc/cmdline'] )` and then detected the URL from the returned string. – fredrik Dec 29 '15 at 00:20
  • That looks like an embedded [UUOC](http://porkmail.org/era/unix/award.html) to me. Python can surely just read the file itself without the need to spawn a subprocess. – user9517 Dec 29 '15 at 07:08
  • Oh, that is completely right. This should work: `with open('/proc/cmdline', 'r') as myfile: data = myfile.read()` - thanks for pointing that out. Not sure why I took the detour of subprocessing... (late night coding I guess) – fredrik Dec 29 '15 at 10:00
0

You can send hostname parameter as kernel parameters (--extra-args in virt-install call). For example:

# virt-install \
    -n centos   \
    -r 2048   \
    --vcpus=1   \
    --os-variant=rhel7 \
    -accelerate \
    -w bridge:virbr0   \
    --disk path=/opt/vm/test2.qcow2,size=100 \
    -l /opt/iso/CentOS-7.0-1406-x86_64-DVD.iso \
    --name test2 \
    --extra-args "ks=http://192.168.122.1/ks.cfg ksdevice=eth0 ip=192.168.122.40 netmask=255.255.255.0 dns=8.8.8.8 gateway=192.168.122.1 hostname=my-hostname"

And hostname automatically will be configure as my-hostname.

e42d3
  • 75
  • 2
  • This is on physical hardware http://serverfault.com/questions/745515/how-to-remotely-initiate-netinstall-of-centos-7. – user9517 Dec 28 '15 at 20:38