Bernard Fay
2016-Nov-07 19:35 UTC
[CentOS] How to start a script to complete configuration
Hi, We have a virtual environment based on XenServer. In this environment I defined a template for CentOS 7 servers. I would like to start a script a boot time to complete the configuration of new VMs based on this template. How can I have a script started before any login prompt to ask question to the user to complete the configuration such as hostname, IP address, etc? Thanks, Bernard
cpolish at surewest.net
2016-Nov-08 15:47 UTC
[CentOS] How to start a script to complete configuration
On 2016-11-07 14:35, Bernard Fay wrote:> Hi, > > We have a virtual environment based on XenServer. In this environment I > defined a template for CentOS 7 servers. > > I would like to start a script a boot time to complete the configuration of > new VMs based on this template. How can I have a script started before any > login prompt to ask question to the user to complete the configuration such > as hostname, IP address, etc?Hi Bernard, My first impulse was "don't!", and that's probably the best advise. A popular model is that the "firstboot" package takes care of this at the first user login, and *nix systems sort of depend on this "logged in users do stuff" model. Even better, use ansible, cfengine, chef, or puppet to automate the task of setting things up. This is the _best_ solution and you will eventually come back to it. But, the darker, cynical part of my brain, the part that says "what, you're cutting down on coffee?" part, said "sure you can". Here's how it _could_ be done. DON'T DO THIS. TURN BACK NOW. Replace /sbin/init with a shell script that does what you want. It will be the first userland process started, have the console for I/O, and run as root. At completion, restore the original /sbin/init and reboot. Leave no traces behind. Do not document your awful hack, others will use your words against you. Best regards, -- Chuck
Bernard Fay
2016-Nov-08 16:26 UTC
[CentOS] How to start a script to complete configuration
It would be hard to use ansible, cfengine or whatever while there no IP address on the new VM..... On Tue, Nov 8, 2016 at 10:47 AM, <cpolish at surewest.net> wrote:> On 2016-11-07 14:35, Bernard Fay wrote: > > Hi, > > > > We have a virtual environment based on XenServer. In this environment I > > defined a template for CentOS 7 servers. > > > > I would like to start a script a boot time to complete the configuration > of > > new VMs based on this template. How can I have a script started before > any > > login prompt to ask question to the user to complete the configuration > such > > as hostname, IP address, etc? > > Hi Bernard, > > My first impulse was "don't!", and that's probably the best > advise. A popular model is that the "firstboot" package takes > care of this at the first user login, and *nix systems sort of > depend on this "logged in users do stuff" model. > > Even better, use ansible, cfengine, chef, or puppet to automate > the task of setting things up. This is the _best_ solution and > you will eventually come back to it. > > But, the darker, cynical part of my brain, the part that says > "what, you're cutting down on coffee?" part, said "sure you > can". Here's how it _could_ be done. > > DON'T DO THIS. TURN BACK NOW. > > Replace /sbin/init with a shell script that does what you want. > It will be the first userland process started, have the console > for I/O, and run as root. At completion, restore the original > /sbin/init and reboot. Leave no traces behind. Do not document > your awful hack, others will use your words against you. > > Best regards, > -- > Chuck > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos >
Leon Fauster
2016-Nov-08 17:43 UTC
[CentOS] How to start a script to complete configuration
Am 08.11.2016 um 16:47 schrieb cpolish at surewest.net:> On 2016-11-07 14:35, Bernard Fay wrote: >> Hi, >> >> We have a virtual environment based on XenServer. In this environment I >> defined a template for CentOS 7 servers. >> >> I would like to start a script a boot time to complete the configuration of >> new VMs based on this template. How can I have a script started before any >> login prompt to ask question to the user to complete the configuration such >> as hostname, IP address, etc? > > Hi Bernard, > > My first impulse was "don't!", and that's probably the best > advise. A popular model is that the "firstboot" package takes > care of this at the first user login, and *nix systems sort of > depend on this "logged in users do stuff" model. > > Even better, use ansible, cfengine, chef, or puppet to automate > the task of setting things up. This is the _best_ solution and > you will eventually come back to it. > > But, the darker, cynical part of my brain, the part that says > "what, you're cutting down on coffee?" part, said "sure you > can". Here's how it _could_ be done. > > DON'T DO THIS. TURN BACK NOW. > > Replace /sbin/init with a shell script that does what you want. > It will be the first userland process started, have the console > for I/O, and run as root. At completion, restore the original > /sbin/init and reboot. Leave no traces behind. Do not document > your awful hack, others will use your words against you.:-) ... kernel parameter init=/root/yourscript https://www.kernel.org/doc/Documentation/kernel-parameters.txt -- LF