PC Operating System: Difference between revisions

From Free Geek Seattle
No edit summary
Line 176: Line 176:
==Structure==
==Structure==


===Kernel===
===Kernel vs Userland===
The OS is centered around a program called the "kernel". Linux is a kernel, as is GNU Mach. Mac OS uses a FreeBSD kernel.  
The OS is centered around a program called the "kernel". Linux is a kernel, as is GNU Mach. Mac OS uses a FreeBSD kernel.  
The kernel controls the computer's hardware- device drivers need some means by which to "hook" into the kernel. The Linux kernel is modular, so device drivers (and other functions) can be dynamically added as modules to the kernel while it runs.
The kernel controls the computer's hardware- device drivers need some means by which to "hook" into the kernel. The Linux kernel is modular, so device drivers (and other functions) can be dynamically added as modules to the kernel while it runs.
The kernel also manages the computer's memory. Memory is divided between "kernel space" and "user space" aka userland. Kernel space is memory reserved by the kernel for its own use, user space is that available for other programs' use.
The kernel also manages the computer's memory. Memory is divided between "kernel space" and "user space" aka userland. Kernel space is memory reserved by the kernel for its own use, user space is that available for other programs' use.
===Userland===
 
''Userland'' or ''user space'' is where everything happens that isn't directly part of the kernel. Most importantly, application programs run by users run in user space.
''Userland'' or ''user space'' is where everything happens that isn't directly part of the kernel. Most importantly, application programs run by users run in user space.
====Processes====
===Processes===
Every running program consists of one or more processes. Each process has a UID and a "nice" value. Nice determines the priority of the process. Lower numbers equal higher priority (they are less nice). Nice has range 32 to -32.
Every running program consists of one or more processes. Each process has a UID and a "nice" value. Nice determines the priority of the process. Lower numbers equal higher priority (they are less nice). Nice has range 32 to -32.
Priority means the amount of processor "ticks" or timeslices init gives to the process. Every processor has some number of timeslices available per unit time. More timeslices means the process runs faster.
Priority means the amount of processor "ticks" or timeslices init gives to the process. Every processor has some number of timeslices available per unit time. More timeslices means the process runs faster.
Processes live in a [[tree]]. This means that every process (except init) has a parent and may have one or more children.
Processes live in a [[tree]]. This means that every process (except init) has a parent and may have one or more children.
=====init=====
====init====
Init is the parent of all processes, with UID 0. Init is started by the kernel during boot.
Init is the parent of all processes, with UID 0. Init is started by the kernel during boot.
Init then starts all the necessary [[daemons]] according to its configuration.
Init then starts all the necessary [[daemons]] according to its configuration.
There are a few different ways of configuring init.
There are a few different ways of configuring init.
======Upstart======
=====Upstart=====
Upstart is a 'new, improved' version of init that handles dependencies (that is, some services need to start before others do, and upstart tracks this) among other things. Upstart introduces a new interface in the '''service''' program. Not all services support this yet as of 20130920.
Upstart is a 'new, improved' version of init that handles dependencies (that is, some services need to start before others do, and upstart tracks this) among other things. Upstart introduces a new interface in the '''service''' program. Not all services support this yet as of 20130920.
======SysV init======
=====SysV init=====
SysV init is the init version most often used by Linux distributions. It is the standard init used by Debian (and therefore Ubuntu). SysV init supports the scripting interface at /etc/init.d/ for controlling services. It also supports '''runlevels''', which are increasing levels of complexity the system can handle as it boots. This allows for graceful degradation in case of problems (or administrative decision- lower runlevels are useful for troubleshooting.)
SysV init is the init version most often used by Linux distributions. It is the standard init used by Debian (and therefore Ubuntu). SysV init supports the scripting interface at /etc/init.d/ for controlling services. It also supports '''runlevels''', which are increasing levels of complexity the system can handle as it boots. This allows for graceful degradation in case of problems (or administrative decision- lower runlevels are useful for troubleshooting.)
0 - Halt
0 - Halt
Line 201: Line 201:
5 - Graphics layer
5 - Graphics layer
6 - Reboot
6 - Reboot
======BSD init======
=====BSD init=====
BSD init is a simpler implementation of init with a 'flatter' configuration. Runlevels are optional.
BSD init is a simpler implementation of init with a 'flatter' configuration. Runlevels are optional.

Revision as of 22:31, 19 September 2013


Installation

This section covers installation of Ubuntu Linux. There is a lot of 'optional' information here that need not be covered in a basic class, but might be useful for reference or for answering students' questions.

These optional parts will look like this.

Preparing to install

Requirements for installing Ubuntu are pretty basic. First you need to ensure that the machine meets Ubuntu's hardware requirements. You need to know if it's a 32-bit or 64-bit machine (note that 64-bit systems work with 32-bit software, but the reverse is not true.)

If it's strange (for example, a CPU other than an Intel or AMD unit) then you need to know which Ubuntu edition to use.

The computer will also need an optical drive (for reading CD or DVD) or ports (like USB, Firewire, or serial / parallel ports) for attaching external drives, along with the ability to boot from those drives (configured in the BIOS setup screen).

If the computer already runs another operating system, then you can still install Ubuntu without needing to boot from a different drive using WUBI.

Configuring the BIOS

In many cases you can just pop a CD into the computer's optical drive and boot from it. Sometimes the computer will ignore the CD and attempt to boot from its hard disk instead. If this is the case, the "Boot Options" need to be changed in the computer's BIOS setup.

The usual procedure is:

  1. Turn on the computer. Watch for the keyboard LEDs to flash. As soon as this happens, watch the screen for a message like "Press F2 for BIOS Setup".
  2. Press the key. It will usually be Delete or F2. If the message does not appear, and neither F2 nor Delete works, you'll have to look up the manufacturer to find out how to enter the BIOS setup.
  3. After you press the key, the computer will continue starting up, and then go to a menu screen. Usually there will be a menu entry called "Boot options" or similar. Unfortunately BIOS software is not well standardized, and you may have to spend some time hunting for the boot options. They are nearly always there.
  4. The Boot Options area will sometimes have a list of devices in the order in which the BIOS will try to boot from them. Sometimes there is just a simple menu entry allowing you to choose your desired boot device. Choose the device you are using (usually the CD/DVD drive) and press the exit key (usually F10.) The system will usully ask you "Save Settings and Exit?" or something similar. Choose Yes and the computer will reboot. Now it should boot from the CD drive.
Note that BIOS software is almost never Free or Open Source, and is almost always flakey. You may need to perform the above procedure more than once before it works. 
Also sometimes messing with the hardware is necessary before the BIOS will respect a change. If this happens, get help!
BIOS issues can be resolved on some machines with the judicious use of Coreboot / SEABIOS.

What will the machine be used for?

Some computers that will be used for specialized purposes can use special Editions of Ubuntu. For example:

  1. Home theater - Mythbuntu
  2. Multimedia production - Ubuntu Studio
  3. Classroom use - Edubuntu
  4. Web, mail, database or other server - Server Edition

See https://en.wikipedia.org/wiki/List_of_Linux_distributions#Ubuntu-based for a non-exhaustive list. Here are some examples:

For most purposes Ubuntu Desktop Edition should work just fine.

The Ubuntu installation process

In general, you install Ubuntu by doing these steps:

  1. Boot from the Ubuntu CD (or other device containing Ubuntu)
  2. Choose "Install Ubuntu" to install quickly OR Choose "Try Ubuntu without installing" to first test the system
  3. Choose your language
  4. If you chose "Try Ubuntu", wait for the desktop to come up, do whatever testing you find necessary, then double-click the "Install" icon
  5. Choose your time zone
  6. Choose partitions
  7. Set up at least one user
  8. Download and install updates and optional packages (if available)

A note on partitions

The Ubuntu installer provides an automatic method of setting up the disk partitions necessary to run Ubuntu. Its defaults are sensible, and it should be used unless you need to do certain fancy tricks. If you have another OS installed on the computer, the installer will usually detect it and give you the option to install Ubuntu "side-by-side" with the existing OS or to remove the existing one.

You will need to set up partitions by hand if:
The installer does not detect the existing OS, and you want to install Ubuntu "side-by-side" with it
You have an existing directory (such as /home) from another Linux installation, and you want to use it with the new Ubuntu installation
Your computer has a small amount of RAM and disk space, and you need a customized swap area

Ubuntu needs a few basic partitions set up when you install it. At minimum, one partition must be set up for the "/" (root directory) mount point, and one for swap space (aka "virtual memory"). Some people like to set up separate partitions for /home, /usr, and /boot, among others.

About packages

All the software that the installer handles, and most of the software you will install later, comes in the form of "packages". A software "package" is an archive of files that contains the software to be installed along with information about the software (like where in the filesystem it will be installed, and what other software it needs in order to work).

When you install Ubuntu, it can automatically update itself and install certain packages if the computer has access to the Internet. The update will bring the version of Ubuntu you're installing to its current state. The optional packages are things like support for certain hardware (wireless networking and some display hardware, usually) or support for certain file formats (like mp3 or Shockwave Flash). These packages are not Free Software, so Ubuntu cannot legally provide them by default.

It is your responsibility, when you install them, to make sure you are legally allowed to do so.

Configuration

The installation should now be complete. You'll be asked to remove the CD from the drive and restart the computer.

When the computer restarts it will display the login screen. Enter the username and password you chose during the installation.

About sudo

The user you set up during the installation is able to use "sudo" to perform administrative tasks. When you open Ubuntu Software Centre, for example, the system will ask you to enter your password. This is the work of the graphical version of sudo (called gksudo in Ubuntu 10.04), because you need special privileges to install software. When you are using the command line, you'll need to prepend "sudo" to certain commands, like this:

sudo apt-get update

This command makes Ubuntu check the software repositories for new or updated packages.

Users

Each person who uses the computer should have a unique user account. For public computers, you may wish to enable the Guest account.

You can add users and toggle the Guest account from System → Administration → Users and Groups.

Groups

A Group is a set of users who get to use a resource. The Group gets ownership of the resource, and users are added to the group.

About privileges

Everything in Ubuntu has an owner and a set of "permissions" associated with it. If you create a file in your home directory, then you are the owner of that file, and you have permission to read, write, or execute that file. You don't have permission to write to files in /etc, although you can read them. You can change the permissions on files you own by right-clicking the file's icon, choosing Properties from the menu, and clicking the Permissions tab.

To override the permissions of files, you can use sudo. To change the permissions of files from the command line, use chmod. To change ownership of files, use chown. 

Updates and basic package management

You can (and should) enable automatic updates when you install Ubuntu. If you forget to do it then, you can always do it later by going to Administration → Software Sources and choosing the Updates tab.

Ubuntu provides two graphical programs for installing and managing software. Ubuntu Software Center is easier to use and gives a nice icon-driven view of available packages. Synaptic is for more advanced package management.

If there is software that you need which isn't installed by default, you can check the Ubuntu Software Center to see if what you want is among the more than 30,000 programs available. If it isn't, then you can add some of the optional repositories found in Administration → Software Sources. Some software providers offer their own repositories, and you can use Software Sources to add those to your system. The "main" repository is supported by Canonical, and the others listed in Software Sources have varying degrees of support in the Ubuntu community. Most repositories you add yourself are not supported by the Ubuntu community or Canonical.

When you file a bug with Launchpad, make sure the package you're reporting on is from one of the supported repositories. 
Bugs in unsupported software should be reported to the upstream provider's tracker.

You generally can't just download things from the Web and expect them to work with Ubuntu.

If you do this, then the package management system will not be able to track that software or update it automatically or keep its dependencies straight. 
You will have to do it by hand. 
If you do download software by other means than the package manager, I recommend keeping it in your /home directory. 
It will not be available to other users on the system, but it is less likely to cause problems.
Some software comes with its own installer. Some of these installers require sudo privileges. Make sure you trust the author before running any of these programs!

Basic use

Logging in

Once the system boots, it will show a screen with a login prompt. Usually this has a menu of existing users to choose from. Click on the one you made, enter your password, and you're in.

Finding your way around

Basic filesystem structure, introduction to FHS

The filesystem is a 'tree' structure. This means that it has one root node, to which all other elements are connected via zero or more intermediary nodes. Like this:

Tldp-tree.jpg

A file is specified by its path from the root node to its position in the tree, like so:

/home/user/Public/images/apicture.jpg

The files one step away from root represent the major categories of the file system, and their standard use is specified in the [Filesystem Hierarchy Standard].

In the GUI

Ubuntu-Thunar.png This is the Thunar file manager program. Other file managers such as Nautilus work similarly to Thunar.

In the top bar, you can see the path of the current working directory- that is, the one we are currently looking at. The icons left of the bar are for navigation: forward and back in history; up a level in the tree (that is, towards root- yes, UNIX trees are upside down for some reason); refresh the current listing; and a shortcut to the user's home directory. More shortcuts are on the left sidebar.

On the command line

See Bash for more information on command line operations.

The following commands are used to navigate the filesystem:

  • cd to change directory
  • pwd to show the path to the current working directory
  • ls to list the contents of the WD (with flags: -l for long listings, -a to show hidden files, -R for recursive listing- see man ls for more)

The shell evaluates the following shortcuts:

  • . for the current WD
  • .. for the parent of the WD
  • - for the previous WD
  • ~ for the user's home directory

The following commands are used to manipulate files:

  • touch to alter the file's timestamp. If the file doesn't exist then touch creates it.
  • rm to remove a file
  • cp to copy a file
  • mv to move a file (that is, to give it a different pathname- same as 'cp $OLDFILE $NEWFILE && rm $OLDFILE'

Structure

Kernel vs Userland

The OS is centered around a program called the "kernel". Linux is a kernel, as is GNU Mach. Mac OS uses a FreeBSD kernel. The kernel controls the computer's hardware- device drivers need some means by which to "hook" into the kernel. The Linux kernel is modular, so device drivers (and other functions) can be dynamically added as modules to the kernel while it runs. The kernel also manages the computer's memory. Memory is divided between "kernel space" and "user space" aka userland. Kernel space is memory reserved by the kernel for its own use, user space is that available for other programs' use.

Userland or user space is where everything happens that isn't directly part of the kernel. Most importantly, application programs run by users run in user space.

Processes

Every running program consists of one or more processes. Each process has a UID and a "nice" value. Nice determines the priority of the process. Lower numbers equal higher priority (they are less nice). Nice has range 32 to -32. Priority means the amount of processor "ticks" or timeslices init gives to the process. Every processor has some number of timeslices available per unit time. More timeslices means the process runs faster. Processes live in a tree. This means that every process (except init) has a parent and may have one or more children.

init

Init is the parent of all processes, with UID 0. Init is started by the kernel during boot. Init then starts all the necessary daemons according to its configuration. There are a few different ways of configuring init.

Upstart

Upstart is a 'new, improved' version of init that handles dependencies (that is, some services need to start before others do, and upstart tracks this) among other things. Upstart introduces a new interface in the service program. Not all services support this yet as of 20130920.

SysV init

SysV init is the init version most often used by Linux distributions. It is the standard init used by Debian (and therefore Ubuntu). SysV init supports the scripting interface at /etc/init.d/ for controlling services. It also supports runlevels, which are increasing levels of complexity the system can handle as it boots. This allows for graceful degradation in case of problems (or administrative decision- lower runlevels are useful for troubleshooting.) 0 - Halt 1 - Single-user mode 2 - Multi-user, no networking 3 - Multi-user with networking 4 - Not used 5 - Graphics layer 6 - Reboot

BSD init

BSD init is a simpler implementation of init with a 'flatter' configuration. Runlevels are optional.