6.5 Single User Mode

Home » CentOS » 6.5 Single User Mode
CentOS 8 Comments

Hello List,

I want to boot into single user mode and run a script automatically.

I have been looking for a couple of hours and have found one solution I don’t like.

How can I get the shell that is started in single user mode to run a script. My one solution was to add a profile in /etc/profile.d/ that called the script. Is this the only way to do it?

Thanks,

8 thoughts on - 6.5 Single User Mode

  • wild guess here:
    1. make this a username that isn’t used for any other purpose
    2. try setting the default shell in /etc/password, for that user,
    to run the script. This may require some experimentation to find
    the correct incantation.

    no clue if it’ll work, haven’t tried it.

    good luck!

  • Steve Clark wrote:

    How often – every time, or just once? If every time, create a script and put it in /etc/init.d/, with a link to /etc/rc1.d, or use whatever it is in systemd’s analog.

    mark

  • What is the big picture here? You could probably just stick your script into /etc/rc.d/rc.local where it will run at the end of the other runlevel processing – and have it put back the old version if it only needs to run once.

    But, poking through /etc/init/* it looks like a file named
    /etc/init/rcS-sulogin.override would do something magic like you want.

  • Everytime. We have a USB key that has a tarfile of CentOS and our software on it The script partitions the hard drive and untars the tarfile – this takes about 2 minutes vs using a custom kickstart file which takes 20 to 30 minutes.

    So we build a CentOS respin iso image along with our software – install it into a virtual machine and at the end of the install the ks file creates a tarfile from the new image. We then move this image to the USB key.

    In CentOS 5.x all I had to do was create a .profile file in / and it would get ran. CentOS 6.x doesn’t run the .profile –

  • If what you are really doing is the equivalent of cloning images, you might look at clonezilla, or the backup/restore package called rear
    (in EPEL). But for a quick brute-force change, you could probably edit /etc/init/rcS-sulogin.conf and add the script you want to replace
    /sbin/sushell.

  • I’d still recommend looking at clonezilla and rear. Clonezilla-live is a CD you boot to save/restore images – and there is also a network server version for PXE booting and image storage. The good part is that it can handle windows along with most linux versions. The down side is that the restore disk has to be the same size or larger. Rear is a set of shell scripts that use your own system tools to build a bootable image containing the scripts you need to partition, format, and restore (pretty much exactly what you are doing but with more options). It is really intended as a backup with a fast simple restore back on the same hardware, but you have an opportunity to change the disk layout if needed so it works for cloning or moving a working system.

    In an case, the other thing new in 6.x is that you need to remove the udev rules for the NICs or update them with the new MAC addresses or the cloned machine will start its ethx names above the old ones, plus fix the /etc/sysconfig/network-scripts/ifcfg-ethx files like you did in 5.x.

  • Yep – already ran into that. We have had our working for about 4 years and it was based on 5.x we are moving to x86_64 bit 6.x so I am creating a new usb key using 64 bit 6.x.