How you could do this with scripts: *CentOS 7* 1. Deploy a VM from your base CentOS 7 template 2. Copy your "my-firstboot.sh" script (or whatever its called) to a location such as /root/scripts/ 1. This scripts only job should be to mount a NFS location and execute any post install scripts you have stored there, and provide a log file. 2. This script should disable the "my-firstboot.service" at the end and then change permissions of itself to no execute to ensure it doesn't get run more than once. 3. It is also useful to have this script email the system admins when its done and reboot the VM (in the case of full system updates that require a reboot to new kernel) 3. Create your "my-firstboot.service" unit file at: /etc/systemd/ system/my-firstboot.service, enable it. example contents: 1. [Unit] Description=Auto-execute my post install scripts After=network.target [Service] ExecStart=/root/scripts/my-firstboot.sh [Install] WantedBy=multi-user.target *CentOS 6* 1. Same thing as above, except no service unit file. Instead simply create a line in /etc/rc.local to execute the "my-firstboot.sh" script like so: 1. echo "/root/scripts/my-firstboot.sh" >> /etc/rc.d/rc.local 2. And have the "my-firstboot.sh" script remove that same line above from rc.local at the end of its execution so its not run again on the next reboot. Bill On Tue, Nov 8, 2016 at 3:44 PM, Oscar Osta Pueyo <oostap.listas at gmail.com> wrote:> Hello, > I think you can use anaconda for this task, you can configure some actions > after the installation. > > Best regards, > > El dt, 8 nov 2016 a les 18:44 Leon Fauster <leonfauster at googlemail.com> va > escriure: > > > 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 > > > > _______________________________________________ > > CentOS mailing list > > CentOS at centos.org > > https://lists.centos.org/mailman/listinfo/centos > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos >
Forgot to mention. After this is setup, shutdown the VM and create a template from it. Then, any VMs created from this new template will auto execute your scripts. Bill On Wed, Nov 9, 2016 at 7:01 AM, Bill Howe <howe.bill at gmail.com> wrote:> How you could do this with scripts: > > *CentOS 7* > > 1. Deploy a VM from your base CentOS 7 template > 2. Copy your "my-firstboot.sh" script (or whatever its called) to a > location such as /root/scripts/ > 1. This scripts only job should be to mount a NFS location and > execute any post install scripts you have stored there, and provide a log > file. > 2. This script should disable the "my-firstboot.service" at the end > and then change permissions of itself to no execute to ensure it doesn't > get run more than once. > 3. It is also useful to have this script email the system admins > when its done and reboot the VM (in the case of full system updates that > require a reboot to new kernel) > 3. Create your "my-firstboot.service" unit file at: /etc/systemd/ > system/my-firstboot.service, enable it. example contents: > 1. [Unit] > Description=Auto-execute my post install scripts > After=network.target > > [Service] > ExecStart=/root/scripts/my-firstboot.sh > > [Install] > WantedBy=multi-user.target > > *CentOS 6* > > 1. Same thing as above, except no service unit file. Instead simply > create a line in /etc/rc.local to execute the "my-firstboot.sh" script like > so: > 1. > > echo "/root/scripts/my-firstboot.sh" >> /etc/rc.d/rc.local > > 2. And have the "my-firstboot.sh" script remove that same line > above from rc.local at the end of its execution so its not run again on the > next reboot. > > > Bill > > > On Tue, Nov 8, 2016 at 3:44 PM, Oscar Osta Pueyo <oostap.listas at gmail.com> > wrote: > >> Hello, >> I think you can use anaconda for this task, you can configure some actions >> after the installation. >> >> Best regards, >> >> El dt, 8 nov 2016 a les 18:44 Leon Fauster <leonfauster at googlemail.com> >> va >> escriure: >> >> > 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 >> > >> > _______________________________________________ >> > CentOS mailing list >> > CentOS at centos.org >> > https://lists.centos.org/mailman/listinfo/centos >> > >> _______________________________________________ >> CentOS mailing list >> CentOS at centos.org >> https://lists.centos.org/mailman/listinfo/centos >> > >
Barak Korren
2016-Nov-09 13:13 UTC
[CentOS] How to start a script to complete configuration
On 9 November 2016 at 15:06, Bill Howe <howe.bill at gmail.com> wrote:> Forgot to mention. After this is setup, shutdown the VM and create a > template from it. > Then, any VMs created from this new template will auto execute your scripts.If you're just talking about VMs and templates, you can try 'virt-builder' or 'virt-sysprep' for manipulating the templates directly (Instead of booting them up in a full VM). Theses tools also allow you to inject scripts and commands to be run once a VM created from the template is brought up for the 1st time. Another option to consider is installing the cloud-init package in the VM. Some virtual environments allow you to inject instructions into VMs using cloud-init. -- Barak Korren bkorren at redhat.com RHCE, RHEV-DevOps Team
Bernard Fay
2016-Nov-09 15:03 UTC
[CentOS] How to start a script to complete configuration
To Bill, The script solution is what I try to do. I am close to it. The problem I am facing at the moment is that this script need to be interactive to have input from the sysadmin. I tried to add the following lines to the service unit file to direct the interaction of the script to tty1 but without success: StandardInput=tty TTYPath=/dev/tty1 TTYReset=yes TTYVHangup=yes On Wed, Nov 9, 2016 at 8:01 AM, Bill Howe <howe.bill at gmail.com> wrote:> How you could do this with scripts: > > *CentOS 7* > > 1. Deploy a VM from your base CentOS 7 template > 2. Copy your "my-firstboot.sh" script (or whatever its called) to a > location such as /root/scripts/ > 1. This scripts only job should be to mount a NFS location and > execute any post install scripts you have stored there, and provide > a log > file. > 2. This script should disable the "my-firstboot.service" at the end > and then change permissions of itself to no execute to ensure it > doesn't > get run more than once. > 3. It is also useful to have this script email the system admins when > its done and reboot the VM (in the case of full system updates > that require > a reboot to new kernel) > 3. Create your "my-firstboot.service" unit file at: /etc/systemd/ > system/my-firstboot.service, enable it. example contents: > 1. [Unit] > Description=Auto-execute my post install scripts > After=network.target > > [Service] > ExecStart=/root/scripts/my-firstboot.sh > > [Install] > WantedBy=multi-user.target > > *CentOS 6* > > 1. Same thing as above, except no service unit file. Instead simply > create a line in /etc/rc.local to execute the "my-firstboot.sh" script > like > so: > 1. > > echo "/root/scripts/my-firstboot.sh" >> /etc/rc.d/rc.local > > 2. And have the "my-firstboot.sh" script remove that same line above > from rc.local at the end of its execution so its not run again on the > next > reboot. > > > Bill > > > On Tue, Nov 8, 2016 at 3:44 PM, Oscar Osta Pueyo <oostap.listas at gmail.com> > wrote: > > > Hello, > > I think you can use anaconda for this task, you can configure some > actions > > after the installation. > > > > Best regards, > > > > El dt, 8 nov 2016 a les 18:44 Leon Fauster <leonfauster at googlemail.com> > va > > escriure: > > > > > 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 > > > > > > _______________________________________________ > > > CentOS mailing list > > > CentOS at centos.org > > > https://lists.centos.org/mailman/listinfo/centos > > > > > _______________________________________________ > > CentOS mailing list > > CentOS at centos.org > > https://lists.centos.org/mailman/listinfo/centos > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos >