关闭UBUNTU图形界面,改为字符界面的相关操作

关闭UBUNTU图形界面,改为字符界面,本文引用7份资料来说明:


Ubuntu 10.04 开机进入控制台的方法  

转载自:http://blog.tianya.cn/blogger/post_read.asp?BlogID=734057&PostID=34170893



1. 关闭gdm 

 Recent version of Ubuntu are using upstart instead of SysV init.
  
   Rename /etc/init/gdm.conf to /etc/init/gdm.disabled

2. 开机自动进入字符界面并自动登录

 /etc/rc.local)
   exec /bin/login -f username

3. 自动运行程序:
 修改~/.profile文件。

 

 




===========================================================================================================

 

补充资料1,以下内容转载自:http://www.cnblogs.com/crazymod/archive/2012/04/10/2441457.html

 
 
ubuntu以及ubuntu类linux系统的运行级别的理解(关闭图形界面)

原创博客,转载注明出处。

 

对于linux,老鸟使用多的还是debian,但是更多的人使用的ubutnu或者ubuntu的衍生版,

如:linuxmint,国产的linuxdeepin等

大部分都是怎么配置显卡驱动以及3D效果等,很少有关闭图形界面的时候。

除非你把系统文件破坏后,不能进入图形界面的除外。。

首先先理解ubuntu的运行级别:

一般的linux的运行级别为6个等级(其中4一般不定义,不过应该也可以):0——6,

     0 Halt the system
    1 Single user mode
    2 Basic  multi user mode
    3 Multi user mode
    5 Multi user mode with GUI
    6 Reboot  the system

以上为一般的linux运行级别,是由init启动的,init为linux内核启动的用户级别进程,

详见网络。

但是ubuntu及其衍生版就不是这样;区别如下:

1、使用upstart代替init启动系统进程。

2、运行级别的改变。

3、其他的

而ubutnu等的运行级别为8种:

0-6   S

0  :关机

1 :单用户mod

2--5:为多用户模式,基本无区别(这与一般的linux不一样,2为默认级别)

6 :重启

S :单用户恢复模式,运行很少进程以及服务

参考:http://book.51cto.com/art/200905/126183.htm

查看运行级别: $runlevel

更改运行级别: telinit  *(0 -6  S)(一般没必要更改为S)

在/etc/rc$.d目录种定义了各种运行级别的运行服务;

要在ubuntu中关闭X服务,x客户端,桌面启动器等进程就行了

那你可以直接终止这些服务就可以了,但是我门要定义的是一开机就进入终端的模式。(ubuntu server版就默认进入终端,那是应为本来就没配置图形X服务)

由于2-5都是大致一样的,在/etc/rc1-5.d目录中找不到桌面启动器的服务,可能老版本的有,我的是ubuntu11.10,

然后在/etc/init/lightgdm.conf中找到了关于启动器的配置,默认是从2-5都是启动X的,那可以修改该配置,使某个运行级别不启动桌面启动即可。(这是linuxmint的配置)ubuntu的应该为gdm的配置。

  

下面的文本是说明ubutnu虽然使用的upstart的,但也遵循intitab的

修改/etc/inittab  (没有的话新建一个,root用户)

id:3:initdefault:

详见:http://space.itpub.net/370491/viewspace-216955
script
    # Check for default runlevel in /etc/inittab
    if [ -r /etc/inittab ]
    then
        eval "$(sed -nre 's/^[^#][^:]*:([0-6sS]):initdefault:.*/DEFAULT_RUNLEVEL="\1";/p' /etc/inittab || true)"
    fi

    # Check kernel command-line for typical arguments
    for ARG in $(cat /proc/cmdline)
    do
        case "${ARG}" in
        -b|emergency)
            # Emergency shell
            [ -n "${FROM_SINGLE_USER_MODE}" ] || sulogin
            ;;
        [0123456sS])

重启就可以进入终端了。

 




 

==================================================================================================================


补充资料2,以下资料引自:www.ubuntu.com

UpstartHowto

Contents

  1. Upstart
    1. Where are initscripts installed?
    2. How are initscripts started and stopped?
    3. What order are initscripts started and stopped in?
    4. How do I find the current/previous runlevel?
    5. How do I change the runlevel?
    6. How do I change the default runlevel?
    7. How do I change the behaviour of Control-Alt-Delete?
    8. How do I enter single-user mode?
    9. How do I reduce the number of gettys?

Upstart

Upstart is a replacement for the traditional sysvinit package, and runs as process #1. Through upstart, we are able to have an event-driven process, whilst at the same time retaining compatibility for the original sysvinit behaviour.

This page documents how to do a few common operations with the new system.

You may want to look at UbuntuBootupHowto, or the Upstart Cookbook for more examples and details of how the Init system is structured in Ubuntu and how to make use of it.

Where are initscripts installed?

This has not changed; they are installed in /etc/init.d. See/etc/init.d/README.

However, most important system jobs are no longer shipped as initscripts, but as upstart jobs. These are installed in/etc/init.

How are initscripts started and stopped?

This has not changed; symlinks are made from the initscript in the/etc/init.d directory to the/etc/rc?.d directories. See/etc/init.d/README and/etc/rc?.d/README.

What order are initscripts started and stopped in?

If a service has not been converted to upstart, this has not changed; the symlinks are namedSNNname orKNNname, whereNN is a number from 00 to 99. The K scripts are run first in numerical order, followed by the S scripts in numerical order.

However, services which have been converted to upstart will define their start criteria in the file, like this:

  • start on runlevel [2345] stop on runlevel [!2345]

This means the service will be started when the system reaches runlevel 2, 3, 4, or 5. It should be noted that it will be started in parallel with every other service that starts on those runlevels, and anything else still starting. The [!2345] in the stop on means it will be stopped whenever a runlevel that is *not* 2, 3, 4, or 5 is reached.

How do I find the current/previous runlevel?

This has not changed; use the "runlevel" command. See runlevel(8).

How do I change the runlevel?

This has not changed, use the "telinit" command or just invoke "init" directly. Seetelinit(8).

How do I change the default runlevel?

If you have an /etc/inittab file, edit it. Locate the following line:

    id:2:initdefault:

Change the number after the first colon to the runlevel you want to be the default.

However, most people won't have that file, in which case you should edit/etc/init/rc-sysinit.conf instead and change the following line:

    env DEFAULT_RUNLEVEL=2

How do I change the behaviour of Control-Alt-Delete?

Edit the /etc/init/control-alt-delete.conf file. The line beginning "exec" is what upstart will run when this key combination is pressed.

To not do anything when Control-Alt-Delete is pressed, you can simply delete this file.

Note that this only affects the behaviour of Control-Alt-Delete when at a text console. In a desktop environment, this key combination is handled by the desktop itself and must be reconfigured there.

How do I enter single-user mode?

This hasn't changed. Choose the "(recovery mode)" option from GRUB; add "-s", "S" or "single" to the kernel command-line; or from a running machine, run "telinit 1" or "shutdown now".

How do I reduce the number of gettys?

Also see "How do I change which runlevels gettys are run in?"

In /etc/init there is a file named ttyN.conf for each getty that will bestarted, where N is numbered 1 to 6. Remove any that you do notwant.

This will not take immediate effect, however you can run "stop ttyN"to stop one that is running.

If your system has Upstart 0.6.7 or later, (first included in Ubuntu 11.04). you will be able to disable the automatic start of these without removing them by running

  • echo manual >> /etc/init/ttyN.conf

UpstartHowto (last edited 2011-03-25 20:20:39 byclint-fewbar)

 

 

 

 


==============================================================================================================

补充资料3,以下内容转载自:http://blog.csdn.net/starlinux/article/details/5781129

Ubuntu 10.04 开机进入控制台的方法


开机后直接进入控制台, 有两种方法可行

方法1. 编辑/boot/grub/grub.cfg文件

sudo chmod 777 /boot/grub/grub.cfg
sudo emacs /boot/grub/grub.cfg

找到类似如下代码:

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.32-21-generic' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod ext2
        set root='(hd0,5)'
        search --no-floppy --fs-uuid --set 0624bfde-9fd7-4a60-ae92-3f43e6efce3d
        linux   /boot/vmlinuz-2.6.32-21-generic root=UUID=0624bfde-9fd7-4a60-ae92-3f43e6efce3d ro   quiet
        initrd  /boot/initrd.img-2.6.32-21-generic
}

在quiet后面加上text,结果应如下所示:

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.32-21-generic' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod ext2
        set root='(hd0,5)'
        search --no-floppy --fs-uuid --set 0624bfde-9fd7-4a60-ae92-3f43e6efce3d
        linux   /boot/vmlinuz-2.6.32-21-generic root=UUID=0624bfde-9fd7-4a60-ae92-3f43e6efce3d ro   quiet text
        initrd  /boot/initrd.img-2.6.32-21-generic
}
sudo chmod 644 /boot/grub/grub.cfg

 

方法2. 修改/etc/init/gdm.conf为gdm.disable

sudo mv /etc/init/gdm.conf gdm.disable

在控制台下进入gdm的使用sudo gdm





===================================================================================================================

补充资料4,以下内容转载自:http://askubuntu.com/questions/76543/how-do-i-disable-gdm-and-graphical-user-selection


How do I disable GDM and Graphical User Selection?

up vote 16 down vote favorite
3

The new Ubuntu features a completely unkillable gdm. Is there a way to disable it?

It is not enabled in services , the gdm startup script is deleted , it is removed from 'update.rc' but it still starts up.

How do I disable GDM and Graphical User Selection?

share improve this question
 
feedback

migrated from serverfault.com Nov 7 '11 at 11:34

8 Answers

ACTIVE OLDEST VOTES
up vote 14 down vote accepted

In Ubuntu 10.4 you should refer to Upstart http://upstart.ubuntu.com/ which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.

Upstart handle start of gdm, so you should edit /etc/init/gdm.conf

# sudo vi /etc/init/gdm.conf

Default runlevel in ubuntu 10.4 is 2 so you must change this line

stop on runlevel [016]

adding "2" at runlevel list

stop on runlevel [0126]

Now you can reboot the system.

share improve this answer
 
feedback
up vote 8 down vote

Do:

sudo dpkg-divert --rename --add /etc/init/gdm.conf

Which prints:

Adding `local diversion of /etc/init/gdm.conf to /etc/init/gdm.conf.distrib'

This will allow you to disable GDM while preventing package upgrades from putting the file back in place andallowing the GDM package to upgrade the configuration file.

In the case of 11.x and above lightdm is used instead of GDM. I instead used the command:

sudo dpkg-divert --rename --add /etc/init/lightdm.conf

To undo it replace the rename and add with a remove.

share improve this answer
 
feedback
up vote 7 down vote

I found this thread to be very helpful: http://newyork.ubuntuforums.org/showthread.php?t=1305659

The solution that I found that worked consistently was post 30 by iscatel

well, this disables sound, as a previous post pointed out, but here goes:

in /etc/default/grub, comment out

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

add

GRUB_CMDLINE_LINUX_DEFAULT="text"

then

sudo update-grub2

this will pass "text" on the kernel line, disabling gdm.

share improve this answer
 
Just tried, worked great for me. Thanks. –  Adam Backstrom  Jun 24 '10 at 21:13
feedback
up vote 7 down vote

Recent versions of Ubuntu are using upstart instead of SysV init.

Rename /etc/init/gdm.conf to /etc/init/gdm.disabled.

For Kubuntu, rename /etc/init/kdm.conf to /etc/init/kdm.disabled.

share improve this answer
 
feedback
up vote 3 down vote

Follow the directions of @freedev:

# sudo nano /etc/init/gdm.conf

And change to:

stop on runlevel [0126]

Also

# sudo nano /etc/init/tty1.conf

And change to:

stop on runlevel [!345]

Note the missing 2 in the tty1.conf. This is so that you get tty1 up and running and can log on into the first console. No need to mess with grub.

share improve this answer
 
This isn't a threaded forum, so your instruction to "follow the directions above" don't really make sense. Can you please edit your answer to be more comprehensive? –  Holocryptic  May 8 '11 at 5:22
 
@lucian303 stop on runlevel [!345] Didn't get this portion My tty1.conf file contains: start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] if i change from "stop on runlevel [!2345]" to "stop on runlevel [!345]" Then both the start on and stop on lines will mean the same. Please explain –  Pradipto  Sep 15 '11 at 8:13
feedback
up vote 1 down vote

You can switch to some other display manager (kdm or xdm being two most widespread alternatives, but there are many more, see Wikipedia). Just aptitude install the one you want to use, run dpkg-reconfigure gdm and select it from the list.

share improve this answer
 
feedback
up vote 1 down vote

Why not just remove it?

apt-get remove gdm
share improve this answer
 
feedback
up vote 0 down vote

For those who arrive on this topic, follow the instructions of freedev, but instead of stop gdm on run level 2, you should prevent it from starting on runlevel 2 :

Edit /etc/init/gdm.conf

$ sudo vi /etc/init/gdm.conf

Change this line

and runlevel [!06]

By this line

and runlevel [!026]

You can also exclude others run level (3, 4 and 5)









































































































































































=========================================================================================================

补充资料5,以下内容转载自:http://linux.koolsolutions.com/2009/07/24/tip-disable-gdm-kdm-or-xdm-from-starting-up-automatically/


Disable GDM, KDM or XDM from starting up automatically

in Tips, X Windows

Here is a quick tip to disable your login manager like GDM, KDM or XDM from starting up automatically upon system boot. Many times you need to boot your Linux system just to a console based mode and ideally you would like to start the X server (Graphics/Login manager) only when you need it.

Disable login/graphics manager

To disable the login manager on your Debian/Ubuntu system (which in turns prevents X server to start automatically) give the following command:

# update-rc.d -f gdm remove

Now next time when you reboot your system, it will just to a plain console mode and now if you want to start your graphics manager all you need to do is simply give the following command as root depending on the type of login manager that you have:

# /etc/init.d/gdm start

or

# /etc/init.d/kdm start

or

# /etc/init.d/xdm start

To switch back to console mode from graphics mode hit:

Ctrl+Alt+F1

and now to switch back to graphics mode hit:

Ctrl+Alt+F7

Enable/Restore login manager


Let’s say you want to restore your system just like it was before i.e. Linux will boot into graphics mode automatically as it normally does. To do that give the following command:

# update-rc.d gdm defaults

That’s it. Now when you reboot your system next time it will start one of your login manager.

Happy consoling!!!

Be Sociable, Share!




========================================================================================================

补充资料6,以下内容转载自:http://www.cyberciti.biz/faq/prevent-xorg-from-starting-in-linux/


Ubuntu Linux stop / disable GNOME GUI ~ X.org

by VIVEK GITE on SEPTEMBER 7, 2007 · 20 COMMENTS· last updated at SEPTEMBER 7, 2007

Q. I don’t need GUI as I’m developing CLI based applications. By default Ubuntu Loads Gnome GUI. How do I disable X.org / Gnome under Linux so that I get text only login?

A. You can use GUI tools or command line tools to disable GDM (Gnome Display Manager) service (/etc/init.d/gdm).

Disable GDM using GUI tools

The Services Administration Tool allows you to specify which services will be started during the system boot process. You can type the command:
services-admin &

Or just click on System > Administration > Services

Now you will be prompted for the administrator password, this is necessary because the changes done with this tool will affect the whole system. After entering the administrator password, the following window is displayed:

关闭UBUNTU图形界面,改为字符界面的相关操作_第1张图片

Make sure you remove GDM (Gnome login manager) by disabling the the checkbox and close the window.

Enable GDM using Command Line (CLI) tools

Ubuntu comes with rcconf and update-rc.d command. rcconf allows you to control which services are started when the system boots up or reboots. It displays a menu of all the services which could be started at boot. The ones that are configured to do so are marked and you can toggle individual services on and off.

Install rcconf

Use apt-get command:
sudo apt-get install rcconf
Now start rcconf:
sudo rcconf
Again you will be prompted for the administrator password, this is necessary because the changes done with this tool will affect the whole system. After entering the administrator password, the following text based window is displayed on screen:
关闭UBUNTU图形界面,改为字符界面的相关操作_第2张图片

Next enable GDM service by pressing space bar (check the checkbox) > Click OK to save the changes.

update-rc.d command

This is 3rd and old method. You can enable or disable any service using update-rc.d command.

Task: Disable X.org GUI

Just enter command:
sudo update-rc.d -f gdm remove

Task: Enable X.org GUI

Just enter command:
sudo update-rc.d -f gdm defaults

You can always start GUI from a shell prompt by typing startx command:
startx &

Please note that you can use above tools to enable or disable any services under Debian / Ubuntu Linux.

See also:

  • update-rc.d / rcconf like command on Redhat Enterprise / CentOS / Fedora Linux to enable & disable SysV services


You should follow me on twitter here or grab rss feed to keep track of new changes.

{ 20 comments… read them below or add one }

Bryce Harrington  March 31, 2008 at 11:11 pm

This command should not be used by users to disable gdm:

sudo update-rc.d -f gdm remove

While it may seem to work, that’s just a side effect. This is a packager’s tool, not an administration tool.

A better approach (recommended to me by slangasek, the Ubuntu release manager) is:

mv /etc/rc2.d/S30gdm /etc/rc2.d/disabled-S30gdm
mv /etc/rc2.d/K30gdm /etc/rc2.d/disabled-K30gdm

REPLY

erkko  January 12, 2009 at 5:27 pm

I shall second to Bryce. And to add insult to injury: when trying to temporarily suspend some services this way, on might end up with pretty screwed system.
sudo update-rc.d -f gdm remove — this removes all links to /etc/init.d/gdm and if you did not pay attention to their original sequence numbers… try to remove gdm this way and restore it afterwards. default restore method, you suggested, will use sequence number 20 for start and kill, original for ubuntu gdm is btw 30 for start and 01 for kill.

And because disabling gdm by itself really is not enough, one has to disable usplash also. When you use this same-old default remove -command and later on wanna restore gdm & usplash, you’ll end up with both of them started at the same sequence and this also means no mouse/keyboard while sitting at gdmgreeter login…

Nice enough?

commands for restoring such systems original condition would be:

update-rc.d -f gdm remove
update-rc.d -f usplash remove
update-rc.d -f gdm defaults 30 01
update-rc.d -f usplash defaults 98 02

use sudo, if need be.

REPLY

rkaneknight  March 2, 2009 at 6:13 pm

I’ve had a horrible time removing the GUI from Ubuntu 8 Maybe I have the wrong version, but I finally ran into this site, and installed and ran rcconf and removed gdm and a few other things related to X and some other stuff I didn’t think I needed. I’m running this as a VM so the last thing I need is a bulky GUI slowing things down. waiting for reboot… Woot, finally a regular login prompt. A couple errors came on the screen, but I don’t care, as long as I don’t have a GUI taking away my ram.

REPLY

SaltwaterC  April 21, 2009 at 9:13 am

sudo apt-get install sysv-rc-conf ; sudo sysv-rc-conf

rcconf looks like an unfinished product besides sysv-rc-conf.

REPLY

ASaavedra  November 11, 2009 at 10:18 pm

SaltwaterC: sysv-rc-conf is such a great tool, thanks for the tip! A. Saavedra

REPLY

Junaid  October 18, 2010 at 2:56 pm

Hi… Is there anyway I can just access a command prompt line like in Windows? And still be on the gui/gdm?

REPLY

ASaavedra  October 18, 2010 at 4:03 pm

Junaid, you mean a console terminal? If using GNome simply go to Applications > Accesories > Terminal

REPLY

Junaid  October 19, 2010 at 12:35 pm

Thanks… You’re a real blessing. I’m new to this stuff.

REPLY

phil  February 12, 2011 at 10:09 pm

lol linux people pwned with terminals long before Windows people did.

REPLY

mate  May 19, 2011 at 10:40 pm

I have used the command as stated above (update-rc.d -f remove/defaults) with great success. I have not used it in Ubuntu 11.4 yet?
Sometimes people have problem with display drivers or what have you and need Not to get on the GUI until they’ve solved the problem. So this is a great tool in fact once I made a little script out of it.

REPLY

Zaid  August 10, 2011 at 7:31 am

Rename gdm.conf to gdm.disabled

file location: etc/init

REPLY

HansBKK  August 29, 2011 at 6:52 am

Zaid is DA MAN!!

only thing that worked on Natty 11.04

hope I didn’t screw up my system trying all the other stuff I found.

startx gets you in manually once you’ve logged in to that beautiful black and white console

REPLY

adam  November 25, 2011 at 1:35 pm

Thanks, that i was looking for too. Only this working in 11.10

REPLY

Aditya  February 13, 2012 at 6:08 pm

The thing that worked for me. Running Ubuntu 10.10.

REPLY

todd  February 14, 2012 at 1:47 pm

Ah, but if you receive updates to your system, then updates to GDM may very well install a new gdm.conf, causing your system to boot into X Windows again.

On the other hand, if you create a gdm.override file and put the word manual in it, then it won’t matter if gdm.conf is ever updated, or recreated, the override will still be effective in preventing X from starting.

REPLY

kurinchilion  October 29, 2011 at 10:17 pm

good & detailed post

REPLY

johnv474  December 15, 2011 at 10:09 pm

Is it just me, or does this page display with a huge ad (usually for Cisco) covering much of the content? So far as I see, there is no way to close the ad.

… among the most annoying website traits, just after sites with talking ads.

REPLY

todd  January 13, 2012 at 1:29 pm

I realize this post is a couple years old, but it still shows up at the top of the search results in Google, so I suppose it’s worth having accurate information.

In the current release of Ubuntu upstart is used in place of init, so one should edit the files in /etc/init and notmodify any rc scripts (i.e. sysv-rc-conf, rcconf, update-rc are all no-no’s). I can’t speak to previous releases of Ubuntu, so I don’t mean to suggest the original article is incorrect.

Rather than renaming /etc/init/lightdm.conf (or gdm.conf, kdm.conf, etc, as the case may be) you should create /etc/init/lightdm.override and put in it one line with just the word

manual

(without the quotes) – this will prevent upstart from starting the job automatically, and will allow it only to be started manually (hence the “manual” keyword). You should also remove the

quiet

,

splash

and

vt.handoff=7

kernel parameters from your GRUB configuration – to do so, edit /etc/default/grub, change

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

to

GRUB_CMDLINE_LINUX_DEFAULT=""

and run /usr/sbin/update-grub.

Ubuntu boots into runlevel 2 by default, so in my system I’ve got it setup so that X does not start in runlevel 2, but will in runlevel 3, 4 and 5 (which used to be the case in the days of old) – if you want to take that approach, change your /etc/init/lightdm.override file to:

start on (filesystem
and runlevel [!026]
and started dbus
and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
or stopped udev-fallback-graphics)

stop on runlevel [0126]

REPLY

todd  January 13, 2012 at 1:32 pm

Let me fix some formatting…

In the current release of Ubuntu upstart is used in place of init, so one should edit the files in /etc/init and notmodify any rc scripts (i.e. sysv-rc-conf, rcconf, update-rc are all no-no’s). I can’t speak to previous releases of Ubuntu, so I don’t mean to suggest the original article is incorrect.

Rather than renaming /etc/init/lightdm.conf (or gdm.conf, kdm.conf, etc, as the case may be) you should create /etc/init/lightdm.override and put in it one line with just the word manual – this will prevent upstart from starting the job automatically, and will allow it only to be started manually (hence the “manual” keyword). You should also remove the quietsplash and vt.handoff=7 kernel parameters from your GRUB configuration – to do so, edit /etc/default/grub, change GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” toGRUB_CMDLINE_LINUX_DEFAULT=”" and run /usr/sbin/update-grub.

Ubuntu boots into runlevel 2 by default, so in my system I’ve got it setup so that X does not start in runlevel 2, but will in runlevel 3, 4 and 5 (which used to be the case in the days of old) – if you want to take that approach, change your /etc/init/lightdm.override file to:

start on (filesystem
              and runlevel [!026]
              and started dbus
              and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
                      or stopped udev-fallback-graphics)
stop on runlevel [0126]

REPLY







你可能感兴趣的:(ubuntu,图形)