[Share] Implement automatic login and run your own graphics program under ubuntu9.10

Source: Internet
Author: User
Tags diff uuid

Automatic login under ubuntu9.10
and run your own graphical interface program
(I have not been in touch with Ubuntu for a long time, some of the text will inevitably have errors and omissions, but also please do not hesitate to criticize. )
The implementation steps are divided into three major strides:
1, the implementation of Ubuntu text form start
2. Automatic login for Ubuntu
3. Implement automatic operation of program

First, text mode start:
The two approaches are similar:
(1) Modify/etc/grub/grub.cfg directly
Find code similar to the following:
Linux/boot/vmlinuz-2.6.31-14-generic root=uuid=0f31592d-e741-42d7-b577-8b0931f965f4 ro Quiet Splash
A text behind the splash, modified as follows:
Linux/boot/vmlinuz-2.6.31-14-generic root=uuid=0f31592d-e741-42d7-b577-8b0931f965f4 ro Quiet Splash text
As I experimented with the virtual machine, the default text mode resolution was 640x480, so the resolution was turned up, with the following sentence: var=791 the resolution to 1024x768. There is the splash changed to Nosplash, this is because splash after, sometimes stuck, do not know what reason, so simply don't let it splash screen, (also please know the reason of the warrior to give a touch) the final modification as follows:
Linux/boot/vmlinuz-2.6.31-14-generic root=uuid=0f31592d-e741-42d7-b577-8b0931f965f4 ro quiet nosplash text vga=791
(2) Modify/etc/default/grub
Find the following code:
grub_cmdline_linux_default= "Quiet Splash"
Modify it to:
grub_cmdline_linux_default= "Quiet nosplash text"
Update Grub:
$update-grub
So far, we've implemented the start in text mode. There is not a bit to understand, that is, when I use RunLevel to view the time, the results will appear:
N 2
If you run $init 2 again, then $runlevel, the results are as follows:
2 2
I don't know if this will have any effect. Pending further experimentation ...
Second, the realization of Ubuntu automatic login.
To achieve this, two files need to be modified, one is Getty and the other is login.
As for the functions of these two files, I have not fully understood, read some of the introduction on the Internet, a simple excerpt is as follows:
1) Gettty main realization of the following functions: (Impatient friends can skip this paragraph directly)
Opens the specified TTY (specified by the parameter);
Prompt user Login (login:);
Get login user name;
Call/bin/login as a parameter to the user login name.
2) Login main to achieve the following functions: (Impatient friends can skip this paragraph directly)
Login first check whether the login is Superuser, if it is not superuser, and there is a/etc/nologin file, then output the contents of the file, and abort the login process, mainly by checknologin () implementation;
If the logged-on user is a superuser, login must implement the login in the TTY list specified in/etc/securetty/, or the login will fail. You can also not specify the/etc/securetty file, at which point the superuser can log on to any TTY.
After the first two steps of testing, login will then prompt for a login password (by Getpass () call completion, interested readers can refer to their manual page), and verify that if the password is incorrect, then prompt to log in again.
After a successful password verification, login will also check for the presence of a. hushlogin file, and if the file exists, perform a "quiet" login (the so-called quiet login means that mail mail is no longer prompted at logon, no longer displays the last logon time, and no messages are output. Start level is 3 o'clock, this information is normally output)
Login Next sets the user ID and group ID of the login TTY and sets the appropriate environment variables, including home, PATH, SHELL, term, logname, and so on. For normal users, path is set to/usr/local/bin:/bin/usr/bin:; for Superuser, Path is set to/sbin:/bin:/usr/sbin:/usr/bin:
The final step of login is to start the shell for the user. If the shell is not specified for the user in/etc/passwd, then/bin/sh is used and "/" is used if the current working directory is not given in/etc/passwd.

At this point, a complete login process is over.
From the above process we are not difficult to conclude, in order to achieve automatic login, we can not let Getty prompt to enter the user name, when calling login, do not let login require password input.

To modify these two files, you first need to get their source code. We can do this in the following steps:
(Note 1: The following six steps are excerpted from: http://blog.csdn.net/gothicane/archive/2007/08/17/1747956.aspx)
(Note 2: The original author is implemented on the 6.10, the package version number will be different, but the change is not big, I will be marked in the place of change)
(1) Find the Deb package that the command belongs to.
$ dpkg-s Getty
Util-linux:/usr/share/doc/util-linux/readme.modems-with-getty.gz
Util-linux:/usr/share/man/man8/getty.8.gz
Util-linux:/sbin/getty
Util-linux:/usr/share/doc/util-linux/readme.getty.gz
By the above input, we can guess that the Getty command is provided by the Deb package named Util-linux.

(2) Download the Deb package source code
$ sudo apt-get source Util-linux
In the current directory can get Util-linux source package, there are the following files:
Util-linux_2.12r-11ubuntu2.diff.gz
Util-linux_2.12r-11ubuntu2.dsc
Util-linux_2.12r.orig.tar.gz
util-linux-2.12r
The source code is in the UTIL-LINUX-2.12R folder.
(Note: In 9.10, this package is updated to version 2.16, showing the following results:
Util-linux_2.16-1ubuntu5.diff.gz
Util-linux_2.16-1ubuntu5.dsc
Util-linux_2.16.orig.tar.gz
util-linux-2.16

The source code for the Getty command and the login command is under the util-linux-2.12r/login-utils/folder.
Note that this is in the article "How to automatically log in to Linux" in the difference is that there is no need to download two source RPM package, and two command source code is here. Where the source code for the Getty command can be login.c for the Agetty.c,login command.
Getty is a program that allows you to log on from a variety of devices, such as a virtual terminal, a text terminal, or a modem. He displays a login prompt, once you type the user name, Getty sends it to Login,login will ask you for the password, after the authentication is successful, give you a shell. There are many Getty, and some distributions, including Red Hat, use a small, mingetty that can only be used on virtual terminals. The login program is part of the Linux Feature Pack and contains a Getty named Agetty.

(3) Modify the source code of the Getty Command
Getty's features typically include:
Open the terminal line and set the mode, output the login interface and prompt, accept the user name input, the login program is loaded with the user name as the login parameter, and the default login prompt is recorded in the/etc/issue file.
In the source code of AGETTY.C, line No. 366 and line 367 can be seen: (Note: In the 2.16 version, the line number is changed, but you can find the two lines by searching, line numbers 345 and 346.) )
366 while ((logname = Get_logname (&options, &chardata, &termio)) = = 0)
367 Next_speed (&termio, &options);
Here called Get_logname to get user input user name, Get_logname in 1014 lines called the Do_prompt function, output the login prompt, similar to "Login:". Here, we put 366 and 367 lines of comments, the direct assignment logname to root: (Note: In the 2.16 version, the line number is changed, but can be found by searching the two lines, line number 345 and 346. )
366//while ((logname = Get_logname (&options, &chardata, &termio)) = = 0)
367//Next_speed (&termio, &options);
368 logname = "root";

(4) Modify source Login command's source code
The login program runs in the same process space as the Getty, accepting the username parameter from Getty as the login user name.
In the source code of LOGIN.C, line No. 407: (Note: In version 2.16, the line number is changed, but you can find this line by searching:/passwd_req. Line number 425. )
407 Passwd_req = 1;
Through the analysis of the source code, here is a switch where the password needs to be verified. We modify here to turn off the switch that the password needs to be verified directly:
407//passwd_req = 1;
408 passwd_req = 0;
(Note: In version 2.16, the following four lines are also commented out:
610 if (Fflag && (getuid () = = 0))
611 Passwd_req = 0;
612 Else
613 passwd_req = 1;
After the comments are complete:
610/if (Fflag && (getuid () = = 0))
611//passwd_req = 0;
612//Else
613//passwd_req = 1;

(5) Compile and build the executable file
Directly using the makefile file in the util-linux-2.12r/login-utils/directory to compile, directly play make command, after compiling, you can get the executable file: Agetty and login.
(Note: In version 2.16, you need to run the./configure, and the default configure file does not compile the login file, and you need to modify the Configure.) Vim Open Configure file:
$vim Configure
Search for the following statement:
:/Enable_login_utils
Found in line 15796
15796 Enable_login_utils=no
Modify it to:
15796enable_login_utils = yes
Save exit:
: Wq
Run the Configure file:
$./configure
The following error occurred:
Configure:error:ncurses or NCURSESW selected, but the library not found (--without-ncurses to disable) we add Parameters--without-ncurse S
New execution./configure, success.
Enter the Login_util directory to compile:
$CD Login_util
$make
This results in the Agetty and login files

The following system is the original Getty and Login executable file. Find the location of the file, and back up, the new executable file into the appropriate directory, the Agetty renamed.
$ Whereis Login
Login:/bin/login/etc/login.defs/usr/share/man/man1/login.1.gz
$ sudo cp/bin/login/bin/login.bak
$ sudo cp login/bin/
$ whereis Getty
Getty:/sbin/getty/usr/share/man/man8/getty.8.gz
$ sudo cp/sbin/getty/sbin/getty.bak
$ sudo cp agetty/sbin/
$ sudo mv/sbin/agetty/sbin/getty
At this last step, you can also create a soft link named Getty to Agetty.
$ sudo ln-s/sbin/agetty/sbin/getty

(6) Rebooting the system
After the boot information is displayed, the system will go directly to the root user login state and a prompt similar to the following appears:
[Email protected]:~#
This means that we have successfully automatically logged into the Ubuntu system.

Third, the realization of automatic operation of the program
Implementing the program Autorun can add the command that will be run to the last of the/etc/profile file
Here's a first way to do this: (Not good)
Because Ubuntu from the text mode login, to run the graphical interface program, need Xwindow support (here is not necessarily right, I am based on their own understanding of writing, the wrong support please the hero, in order to avoid misleading), so to run Xinit, and then run our own program. So you need to add the following line to the/etc/profile last:
Xinit Mybinfile
This can achieve automatic operation, but there is a big flaw, is the automatic login after the Xinit window first appeared, about a second later, their own program will bounce out, the middle of the poor cohesion.
Later guided by eexpress (in this serious thank eexpress!! ), modify the method as follows:
(1) in the ~ directory, create a new. xinitrc file, and write a sentence in it:
EXEC mybinfile
(2) Add a sentence at the end of the/etc/profile file:
StartX

So far, automatic login is done.

Iv. problems that are still present:
1, the program does not have a mouse after running.
2, enter the program with the input box the mouse will appear a mouse pointer, but a "X" line of the symbol, do not know how to make it appear as arrows.
3, the splash screen is not stable, sometimes out sometimes.

[Share] Implement automatic login and run your own graphics program under ubuntu9.10

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.