Riddle, Mystery, Enigma
- 0
- Add a Comment
- No Related Post
Riddle, Mystery, Enigma
I was building startup scripts today at work. Actually, I was adding commands to the /etc/rc.d/rc.local file that runs at boot. It’s a good place to autoexecute commands prior to seeing an X Window desktop. I use it for the few tasks we start at boot that require root privileges to execute. Today, it was a command to start the Global Positioning Satellite (GPS) receiver we use for precisely setting and updating the system time. The command is simple. gpsd -fsa starts the gps daemon, forces [-f] an adjustment to the system time when it starts, adjusts the time [s]moothly as necessary, and does a single write to the telescope configuration files to update latitude and longitude [a]. I wrote the line into /etc/rc.d/rc.local and rebooted for a thorough test. One problem - without adding & to the end of the command, the boot process never lets go of the gps daemon. In other words, the computer never completely boots. I watched my perfectly configured machine echo, “Starting GPS receiver … “, and hang, and hang, and hang. You know, it’s always the 11th hour stuff that kills!
So how do you change a file that prevents a Linux box from booting when you can’t get to a text editor because the box won’t boot? It looks like a real conundrum.
OK. Maybe I overdramatize it, but you knew that. I used a trick that is, in part, useful for when Mr. Root loses his password. First, I was able to reboot the machine cleanly using the nearly universal sign-language for “die machine” - [ctrl][alt][del]. That sends a signal to the system to kill all running processes and halt. Then I powered back up. At the Lilo prompt, I entered:
linux init=/bin/sh rw
This starts a minimal Linux system with the root filesystem mounted in read-write mode. It was just enough to give me access to vi and, by that, to the /etc/rc.d/rc.local file. I added the & at the end of the gps command and remounted the root filesystem in readonly mode:
mount -o remount,ro /
Just for good housekeeping sake, I ran the init process and rebooted:
exec /sbin/init 6
When the system came back up, the gps initialization worked perfectly. I love it when stuff works.
As I mentioned, much of this process works when you’ve lost the root password. Follow the initial boot instructions (linux init=/bin/sh rw). When you fall to the shell, enter the command “passwd” [no quotes]. This will allow you to create a new password. Once the password is changed, it’s a good idea to clear the cache buffers using sync; sync; sync. Remount the filesystem readonly, run the init process, and you’re off and running once again.
See - there really is an answer to every riddle.
