boot

advertisement
ASIST
Administração de Sistemas
Linux: Pós-instalação
Semana
20 a 25 Novembro
2006
Alexandre Bragança
Red Hat / Fedora
(http://fedoraproject.org/wiki/)
Installation Log
• In Fedora and generally all RedHat versions,
Anaconda stores a log of all the installed
packaged in /root/install.log.
• Another interesting file is /root/anacondaks.cfg, a working configuration file for an
unattended kickstart installation which uses the
parameters and settings defined for the newly
installed box.
• Other usefull files:
• /var/log/messages check everything in here daily
• /var/log/dmesg check for hardware errors
Fedora Disk Druid
Fedora Disk Druid
For each of the hard disk partitions, you can see:
• Device
• The device name is the name representing the hard disk
partition in the /dev directory. Each disk partition device
begins with two letters: hd for IDE disks, sd for SCSI
disks, ed for ESDI disks, or xd for XT disks. After that is
a single letter representing the number of the disk (disk 1
is a, disk 2 is b, disk 3 is c, and so on). The partition
number for that disk (1, 2, 3, and so on) follows that. For
example, /dev/hda1 represents the first partition on the
first IDE hard drive on the computer.
Fedora Disk Druid
•
•
•
•
•
Mount Point/Raid/Volume—The directory where the partition is connected
into the Linux file system (if it is). You must assign the root partition (/) to a
native Linux partition before you can proceed. If you are using RAID or
LVM, the name of the RAID device or LVM volume appears here.
Type—The type of file system that is installed on the disk partition. In many
cases, the file system will be Linux (ext3), Win VFAT (vfat), or Linux swap.
However, you can also use the previous Linux file system (ext2), physical
volume (LVM), or software RAID.
Format—Indicates whether (check mark) or not (no check mark) the
installation process should format the hard disk partition. Partitions marked
with a check are erased! So, on a multiboot system, be sure your Windows
partitions, as well as other partitions containing data are not checked!
Size (MB)—The amount of disk space allocated for the partition. If you
selected to let the partition grow to fill the existing space, this number may
be much larger than the requested amount.
Start/End—Represents the partition’s starting and ending cylinders on the
hard disk.
Disk Partition Notes
• You need at least a root (/) partition and a swap partition.
• The fdisk utility is available with most every Linux system
for creating and working with disk partitions in Linux. It
does the same job as graphical partitioning tools such as
Disk Druid, although it’s no longer offered as an option
during Fedora installation.
• However, during Fedora installation, and other Linux
installations that have virtual terminals running, you can
switch to a shell (press Ctrl+Alt+F2) and use fdisk
manually to partition your hard disk.
Disk Partition Notes
• The fdisk command is one that is available on many
different operating systems (although it looks and
behaves differently on each). In Linux, fdisk is a menubased command. To use fdisk to list all your partitions,
type the following (as root user):
# fdisk –l
Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 4833 38716650 83 Linux
/dev/hda3 4834 4865 257040 82 Linux swap
Disk Partition Notes
• To see how each partition is being used
on your current system, type the following:
• # df –h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 37G 5.4G 30G 16% /
/dev/hda1 99M 8.6M 86M 10% /boot
none 61M 0 61M 0% /dev/shm
Disk Partition Notes
• If this had been a dual-boot system (with
Windows 98), you might have seen a Windows
partition from fdisk that looked like the following:
/dev/hda1 * 1 83 666666+ b Win95 FAT32
• You could mount that partition in Linux (to get to
your Windows files when Linux is booted) by
typing:
# mkdir /mnt/win
# mount -t vfat /dev/hda1 /mnt/win
Assigning Partitions to Particular
Directories
/boot
• Sometimes the BIOS in older PCs can access only the
first 1,024 cylinders of your hard disk. To make sure that
the information in your /boot directory is accessible to
the BIOS, create a separate disk partition (of about
100MB) for /boot and make sure that it exists below
cylinder 1,024.
• The rest of your Linux system can exist outside of that
1,024-cylinder boundary if you like.
• Even with several boot images, there is rarely a reason
for /boot to be larger than 100MB. (For newer hard disks,
you can select the Linear Mode check box during
installation. Then the boot partition can be anywhere on
the disk.)
Assigning Partitions to Particular
Directories
/usr
• This directory structure contains most of the applications
and utilities available to Fedora Linux users. Having /usr
on a separate partition lets you mount that file system as
read-only after the operating system has been installed.
This prevents attackers from replacing or removing
important system applications with their own versions
that may cause security problems.
• A separate /usr partition is also useful if you have
diskless workstations on your local network.
• Using NFS, you can share /usr over the network with
those workstations.
Assigning Partitions to Particular
Directories
/var
• Your FTP (/var/ftp) and Web-server (/var/www) directories are, by
default in many Linux systems, stored under /var. Having a separate
/var partition can prevent an attack on those facilities from corrupting
or filling up your entire hard disk.
/home
• Because your user account directories are located in this directory,
having a separate /home account can prevent a reckless user from
filling up the entire hard disk.
/tmp
• Protecting /tmp from the rest of the hard disk by placing it on a
separate partition can ensure that applications that need to write to
temporary files in /tmp are able to complete their processing, even if
the rest of the disk fills up.
Linux directories
Some of the Linux directories that may interest you include the following:
• /bin—Contains common Linux user commands, such as ls, sort, date, and
• chmod.
• /boot—Has the bootable Linux kernel and boot loader configuration files
• (GRUB).
• /dev—Contains files representing access points to devices on your
systems. These include terminal devices (tty*), floppy disks (fd*), hard disks
(hd*), RAM (ram*), and CD-ROM (cd*). (Users normally access these
devices directly through the device files.)
• /etc—Contains administrative configuration files.
• /home—Contains directories assigned to each user with a login account.
• /media—Provides a standard location for mounting and automounting
devices, such as remote file systems and removable media (with directory
names of cdrecorder, floppy, and so on).
Linux directories
•
•
•
•
•
•
•
•
/mnt—A common mount point for many devices before it was supplanted by
the standard /media directory. Some bootable Linux systems still used this
directory to mount hard disk partitions and remote file systems.
/proc—Contains information about system resources.
/root—Represents the root user’s home directory.
/sbin—Contains administrative commands and daemon processes.
/sys (A /proc-like file system, new in the Linux 2.6 kernel and intended to
contain files for getting hardware status and reflecting the system’s device
tree as it is seen by the kernel. It pulls many of its functions from /proc.
/tmp—Contains temporary files used by applications.
/usr—Contains user documentation, games, graphical files (X11), libraries
(lib), and a variety of other user and administrative commands and files.
/var—Contains directories of data used by various applications. In
particular, this is where you would place files that you share as an FTP
server (/var/ftp) or a Web server (/var/www). It also contains all system log
files (/var/log).
Boot Loader Configuration
• In order to boot the system without a boot
diskette, you usually need to install a boot
loader.
• A boot loader is the first software program that
runs when a computer starts. It is responsible for
loading and transferring control to the operating
system kernel software.
• The kernel, in turn, initializes the rest of the
operating system.
where you want the boot loader to
be installed
• The master boot record (MBR)
– This is the recommended place to install a boot loader, unless
the MBR already starts another operating system loader, such as
System Commander. The MBR is a special area on your hard
drive that is automatically loaded by your computer's BIOS, and
is the earliest point at which the boot loader can take control of
the boot process. If you install it in the MBR, when your machine
boots, GRUB (or LILO) will present a boot prompt. You can then
boot Red Hat Linux or any other operating system that you have
configured the boot loader to boot.
• The first sector of your boot partition
– This is recommended if you are already using another boot
loader on your system. In this case, your other boot loader will
take control first. You can then configure that boot loader to start
GRUB (or LILO), which will then boot Red Hat Linux.
Using LILO or GRUB Boot
Loaders
• A boot loader lets you choose when and
how to boot the bootable operating
systems installed on your computer’s hard
disks.
• Most Linux systems give you the
opportunity to use GRUB or LILO boot
loaders.
GRUB Boot Loader
• With multiple operating systems installed and several
partitions set up, how does your computer know which
operating system to start?
• To select and manage which partition is booted and how
it is booted, you need a boot loader.
• The boot loader that is installed by default with Fedora is
called the GRand Unified Boot loader (GRUB).
• If you want to change your boot options so that they take
effect every time you boot your computer, see the
section on permanently changing boot options.
• Changing those options involves editing the
/boot/grub/grub.conf file.
Temporarily Changing Boot
Options
•
From the GRUB boot screen, you can select to change or add boot options
for the current boot session. First, select the operating system you want
(using the arrow keys) and type e.
GRUB version 0.94 (639K lower / 128768K upper memory)
root (hd0,0)
kernel /boot/vmlinuz-2.6.13-1.1526_FC4 ro root=LABEL=/
initrd /boot/initrd-2.6. 13-1.1526_FC4.img
Use the↑and↓keys to select which entry is highlighted.
Press ‘b’ to boot, ‘e’ to edit the selected command in the
boot sequence, ‘c’ for a command-line, ‘o’ to open a new
line
after (‘O’ for before) the selected line, ‘d’ to remove
the
selected line, or escape to go back to the main menu.
Temporarily Changing Boot
Options
• The second line of the example (beginning with
kernel) identifies the boot image (/boot/vmlinuz2.6. 13-1.1526_FC4) and several options. The
options identify the partition as initially being
loaded ro (read-only) and the location of the root
file system on a partition with the label LABEL=/.
• The third line (starting with initrd) identifies the
location of the initial RAM disk, which contains
the minimum files and directories needed during
the boot process.
Temporarily Changing Boot
Options
1. Position the cursor on the kernel line and type e.
2. Either add or remove options after the name of the boot
image.
• Boot to a shell—If you forgot your root password or if
your boot process hangs, you can boot directly to a shell
by adding init=/bin/sh to the boot line.
• Select a run level—If you want to boot to a particular run
level, you can add the word linux, followed by the
number of the run level you want. For example, to have
Fedora Linux boot to run level 3 (multiuser plus
networking mode), add linux 3 to the end of the boot line.
You can also boot to single-user mode (1), multi-user
mode (2), or X GUI mode (5). Level 3 is a good choice if
your GUI is temporarily broken.
Permanently Changing Boot
Options
• You can change the options that take
effect each time you boot your computer
by changing the GRUB configuration file.
In Fedora and other Linux systems, GRUB
configuration centers on the
/boot/grub/grub.conf file.
/boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making
# changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda6
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,4)/grub/splash.xpm.gz
title Fedora Linux (2.6.13-1.1526_FC4)
root (hd0,4)
kernel /vmlinuz-2.6.13-1.1526_FC4 ro root=LABEL=/
initrd /initrd-2.6.13-1.1526_FC4.img
title Windows XP
rootnoverify (hd0,0)
chainloader +1
Adding a New GRUB Boot Image
• 1. Copy the new image from the directory in
which it was created (such as
/usr/src/kernels/2.6.13-1.1526_FC4i386/arch/i386/boot/) to the /boot directory.
Name the file something that reflects its
contents, such as bz-13-1.1526_FC4-i386. For
example:
# cd /usr/src/kernels/13-1.1526_FC4i386/arch/i386/boot/
# cp bzImage /boot/bz-13-1.1526_FC4-i386
Adding a New GRUB Boot Image
• 2. Add several lines to the
/boot/grub/grub.conf file so that the image
can be started at boot time if it is selected.
For example:
title Fedora Linux (IPV6 build)
root (hd0,4)
kernel /bz-13-1.1526_FC4-i386 ro
root=/dev/hda6
initrd /initrd-2.6.5.img
• 3. Reboot your computer.
Booting Your Computer with
LILO
• LILO stands for LInux LOader. Like other boot loaders,
LILO is a program that can stand outside the operating
systems installed on the computer so you can choose
which system to boot. It also lets you give special
options that modify how the operating system is booted.
• If LILO is being used on your computer, it is installed in
either the master boot record or the first sector of the
root partition. The master boot record is read directly by
the computer’s BIOS. In general, if LILO is the only
loader on your computer, install it in the master boot
record. If there is another boot loader already in the
master boot record, put LILO in the root partition.
Setting Up the /etc/lilo.conf File
prompt
timeout=50
default=linux
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
message=/boot/message
linear
image=/boot/vmlinuz-2.6.13-1.1526_FC4-i386
label=linux
initrd=/boot/initrd-2.6.13-1.1526_FC4-i386.img
read-only
root=/dev/hda6
append=”root=LABEL=/”
other=/dev/hda1
optional
label=dos
Changing /etc/lilo.conf File
1. Copy the new image from the directory in which it was
created (such as /usr/src/kernels/ 2.6.12-1.1398_FC4i386/arch/i386/boot) to the /boot directory. Name the file
something that reflects its contents, such as zImage2.6.z13-1.1526_FC4-i386.
2. Add several lines to the /etc/lilo.conf file so that the
image can be started at boot time if it is selected. For
example:
image=/boot/zImage-2.6.13-1.1526_FC4-i386
label=new
3. Type the lilo -t command (as root user) to test that the
changes were okay.
4. Type the lilo command (with no options) for the changes
to be installed.
To switch your boot loader from
GRUB to LILO, do the following:
1. Configure the /etc/lilo.conf.
2. As root user from a Terminal window,
type the following:
# lilo
3. The new Master Boot Record is written,
including the entries in /etc/lilo.conf.
4. Reboot your computer. You should see
the LILO boot screen.
To change your boot loader from
LILO to GRUB, do the following:
1. Configure the /boot/grub/grub.conf file.
2. You need to know the device on which you want
to install GRUB. For example, to install GRUB
on the master boot record of the first disk, type
the following as root user from a Terminal
window:
# grub-install /dev/hda
The new Master Boot Record is written to boot
with the GRUB boot loader.
3. Reboot your computer. You should see the
GRUB boot screen.
After starting the kernel…
• In Linux, we create processes by using
fork.
• Init (Pid = 1) is the first Linux process and
the only one that does not have a parent.
• Init is responsible to start other Linux
services. The services to be started are
configured in /etc/inittab.
After starting the kernel…
•
•
Init also set up the system to a specific run-level.
Run-levels are used to configure the services available in the
system.
• Usual run-levels are:
0: halt
1: Single user mode
2: Multiuser, without NFS
3: Full multiuser mode
4: unused
5: X11
6: reboot
Note: If run-level 5 fails it is possible to change to text mode using
CTRL-ALT-F2.
/etc/inittab
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
# Run gettys in standard runlevels
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
/etc/inittab
• To change runlevels, the root can execute
telinit with an argument that represents the
new runlevel or q which tells init to reload the
inittab file.
• Runlevels are defined in /etc/rc.d
(“runcommands.directory”). This directory has
several sub-directories (rc0.d, rc1.d, rc2.d, ...)
that define the state of the system services for
each runlevel. Actually, the contents of this subdirectories are symbolic links to scripts which are
responsible to start and stop the system services
that reside in /etc/rc.d/init.d.
/etc/inittab - Notas
• O nome dos links simbólicos das sub-pastas (rc0.d,
rc1.d, rc2.d, ...) é atribuído da seguinte forma:
XxxNomeServico, onde X e o caracter K ou S conforme
se deseje terminar ou iniciar o serviço e xx é um número
inteiro utilizado para indicar a ordem pela qual os
serviços devem ser terminados ou iniciados.
• O ficheiro script rc, e o responsável pela mudança de
runlevel. Este recebe como argumento o runlevel para o
qual deve mudar e executa os scripts indicados na pasta
respectiva.
• Antes de iniciar os serviços de qualquer runlevel é
necessário efectuar algumas iniciações. Isto e feito pelo
script rc.sysinit, localizado também em /etc/rc.d. Este
script é razoavelmente longo, e é responsável por
tarefas como: criação do sistema de ficheiros proc,
criação da partição de swap, atribuição do nome da
máquina, iniciações de teclado, etc.
Alguns comandos
runlevel
• Devolve o run-level actual.
chkconfig
• Mostra os serviços activos em cada run-level. A
lista inclui os serviços do rc.init assim como os
serviços de rede do xinetd (extended Internet
services daemon).
chkconfig --list # lista os serviços
chkconfig servicename off | on | reset
chkconfig xinetd on # ligar o xinetd
Alguns comandos
service
• Regardless of how a service is enabled a
runlevel or if it is defaulted to "On" or "Off",
every service can be started or stopped
and managed at runtime.
service –status-all # lista estado dos
servicos
service nome_do_servico [ start | stop |
status | reload | restart ]
Virtual Terminals
• Virtual terminals are a way to have multiple shell
sessions open at once without having a GUI running.
• You can switch between virtual terminals much the same
way that you would switch between workspaces on a
GUI. Press Ctrl+Alt+F1 (or F2, F3, F4, and so on up to
F6 on Fedora and other Linux systems) to display one of
six virtual terminals.
• The next virtual workspace after the virtual terminals is
where the GUI is, so if there are six virtual terminals, you
can return to the GUI (if one is running) by pressing
Ctrl+Alt+F7. (For a system with four virtual terminals,
you’d return to the GUI by pressing Ctrl+Alt+F5.)
Linux Disk Management
• /etc/fstab
Identifies the devices for common storage media
(hard disk, floppy, CD-ROM, and so on) and
locations where they are mounted in the Linux
system.
This is used by the mount command to choose
which file systems to mount when the system
first boots.
• To see file system types that are currently
available to be used on your system, type cat
/proc/filesystems.
Linux Disk Management
• Here’s an example of an /etc/fstab file:
LABEL=/
LABEL=/boot
/dev/devpts
/dev/shm
/dev/proc
/dev/sys
/dev/hda5
/dev/hdc
/dev/hda1
/dev/fd0
/
ext3
/boot
ext3
/dev/pts
devpts
/dev/shm
tmpfs
/proc
proc
/sys
sysfs
swap
swap
/media/cdrecorder udf,iso9660
/mnt/win
vfat
/mnt/floppy
auto
defaults
defaults
gid=5,mode=620
defaults
defaults
defaults
defaults
exec,noauto,managed
noauto
noauto,owner 0 0
1
1
0
0
0
0
0
0
0
• The CD drive (/dev/hdc) and floppy disk (/dev/fd0)
drives are not mounted at boot time. Definitions are
put in the fstab file for floppy and CD drives so that
they can be mounted in the future
1
2
0
0
0
0
0
0
0
Mount
•
Any user can type mount (with no options) to see what file systems are
currently mounted on the local Linux system:
$ mount
/dev/hda3 on / type ext3 (rw)
/dev/hda2 on /boot type ext3 (rw)
/dev/proc on /proc type proc (rw)
/dev/sys on /sys type sysfs (rw)
/dev/devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/shm on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/hdc on /media/cdrecorder type iso9660
(ro,nosuid,nodev)
/dev/fd0 on /mnt/floppy type ext3 (rw)
Mounting Removable Media
•
•
#
#
•
#
#
•
#
If you want to mount a file system manually, the /etc/fstab file helps make it
simple to mount a floppy disk or a CD.
CD—If you are mounting a CD that is in the standard ISO 9960 format (as
most software CD-ROMs are), you can mount that CD by placing it in your
CD-ROM drive and typing one of the following:
mount /media/cd*
mount /mnt/cdrom
Floppy disk—If you want to mount a floppy in the Linux ext3 file system
format (ext3), or in some cases a format that can be autodetected, mount
that floppy disk by inserting it in your floppy drive and typing one of the
following:
mount /media/floppy*
mount /mnt/floppy
here’s an example of how to mount a floppy containing MS-DOS files:
mount -t msdos /dev/fd0 /mnt/floppy
Mounting a Disk Image in
Loopback
• Another valuable way to use the mount
command has to do with disk images. If you
download a CD or floppy disk image from the
Internet and you want to see what it contains,
you can do so without burning it to CD or
floppy.
# mkdir /mnt/mycdimage
# mount -o loop whatever-i386-disc1.iso
/mnt/mycdimage
Using the umount Command
• When you are done using a temporary file
system, or you want to unmount a permanent
file system temporarily, use the umount
command. This command detaches the file
system from its mount point in your Linux file
system. To use umount, you can give it either a
directory name or a device name.
# umount /mnt/floppy
Linux autofs
• This is the automount daemon used for remote
filesystem mounting such as nfs along with
mounting CDROM and floppy drives
automatically. It uses the automount program to
run as a background task to perform the
automatic mounts when required.
• It will read the configuration file,
/etc/auto.master and pass parameters from
this file to the automount program.
/etc/auto.master
# $Id: auto.master,v 1.2 1997/10/06 21:52:03 hpa
Exp $
# Sample auto.master file
# Format of this file:
# mount point map options
# For details of the format look at autofs(8).
/mnt /etc/auto.misc --timeout 20
There is a man page for auto.master(5). This file
specifies the file /etc/auto.misc for device
mounts.
/etc/auto.misc
#
#
#
#
#
$Id: auto.misc,v 1.2 1997/10/06 21:52:04 hpa Exp $
This is an automounter map and it has the following
format
key [ -mount-options-separated-by-comma ] location
Details may be found in the autofs(5) manpage
#kernel -ro,soft,intr ftp.kernel.org:/pub/linux
cd -fstype=iso9660,ro :/dev/cdrom
# the following entries are samples to pique your
# imagination
fl -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
This file controls the devices to be mounted and specifies the directory used for
that device
VMWare Server
(www.vmware.com)
•
•
•
•
Vai ser usado para as aulas práticas.
Software que permite criar máquinas virtuais.
O VMWare Server é “free”.
No DEI está instalado em:
– virtual.dei.isep.ipp.pt (servidor)
– Postos acedem através de "VMware Server Console“
(disponivel em "\\virtual\clients").
– Em "\\virtual\CDS“ estão disponíveis “imagens” de
linux.
Download