If you can see this check that

next section prev section up prev page next page

Basic Administration Concepts

Disks and Partitions

Disks

Linux disk devices are named after the type of interface they sit on. Legacy hard drive interfaces, such as IDE and EIDE are often named /dev/hda*, while more modern SATA or SCSI are named /dev/sda*.

Partitions

Rather than use the whole disk for one purpose almost all operating systems allow hard drives to be partitioned up into partitions. Each partition is effectively a chunk of the disk, and can have its own operating system, boot information, or simply be a different volume in a single operating system.

Partitions can be primary or secondary partitions. In effect the first 4 partitions can be primary, while the remainder are considered secondary. There are some technical advantages to primary partitions, but by and large it is normal to make your bootable partitions as primary partitions (although this is not a requirement), and then to split up the disk how you like.

> sfdisk -l /dev/sda

Disk /dev/sda: 19449 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+   1274-   1275-  10240000   83  Linux
/dev/sda2       1274+   3824-   2550-  20480000   82  Linux swap / Solaris
/dev/sda3       3824+  19449-  15625- 125506560   83  Linux
/dev/sda4          0       -       0          0    0  Empty

The sfdisk command in linux is one of the many commands offered by linux to investigate and change partition table information. The above example is the drive structure of one of my servers. Here you see 3 partitions (all primary).

In this structure sda1 is 10GB and is /, and sda3 is /home (125GB or so). There are is one other partition, sda2, which is the swap partition for use with virtual memory. It is customary unless you have other information to make the swap space double your main memory size. The swap size in this case is 2GB.

$ cat /etc/fstab

The fstab file explains to Linux what partitions are to be mounted where. It may contain magical partitions which dont really exist, and these are to do with special filesystems for handling kernel virtual directories, such as the /proc directory.

UUID=d40d9bef-1306-491f-bcba-61990e1bf886 /                       ext4    defaults        1 1
UUID=f9d23007-9414-498f-9cc6-553eeb685213 /home                   ext4    defaults        1 2
UUID=5501a6af-ee7f-4c73-81a7-cf5c75cb8661 swap                    swap    defaults        0 0
# /dev/sda2	       swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

The first column indicates what to mount. This could be the device name, such as /dev/sda2. In modern systems each device, when formatted, is given a block device identifier, or UUID. You can use that in place of the device name. This is useful as it allows a drive to be moved from one drive slot to another (which may change the device name) and still have Linux recognise it and mount it correctly. Next is the location that the partition should be mounted, its file system type (such as swap or ext4 or ntfs), then some flags to be used, then two numbers. The first number is 1 if this drive should be backed up (assuming you do backups) and the last number is the order that the drives are checked for damage (root first then the others).

% blkid
/dev/sda1: UUID="d40d9bef-1306-491f-bcba-61990e1bf886" TYPE="ext4"
/dev/sda2: UUID="5501a6af-ee7f-4c73-81a7-cf5c75cb8661" TYPE="swap"
/dev/sda3: UUID="f9d23007-9414-498f-9cc6-553eeb685213" TYPE="ext4"

The blkid command allows you to find out the UUIDs for all attached block device partitions, along with their types if known.

$ df

Filesystem           1K-blocks      Used        Available Use% Mounted on
/dev/sda2             10080520     3142968   6425484    33%	/
/dev/sda1             101086         9665         86202        11% 	/boot
none                     1038660       0              1038660     0% 	/dev/shm
/dev/sda6             56340828      3853984  49624868   8% 	/home

The df command lets you find out the current Disk Usage, which reports mounted partition utilisation of all mountpoints which are present as a directory. So it does not report swap space usage (but this can be found in /proc/swaps). It can be hard to read as it is in blocks, but "du -h" reports the information in a human readable form, e.g. MB or GB.

*UML

In a UML-power virtual machine, there are no IDE or SCSI drives. The disks are called /dev/ubd/n where n is a number. They are actually implemented by files in the host operating system, but this is hidden from you. If you have a UML virtual machine then the drive partitions are:

However if you are using the standard QEMU/KVM virtualisation then the drives are the normal /dev/sda1 style devices.

Disk Usage

If you want to find out how much disk space a directory is using, the "du" command does this easily.

$ du -s /usr/lib
477464  /usr/lib
$ du -sh /usr/lib
467M    /usr/lib

"-s" is useful, otherwise it tells you about all subdirectories sizes too one subdirectory at a time. With this summary flag, it still check the subdirectories but only reports the total size. Again "-h" puts it into human readable form using MB or GB.

Linux Boot Process

Booting to kernel

From switch-on:

  1. PC BIOS selects a boot disk
  2. BIOS loads the boot block and executes it.
  3. This loads a stage 1 boot loader.
  4. Stage 1 loads stage 2 loader.
  5. Linux loader (e.g. Grub, lilo) runs
  6. Operator selects from loader menu
  7. Kernel loaded with device ramdisk

The linux loader, e.g. grub, gives the user an interface for selecting different operating systems or different kernel configurations. For Redhat it looks like this:

$ cat /etc/grub.conf

The grub loaded is very configurable, and the example above is configured as follows:

default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Fedora Core (2.6.6-1.435.2.3)
        root (hd0,0)
        kernel /vmlinuz-2.6.6-1.435.2.3 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.6-1.435.2.3.img
title Fedora Core (2.6.5-1.358)
        root (hd0,0)
        kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/ rhgb quiet
        initrd /initrd-2.6.5-1.358.img

Here it says that unless within 10 seconds you touch the keyboard, it will automatically boot the first entry by default. The background image is called the splashimage. There are two entries, each for a different version of the kernel. This is standard Linux practice. Each time you update your linux distribution kernel, the previous few versions are kept to allow you to recover from a problem caused by the new kernel. Problems with new kernels is uncommon but they can happen, and having a broken kernel may result in an unusable machine.

Startup Commands

As linux boots, it runs various system scripts. These do general housekeeping functions, but eventually it enters one for your standard "runlevel". Runlevel scripts enable the services (like ssh and apache") which you may want to start. Runlevel startup scripts all live in /etc/init.d/.

For example, apache, the web server in Linux, is looked after by the following init script:

/etc/init.d/httpd

/etc/init.d/*

All the scripts in the init.d directory can be executed directly, and take a range of parameters. You could call them by hand, but it is best to use system commands to do this instead. The scripts in init.d can:

You should not call these scripts directly, as this can interfere with different security models which are in use (such as SELinux). Instead you need to use the "service" command. For instance, sending "start" to the httpd control script in init.d is performed as follows:

> service httpd start

Run levels

The run level determines what init.d files run. As you enter a run level services not running which should run at that run level start. As you leave a run level services which should not be running at the new run level stop. There are 7 default runlevels, numbered 0 to 6.

  1. Runlevel 0 - "HALT", is entered to shut the system down.
  2. Runlevel 1 - "Single User Mode", is entered for serious administrative tasks without allowing other users to login or starting services.
  3. Runlevel 2 - "Multi User Mode", is entered to have no networking or GUI.
  4. Runlevel 3 - "Multi User with Networking", is entered to have networking byt no GUI.
  5. Runlevel 4 - "Unused".
  6. Runlevel 5 - "Normal System", is entered to run the system normally.
  7. Runlevel 6 - "REBOOT", is entered when you want to reboot the machine.

What services start and stop are determined by the soft links found in the different /etc/rd?.d directories (where the ? can be the numbers 0 to 6). Usually all we need to know is the stardard runlevel is 5.

$ ls /etc/rc5.d

K01yum 		K35vncserver 	K74ypxfrd 	   S13portmap    S80sendmail
K05saslauthd 	K35winbind 	K89netplugd 	   S14nfslock    S90crond
K10dc_server 	K45named 	K95kudzu 	   S18rpcgssd    S90xfs
K10psacct 	K50netdump 	K96init.cssd 	   S19rpcsvcgssd S95anacron
K12dc_client 	K50snmpd 	S00microcode_ctl   S20random 	 S95atd
K12mysqld 	K50snmptrapd 	S04readahead_early S25netfs 	 S96init.cssd
K20nfs 		K50tux 		S06cpuspeed 	   S26apmd 	 S96readahead
K24irda 	K54dovecot 	S08iptables 	   S28autofs 	 S97messagebus
K25squid 	K70aep1000 	S09isdn 	   S44acpid 	 S97rhnsd
K34dhcrelay 	K70bcm5820 	S10network 	   S55sshd 	 S99local
K34yppasswdd 	K74ntpd 	S12syslog 	   S56rawdevices S99mdmonitor
K35dhcpd 	K74ypserv 	S13irqbalance 	   S56xinetd

The filenames all take the following format:
S/K priority service-name
If the name starts with an S then it Starts at that runlevel, while a K indicates that is is stopped (Killed) at that runlevel. A priority of 00 is executed before priority 01, which is before priority 50, all the way to 99. So for instance, consider S99mdmonitor:

$ ls -l /etc/rc5.d/S99mdmonitor
lrwxrwxrwx. 1 root root 19 Jul 27 13:00 S99mdmonitor -> ../init.d/mdmonitor

Link management

Newer service managers

One problem with init.d is that it is linear. Each service is started in turn before the next service starts. There are newer service managers available which use tree dependency models and parallel execution. Fedora 15 currently uses a system based on systemd. However it still uses init.d for some services which have not been migrated to the new manager. "systemd" is much more complex to understand than the simple init.d approach, but it is much faster to boot as many services can start in parallel. Service managers is still very much an area under active development

The syslog

The xinetd super-daemon

XINETD

$ cat /etc/xinetd.d/telnet

service telnet
{
        flags           	= REUSE
        socket_type 	= stream
        wait            	= no
        user            	= root
        server          	= /usr/sbin/in.telnetd
        log_on_failure  += USERID
        disable         = no
}

Terminating a process

User Management

User Management

Manual Creation

$ adduser gordon

Skel files

$ ls /etc/profile.d

colorls.csh  gnome-ssh-askpass.csh  	krb5.csh  less.csh  vim.csh
colorls.sh    gnome-ssh-askpass.sh	krb5.sh    less.sh    vim.sh
glib2.csh     kde.csh                          	lang.csh  qt.csh      which-2.sh
glib2.sh       kde.sh                         	lang.sh    qt.sh

$ cat /etc/profile.d/vim.sh

if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then
  # for bash, pdksh and zsh, only if no alias is already set
  alias vi >/dev/null 2>&1 || alias vi=vim
fi

Example

Moving a uid or gid

Useful Commands

$ chown jim.staff filename
$ chown jim filename
$ chgrp staff filename

When a User logs in

FILE SEARCHING

A file CONTAINING something

A FILENAME containing something

Find to do something

Discussion

Discussion

Discussion

Question 1

Question 2

Question 3

Question 4

  • The following commands are typed on a Unix computer.
    $ mkdir temp
    $ cd temp/
    $ mkdir txt.txt/
    $ cd txt.txt/
    $ touch hello
    $ cd ..
    $ ls *.*
    
    What is printed on the screen in response to the last line of the commands?

  • Centos 7 intro: Paths | BasicShell | Search
    Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
    Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
    Caine 13.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Registry | Mock Exam |
    CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
    Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
    Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
    Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

    Linuxzoo created by Gordon Russell.
    @ Copyright 2004-2024 Edinburgh Napier University