Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

Like this article? We recommend

Exploring the Startup of the X Window System

Each distribution has a slightly different startup sequence, and your startup sequence will also be different if you use another window manager. These sequences also tend to change from version to version of a distribution. Obviously, trying to document all of the possible startup sequences would take us quite a while and make for rather boring reading.

Understanding why all these scripts are run will help you understand the startup sequence for any distribution. Learning a little shell scripting won't hurt, either. Let's go through the startup sequence from an explorer's point of view.

inittab

Startup of the X Window System will almost always start with /etc/inittab, if you've configured a graphical login. inittab is init's configuration file, and init is about the first thing to run during Linux startup. It is process no. 1 and is the ultimate parent of every other process in the system.

One of the few things that has standardized among Linux startup sequences is the definitions of run levels. Run level 5 is a graphical login. So, if you want the X Window System to automatically start on bootup, you need to set your default run level to 5.

Starting at the beginning of our exploration, we should verify the default run level by looking for the following line in /etc/inittab:

id:5:initdefault:

This tells us that the default run level is, in fact, 5. The other likely setting is 3, which is full multiuser mode.

Now that we know the starting run level, let's determine what processes init will run (this example happens to be a Red Hat system):

$ grep 5 /etc/inittab
#   5 - X11
id:5:initdefault:
l5:5:wait:/etc/rc.d/rc 5
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon

The id line indicates the default run level. The l5 line is what kicks off all the /etc/rc.d/rc5.d scripts. We'll get back to these in a moment. The pr line is for when power is restored after a power failure, so we don't really care about that. All those mingetty lines represent the virtual consoles that you get when pressing Ctrl+Alt+F#, so we're not interested in those, either.

Finally, that x line is exactly what we're looking for. Don't assume that the x itself means anything. Remember that in OpenLinux, this line was labeled gu. The first field is just a name that the distribution gave to this rule. What we're looking for generally is something that kicks off a display manager (xdm, gdm, kdm). This version of Red Hat uses /etc/X11/prefdm. We'll investigate prefdm in a moment, but for now, notice that this rule is fired when we enter run level 5 and that, if prefdm ever dies, init will restart it (that's what respawn means). The -nodaemon parameter indicates that prefdm should not put itself into the background. This is how programs run by init should work because init handles backgrounding them.

Sometimes it's not as easy as looking for "dm" in the name. OpenLinux runs a script called rc.gui, which then runs kdm. Generally, the line we're interested in is near the bottom, though, and should be fairly obvious (once you know what you're looking for).

You might discover that nothing in inittab seems to start a display manager. In this case, you should look at the rc scripts, which are usually stored in /etc/rc.d/rc#.d or /etc/rc#.d, where # is the run level. In the case of Debian, you'll find an rc script called xdm. This is the script that starts the display manager. A quick look inside this script will show us this line:

DAEMON=/usr/bin/X11/xdm

This is the display manager that Debian will start.

The Display Manager

init's ultimate goal with run level 5 is to get a display manager started. Whether it does it directly (by calling xdm, for instance) or through a script (such as rc.gui), eventually a display manager should be started.

In the previous example, we saw that Red Hat uses prefdm. In older version of Red Hat, this was a symbolic link to the desired display manager. In newer versions of Red Hat, this is a script (similar to OpenLinux's rc.gui).

There are three common display managers: xdm, kdm, and gdm.

xdm

xdm is the oldest display manager. Most distributions store the xdm configuration files in /etc/X11/xdm. If the configuration files aren't here, try this:

locate xdm-config

As an explorer, our next point is xdm-config (if we've determined that this system uses xdm). There is a lot of interesting information in this file, but here are the most important lines:

DisplayManager.errorLogFile:    /var/log/xdm-error.log
DisplayManager._0.setup:        /etc/X11/xdm/Xsetup_0
DisplayManager*session:         /etc/X11/xdm/Xsession

The first line, errorLogFile, determines where xdm will output error messages. This is very important when trying to troubleshoot problems with xdm. Most distributions seem to be standardizing on /var/log/xdm-error.log.

The second line, _0.setup, determines what script xdm will run before providing a login prompt. This script generally does things like provide an attractive background and perhaps a console window. The _0 indicates that this configuration entry is for the primary display. On machines with multiple displays, you might have a _1.setup line as well, but this is very rare. Unless you are debugging problems with xdm itself, it is unlikely that you will need to investigate this script.

The third line, session, is probably the most important. This is the script that is run once a user logs in. This is also where different distributions start to diverge the most. We'll investigate Xsession more later.

kdm

As we've mentioned already, kdm is the KDE Display Manager and is almost identical to xdm in configuration. In fact, kdm is based directly on xdm's source code. kdm provides some nice features, such as "faces" (which show available user IDs on the system as small pictures), multilingual support, and a more configurable appearance. All of these advanced configuration options are managed by the Control Center under System, Login Manager.

Because kdm uses xdm's configuration files, it also calls /etc/X11/xdm/Xsession when a user logs in.

gdm

gdm is the GNOME display manager and is a complete rewrite of xdm, although it generally implements the same functions (as well as the added features of kdm).

The primary gdm configuration file is /etc/X11/gdm/gdm.conf. This location is fairly standard, but if you cannot find gdm.conf here, try this:

locate gdm.conf

gdm configuration is actually somewhat complicated, but the following lines from gdm.conf should point you in the right direction to understand the startup sequence:

LogDir=/var/gdm
DisplayInitDir=/etc/X11/gdm/Init
PreSessionScriptDir=/etc/X11/gdm/PreSession
SessionDir=/etc/X11/gdm/Sessions/
PostSessionScriptDir=/etc/X11/gdm/PostSession/

Notice that most of the variables end with "Dir" and point to directories rather than files. This is because gdm allows extremely configurable session types. A session is the sequence of events between when a user logs in and when that user logs out. Each session type has a name and is selected with the Session menu on the login screen of gdm. If no session type is selected, then Default is used (this is also what is used if no special rules exist for a particular session type). So, for example, if you have chosen the GNOME session, gdm will first look for the script /etc/X11/gdm/PreSession/GNOME and then look for /etc/X11/gdm/PreSession/Default.

The LogDir variable indicates the directory where gdm stores all of its logs. This is very important if you are debugging a problem with gdm.

The DisplayInitDir variable indicates where to look for scripts to run before presenting the user a login prompt. This is the same function as the Xsetup_0 file for xdm. In fact, /etc/X11/gdm/Init/Default is often symbolically linked to /etc/X11/xdm/Xsetup_0. Although gdm is incredibly flexible in what it allows to be done, you will find that most distributions just have it point back to what xdm does.

The PreSessionScriptDir variable indicates where to look for scripts to run after the user has logged in but while the system is still running as root. This generally points back to /etc/X11/xdm/GiveConsole, where the user is given ownership of the console.

The SessionDir variable indicates where to look for scripts to run as the user. This generally points back to /etc/X11/xdm/Xsession. Almost all display manager configurations eventually get back to Xsession, which we'll cover next.

The PostSessionScriptDir variable indicates where to look for scripts to run after the user has logged out and once gdm is running as root again. This generally points back to /etc/X11/xdm/TakeConsole, which gives the console back to root.

Xsession

After the user has logged in, most distributions will run /etc/X11/xdm/Xsession. Although most distributions call this file the same thing, they tend to differ wildly about what it does. The only way to know is to actually read it.

In general, Xsession is going to do the following things:

  • Redirect output to ${HOME}/.xsession-errors—Most distributions agree on this location, and it is an important source of information for debugging all kinds of problems. This file will catch the output of any application that doesn't have a controlling terminal, so it is a good place to look for output from applications that you launch via KDE or GNOME's panel or in other ways that don't use a terminal.

  • Load resources—Many older applications in the X Window System are configured with resources. Resources are configuration options stored in memory by the X Window System and are queried by various applications. Xsession generally includes a mechanism for loading user-specific resources from a file such as ${HOME}/.Xresources. Another common name is ${HOME}/.Xdefaults. To verify the actual name, look for parts of Xsession that call xrdb.

  • Run user-defined script—Generally, the user is allowed to create her own startup scripts. Some distributions will run ${HOME}/.xsession, if it is found. If not, they may try ${HOME}/.Xclients or even ${HOME}/.xinitrc. Which user-defined scripts Xsession will honor is somewhat distribution-specific, and you should check Xsession itself to be sure. Some distributions will also skip this step if the user requested a specific session via kdm or gdm. In that case, Xsession may just run the desktop or window manager directly.

  • Run Xclients—The final fallback is almost always /etc/X11/xinit/Xclients. This script generally figures out what desktop or window manager the user wants (sometimes by querying distribution-specific configuration files) and starts it.

Desktop or Window Manager Startup

The last startup step is generally an "exec" command that starts a desktop (KDE or GNOME, for example) or a window manager (fvwm2 or Blackbox, for example). The "exec" instructs the script to remove itself from memory before launching the desired environment. This not only saves memory, but it also ensures that the rest of the script won't be accidentally executed when the user logs out.

KDE starts with a script called startkde. This script launches the various servers that KDE needs for interprocess communication. It also starts the window manager, the KDE panel, and other useful applications.

GNOME starts with a script called gnome-session. This script does essentially the same things as startkde.

Window managers are generally started by simply running the window manager's executable.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020