Ubuntu: from inittab to upstart

1,151 views
Skip to first unread message

Robert Citek

unread,
Feb 28, 2008, 12:29:38 AM2/28/08
to Central West End Linux Users Group
Ubuntu changed from using init (and /etc/inittab) to using upstart
(and /etc/event.d). Great, except that I think whomever was pushing
upstart left out the transition documentation. Even after Googling
and reading the upstart docs, I haven't been able to find answers to
some questions:

1) How does one change the default runlevel? When Ubuntu boots, it
boots into runlevel 2. I'd like it to boot into runlevel 5. With
/etc/inittab I would modify the "id:" line.

2) How does one re-read the /etc/even.d files? With inittab, I would
type 'init -q'. In upstart I modified the /etc/event.d/rc-default
file, changing 2 to 5. However, if I type "init 1" and then exit from
runlevel 1, Ubuntu still goes into runlevel 2. According to the docs,
any changes in events should be automatic:

http://upstart.ubuntu.com/faq.html#reload

3) How does one specify a different runlevel at boot time? With init
I would simply specify the run level at the end of the kernel line.
That doesn't work in Ubuntu.

4) How does one enter Emergency mode? Before upstart one could
specify -b and only a minimal number of drivers were installed, e.g.
no networking.

Any pointers appreciated.

Regards,
- Robert

Sean Burns

unread,
Feb 28, 2008, 9:24:12 AM2/28/08
to cwe...@googlegroups.com
When I first started using Linux, I bought a book called _A
Practical Guide to Linux_ by Mark G. Sobell. It was published in
1997 but I still find it one of the most useful Linux books I've
ever used. So I emailed Sobell last May and he responded that
he'd be publishing an Ubuntu book soon. Looks like it was
published a few weeks ago.

Anyway, seems he wrote something about /etc/event.d:
http://www.linux.com/feature/125977?theme=print

I haven't read it yet, but what you need might be there.

Sean

--
Thu, 28 Feb 2008 08:18:53 -0600

Sean Burns

unread,
Feb 28, 2008, 9:43:56 AM2/28/08
to cwe...@googlegroups.com
On Thu, Feb 28, 2008 at 08:24:12AM -0600, Sean Burns wrote:
> When I first started using Linux, I bought a book called _A
> Practical Guide to Linux_ by Mark G. Sobell. It was published in
> 1997 but I still find it one of the most useful Linux books I've
> ever used. So I emailed Sobell last May and he responded that
> he'd be publishing an Ubuntu book soon. Looks like it was
> published a few weeks ago.
>
> Anyway, seems he wrote something about /etc/event.d:
> http://www.linux.com/feature/125977?theme=print
>
> I haven't read it yet, but what you need might be there.

Here's the specific info you need. Interesting....

Under SysVinit, the initdefault entry in the /etc/inittab file
tells init which runlevel to bring the system to when it comes
up. Ubuntu does not include an inittab file and, by default,
the Upstart init daemon (using the rc-default task) boots the
system to multiuser mode (runlevel 2, the default runlevel).
If you want the system to boot to a different runlevel, create
an inittab file. The following file causes the system to boot
to single-user mode (runlevel S):

$ cat /etc/inittab :id:S:initdefault:

When the system comes up in single-user (recovery) mode, if
the root account on the system is unlocked, init requests the
root password before displaying the root prompt. Otherwise it
displays the root prompt without requesting a password.

Never set the system to boot to runlevel 0 or 6, as it will
not come up properly. To boot to multiuser mode (runlevel 2),
remove the inittab file if it exists or create the inittab
file shown in the example and replace the S with a 2.

Sean
--
Thu, 28 Feb 2008 08:41:06 -0600

Robert Citek

unread,
Feb 28, 2008, 10:03:25 AM2/28/08
to Central West End Linux Users Group
On Thu, Feb 28, 2008 at 8:43 AM, Sean Burns <sean...@gmail.com> wrote:
> Never set the system to boot to runlevel 0 or 6, as it will
> not come up properly. To boot to multiuser mode (runlevel 2),
> remove the inittab file if it exists or create the inittab
> file shown in the example and replace the S with a 2.

Why does that design sound so very wrong?

What's worse is that I don't think it will work. Below is the actual
rc-default script. If I create an /etc/inittab file, it would be the
sed line that would change the default runlevel. Yet, I changed the
2's to 5's in the script and Ubuntu still boots into runlevel 2.

<quote>
# rc-default script
start on stopped rcS

script
runlevel --reboot || true

if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
telinit S
elif [ -r /etc/inittab ]; then
RL="$(sed -n -e
"/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
if [ -n "$RL" ]; then
telinit $RL
else
telinit 2
fi
else
telinit 2
fi
end script
<quote>

Regards,
- Robert

Sean Burns

unread,
Feb 28, 2008, 10:27:06 AM2/28/08
to cwe...@googlegroups.com
On Thu, Feb 28, 2008 at 09:03:25AM -0600, Robert Citek wrote:
> Why does that design sound so very wrong?
>
> What's worse is that I don't think it will work.

Yep, I tested it too and it won't boot into any other runlevel. I
have to put this off for a while, and I don't recall if you
mentioned this, but you might find some info here:

http://upstart.ubuntu.com/index.html

Sean

--
Thu, 28 Feb 2008 09:24:47 -0600

Robert Citek

unread,
Feb 28, 2008, 2:24:17 PM2/28/08
to cwe...@googlegroups.com
On Thu, Feb 28, 2008 at 9:27 AM, Sean Burns <sean...@gmail.com> wrote:
> On Thu, Feb 28, 2008 at 09:03:25AM -0600, Robert Citek wrote:
> > Why does that design sound so very wrong?
> >
> > What's worse is that I don't think it will work.
>
> Yep, I tested it too and it won't boot into any other runlevel.

Thanks for testing it. Nice to see confirmation.

> I have to put this off for a while,

I understand. Like you this is going on the back burner for now.
Being able to change runlevels is really useful for debugging services
and drivers. It's unfortunate that changing runlevels doesn't work or
doesn't work as expected with upstart.

> and I don't recall if you
> mentioned this, but you might find some info here:
>
> http://upstart.ubuntu.com/index.html

Yup. That's where I've been reading and haven't found anything really
helpful there. There might be nuggets in the wiki page, but I haven't
fully explored that, yet. I'll post to the forums and see what I can
get from there.

Regards,
- Robert

Robert Citek

unread,
Feb 28, 2008, 4:27:15 PM2/28/08
to Central West End Linux Users Group
On Thu, Feb 28, 2008 at 9:03 AM, Robert Citek <robert...@gmail.com> wrote:
> Why does that design sound so very wrong?
>
> What's worse is that I don't think it will work. Below is the actual
> rc-default script. If I create an /etc/inittab file, it would be the
> sed line that would change the default runlevel. Yet, I changed the
> 2's to 5's in the script and Ubuntu still boots into runlevel 2.

Maybe a little sleep helps. Tried it today and it works as expected.

So, I modified the script to this:

<quote>
# rc - runlevel compatibility
#
# This task guesses what the "default runlevel" should be and starts the
# appropriate script.

start on stopped rcS

script
def_RL=4
runlevel --reboot || true

if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
telinit S
elif [ -r /etc/inittab ]; then
RL="$(sed -n -e
"/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
if [ -n "$RL" ]; then
telinit $RL
else

telinit $def_RL
fi
else
telinit $def_RL
fi
end script
</quote>

To change the default runlevel, I change the value of def_RL.

Regards,
- Robert

Robert Citek

unread,
Feb 28, 2008, 4:36:25 PM2/28/08
to Central West End Linux Users Group
On Thu, Feb 28, 2008 at 3:27 PM, Robert Citek <robert...@gmail.com> wrote:
> On Thu, Feb 28, 2008 at 9:03 AM, Robert Citek <robert...@gmail.com> wrote:
> > Why does that design sound so very wrong?
> >
> > What's worse is that I don't think it will work. Below is the actual
> > rc-default script. If I create an /etc/inittab file, it would be the
> > sed line that would change the default runlevel. Yet, I changed the
> > 2's to 5's in the script and Ubuntu still boots into runlevel 2.
>
> Maybe a little sleep helps. Tried it today and it works as expected.
>
> So, I modified the script to this:

I changed my default RL to 5 and then modified what starts up in
different runlevels:

sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf --list
sudo sysv-rc-conf --level 2 gdm off

If you are familiar with chkconfig from fedora or red hat, then you'll
fell (mostly) at home with sysv-rc-conf.

Regards,
- Robert

Sean Burns

unread,
Feb 28, 2008, 4:49:20 PM2/28/08
to cwe...@googlegroups.com

Thanks Robert. This is really good to know.

Sean

--
Thu, 28 Feb 2008 15:48:09 -0600

Robert Citek

unread,
Feb 28, 2008, 6:36:57 PM2/28/08
to Central West End Linux Users Group
On Wed, Feb 27, 2008 at 11:29 PM, Robert Citek <robert...@gmail.com> wrote:
> 3) How does one specify a different runlevel at boot time? With init
> I would simply specify the run level at the end of the kernel line.
> That doesn't work in Ubuntu.

Might as well modify the /etc/event.d/rc-default script to handle this, too:

<quote>
# rc - runlevel compatibility
#
# This task guesses what the "default runlevel" should be and starts the
# appropriate script.

start on stopped rcS

script
def_RL=5
runlevel --reboot || true

RL="$(< /proc/cmdline tr ' ' '\n' | grep -v '[^0-9]' | tail -1 || true)"
if [ -n "$RL" ] ; then
RL=$RL
elif grep -q -w -- "-s\|single\|S" /proc/cmdline; then
RL=S


elif [ -r /etc/inittab ]; then
RL="$(sed -n -e
"/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
if [ -n "$RL" ]; then

RL=$RL
else
RL=$def_RL
fi
else
RL=$def_RL
fi
telinit $RL
end script
</quote>

Now you can change the default runlevel by changing the value of
def_RL and you can boot into a different runlevel by putting the
runlevel number on the kernel line.

The logic's a bit contorted, but it works. Fell free to refactor.

Regards,
- Robert

Robert Citek

unread,
Feb 29, 2008, 1:04:34 AM2/29/08
to Central West End Linux Users Group
On Thu, Feb 28, 2008 at 5:36 PM, Robert Citek <robert...@gmail.com> wrote:
> On Wed, Feb 27, 2008 at 11:29 PM, Robert Citek <robert...@gmail.com> wrote:
> > 3) How does one specify a different runlevel at boot time?
>
> Might as well modify the /etc/event.d/rc-default script to handle this, too:
> ...

> The logic's a bit contorted, but it works. Fell free to refactor.

Slightly easier to read code:

http://ubuntuforums.org/showpost.php?p=4426474

Regards,
- Robert

Reply all
Reply to author
Forward
0 new messages