Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to build a custom ISO, using ubuntu-builder. I've taken a 12.40 mini remix ISO as a starting point. Here is my specific example - however, I'm interested in principle how the process goes (so I can apply that to other DE/WM).

when I run a new ISO, built directly from the mini remix starting ISO, all is as expected - I can run the new ISO in a virtual machine, and the boot process terminates with text-only prompt for the live ubuntu user.

Now, I try to install LXDE (there is an entry for it in ubuntu-builder, apparently it installs lxde-core and X dependencies; and I manually have to install lxterminal, and as icons are missing, probably lxde-icon-theme as well). I have to also manually install xinit, so I have startx. But this, by itself, doesn't do much: if I boot this customized ISO in a virtual machine, the exact same thing happens as with the "original" ISO - boot process completes with a text mode prompt for ubuntu live user.

If I now type startx at this prompt, then LXDE starts (running startlxde at this prompt will complain about X), such that when you start lxterminal from that desktop, it is started under the live ubuntu user.


In LiveCDCustomization - Boot init, it is mentioned:

Boot init
You have to edit the files in edit/usr/share/initramfs-tools/scripts/casper-bottom/* For example you can change the hostname or the livecd user.

... but I don't exactly understand what is exactly being ran by what there. The ubuntu-builder unpacks these files under /home/ubuntu-builder/FileSystem/usr/share/initramfs-tools/scripts/casper-bottom/ - but as far as I can see, most of these just run some inline sed commands, I cannot see much executive commands there?

Still, I tried to copy one of the scripts there as a new script, 51startx, which in the executable section has:

log_begin_msg "$DESCRIPTION"

chroot /root startx
chroot /root startlxde

log_end_msg

This does absolutely nothing - again, after boot, I get the usual text prompt ubuntu@ubuntu:~$.


Then I found Modify: Startx automatically, add apt, etc - backtrack-linux.org:

To have a graphical login, just install gdm and run it in startup:

aptitude update
aptitude install gdm

Then, edit /etc/rc.local, and add a line BEFORE "exit 0" like this:

service gdm start

This is not the best way, but run! . This must work running "update-rc.d gdm defaults", but this way fail.

And indeed - I added:

startx
startlxde

... to /etc/rc.local - and this indeed does boot, and start LXDE automatically - however, when I run lxterminal, it is under user root - not under the live user ubuntu!


So, what should I do, so that I can start (any) X and/or any desktop environment automatically at boot under the live ubuntu user?

Note that in this case, I would not like to use an additional desktop manager (e.g. gdm) nor a corresponding greeter - but it would be good to know, if a solution for automatically starting up X would also work for a desktop manager or a greeter.

share|improve this question

1 Answer 1

OK, I think I got somewhere - but still don't quite get it, so a proper answer would be appreciated :)

But, basically: the boot process starts, somewhere in there the init process run, and the kernel loads - but also, some startup scripts run. These scripts are part of initramfs, from within the booting kernel they are referred to as /scripts/... - however, in the unpacked file system of ubuntu-builder they would be in ./FileSystem/usr/share/initramfs-tools/scripts/. Eventually - in a typical install - this would end up with loading the given Display Manager (DM), which "presents the user with a login screen which prompts for a username and password"; where apparently one design of such a screen in a DM is known as a greeter. Once the login has been performed in the DM greeter, then control is passed onto the Desktop Environment/Window Manager (DE/WM). I'm still not clear who/what starts the DM in the first place; but if it is started, I guess the DM afterwards is the starter of the DE/WM (depending on login authentication and settings). Or:

(boot start) --> initramfs --> scripts --> (kernel?) --> DM --> (login) --> DE+WM --> (boot completion)

I still cannot tell the difference between the DE and WM properly, but for example, LXDE is apparently a DE (as per the name); and typically it is used with openbox as a WM. So, in other words, what I want here is to skip the DM, and go directly to DE/WM as the live ubuntu user.

Back to the boot scripts - particularly, the init-bottom and casper-bottom are visible in the boot log messages - which are also available in the file /var/log/boot.log, once the ISO finishes booting and we can use less. Particularly interesting are these scripts:

$ sudo grep -ri "Adding live" ./FileSystem/usr/share/initramfs-tools/
./FileSystem/usr/share/initramfs-tools/scripts/casper-bottom/25adduser:DESCRIPTION="Adding live session user..."

$ sudo grep -ri dm ./FileSystem/usr/share/initramfs-tools/scripts/ | grep 'if \['
(./FileSystem/usr/share/initramfs-tools/scripts/casper-bottom/15autologin)
15autologin:if [ -d /root/etc/gdm ]; then
15autologin:if [ -f /root/etc/kde4/kdm/kdmrc ]; then
15autologin:if [ -f /root/etc/lxdm/lxdm.conf ]; then
15autologin:if [ -f /root/etc/xdg/lubuntu/lxdm/lxdm.conf ]; then
15autologin:if [ -d /root/etc/lightdm ]; then

So, the autologin script basically counts on a Display Manager (DM) being already installed (in the CD image) - and simply searches for possible config files thereof, and replaces inplace using sed, such that the particular DM performs an automatic login, once it is started (by whatever usually starts it). On the other hand, the adduser script creates the live user ubuntu from scratch during boot - and as such, there are no files we could apriori edit and store on the CD image.

The good thing, however, is that these scripts definitely run before /etc/rc.local runs, which runs before the bash terminal is ultimately started at end of boot. So what I've done, is used the /etc/rc.local file to "inject" an X startup sequence in ~/.bashrc of the ubuntu user:

$ tail -n 15 ./FileSystem/etc/rc.local 
#
# By default this script does nothing.

#sed -i 's/console/anyone/' /etc/X11/Xwrapper.config
#su - ubuntu -c "touch /home/ubuntu/.Xauthority"
#su - ubuntu -c startx
#sed -i 's/anyone/console/' /etc/X11/Xwrapper.config

echo ls -la /home/ubuntu
ls -la /home/ubuntu
# echo startx >> /home/ubuntu/.bashrc # this gives error "Server is already active for display 0"
echo 'if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then startx ; fi' >> /home/ubuntu/.bashrc
ls -la /home/ubuntu

exit 0

So, in brief:

  • Trying to mess with .Xauthority will not help here; the failure will be "X: user not authorized to run the X server, aborting."
  • Just pushing startx into .bashrc will not help here; the failure (after a long black screen) will be "Server is already active for display 0"
  • However, startx within an if [ ... ] check will succeed (but I don't understand why would a simple if [] make a difference?)!

In my case, that startx command starts both LXDE and openbox, so both the DE and the WM (how and why, I still don't understand). So all looks good now - except for icons, and that I have no shutdown, suspend, hibernate and reboot options. But at least the immediate problem in my OP is solved. However, I'd still appreciate a more proper description of what goes on here.


Below are some links/quotes which I found useful:

XDM (in full, the X Window Display Manager) is the default display manager for the X Window System. It is a bare-bones X display manager. It was introduced with X11 Release 3 in October 1988, to support the standalone X terminals that were just coming onto the market.

What I don't get is why you want to use xdm when you aren't going to use it? I mean, having xdm auto-login is precisely the opposite of what it was designed to do: Give you a graphical login prompt.

Use runlevel 3 and add 'su - -c startx' to /etc/init.d/rc.local or (if using inittab) change "x:5:respawn:/etc/X11/prefdm -nodaemon" to "x:5:respawn:su - -c startx".

If you create your own /etc/inittab file, Ubuntu will honour it.

To change your runlevels the Ubuntu way look in /etc/init.d/ which contains startup scripts. Then look in /etc/rc#.d/ which contains symlinks to scripts in /etc/init.d/. The name of the symlinks determines what will be started/stopped and in what order.

In bashrc try something like

[ -z "$DISPLAY" ] && startx && {sleep 5; DISPLAY=0:0 setsid Guake; } 

for automatic startx
edit .bash_profile (or other file that gets run when you login) and add

if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then
   startx
fi
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.