LPI Linux LPIC1
Total Page:16
File Type:pdf, Size:1020Kb
LPI Linux LPIC1 Module 2 Module Contents • 1 Evans Ikua Lead Editor Kenya [email protected] • 2 Chris Brown Content Author UK [email protected] • 3 Mark Clarke Content Author RSA [email protected] • 4 Brian Ssennoga Content Author Uganda [email protected] • 5 Trust Zifa Material co-editor Zimbabwe [email protected] • 6 John Matogo Material co-editor Kenya john [email protected] • 7 Ken Mutua Material co-editor Kenya [email protected] • 8 Bernard Owuor Material co-editor Kenya [email protected] • 9 Sisay Adugna Material co-editor Ethiopia [email protected] • 10 Balthas Seibold Senior Project • Manager - GIZ • Germany [email protected] • 11 Petra Hagemann Project Manager - GIZ Germany [email protected] • 12 George Nyambuya Africa Coordinator - • ict@innovation • RSA [email protected] • 13 David Paulus Intern - GIZ Germany [email protected] Module Contents • Design hard disk layout • Install a boot manager • Manage shared libraries • Use Debian package management • Use RPM and YUM package management Design hard disk layout Linux creates filesystems on block devices. A device whose data can only be accessed sequentially, such as keyboards and mice are character devices but devices such as hard-disks, that can have their data accessed randomly are call block devices. Each type of device has different functionality to cater for the differences in data access methods. The Linux kernel's device-mapper framework allows for the creation of virtual block devices on which filesystems can be created. The advantage of virtual block devices is that Linux can provide functionality such as encrypted drives and raid devices without the need for specialist hardware. Virtual block devices allow for the creation of LVM (Logical Volume Manager) drives. Design hard disk layout Common Partition Schemes 1. Small systems – Boot partition - 50-100MB usually on the 1st partition to ensure all kernels are below the 1024 cylinder limit for older kernel BIOS. – Swap partition - Swap space allocation depends on he amount of physcial ram available. There is much debate about the optimal size of the partition for swap space, especially as the amount of physical memory available in most systems is increasing, but a general rule of thumb is to use twice the amount of ram available but a maximum of around 1 G is recommended. Design hard disk layout Common Partition Schemes – / The root filesystem partition contains the rest of the Linux operating system and should usually be allocated the remaining disk space. Most distributions today will install the root partition on an logical partition to allow for the possibility of creating more than 4 partitions in future should this be necessary. Design hard disk layout Common Partition Schemes 2. Larger systems – Boot partition - 100MB-250MB In more modern computers, that do not have the 1024 cylinder limit, you may want to allocate more space to the boot to accommodate additional kernels. Keeping the /boot separate may be necessary especially if the remaining filesystems are loaded on virtual block devices which the boot loader cannot access natively, for example they root filesystem is on a software raid5 block device. Design hard disk layout Common Partition Schemes –Swap partition - as above –/home - The /home directory is where all user data and documents are kept. A separate partition means that it will be easier to backup data and protects the kernel and other core system files from running out of disk space due to users storing too much data in their home directories. – /usr - The user directory contains is user application. Usually the /usr directory does not grow that much in size and is fairly static. Design hard disk layout Common Partition Schemes –/var - The /var directory contains system log files. Logs files, especially if not maintained properly, can rapidly fill up disk space. By placing the /var directory on a different drive the rest of the system is protected from running out of disk space. –/tmp - The /tmp directory is used to house all temporary files. The directory should be cleaned upon reboot or when users log out but often files are left behind. Over time this can cause the system to run out of disk space. Placing /tmp in its own directory protects the rest of the system form this. Design hard disk layout How to Partition Using fdisk The fdisk command takes the block device you wish to partition as a parameter. For example to partition the master drive on the primary connector for a SATA drive the command would be: fdisk /dev/sda The fdisk utility provides you with a command prompt to create and delete partitions on block devices. Pressing “m” at the prompt will provide you with a list of possible actions to perform on the Design hard disk layout How to Partition Using fdisk Command action options: • a toggle a bootable flag • b edit bsd disklabel • c toggle the dos compatibility flag • d delete a partition • l list known partition types • m print this menu • n add a new partition • o create a new empty DOS partition table Design hard disk layout How to Partition Using fdisk • p print the partition table • q quit without saving changes • s create a new empty Sun disklabel • t change a partition's system id • u change display/entry units • v verify the partition table • w write table to disk and exit • x extra functionality (experts only) Design hard disk layout Filesystem types in Linux A filesystem is a way of storing data in a computer- accessible form on the hard disk. Different filesystems have different algorithms and structures to determine where the data and indexing information, needed by the computer to find data, will be stored. Meta-data relating to the organisation of the filesystem is stored in areas of the disk called superblocks. Superblocks contain critical information for the computer to find files and data on disk. Design hard disk layout Filesystem types in Linux Some popular Linux filesystems include: • ext2 – the oldest and most well supported filesystem on Linux machines. • ext3 - an extension of the ext2 filesystem which adds journaling support • ext4 – an extension of the ext3 filesystem, supporting bigger volumes, more subfolders handled (up to 32000), extents and pre-allocation handling, etc. • reiserfs - an enhanced journaling filesystem written by Hans Reiser Design hard disk layout Managing Swap space Swap space does not contain a file system but is accessed in raw mode by the Linux kernel. By passing a filesystem has some speed advantages which is crucial for swap space. After creating the disk partition to be used as swap space , you will need to activate it. For example: swapon /dev/sda2 During system insallation this will be done automatically for you. Information on the swap partition can be displayed with swapon. swapon -s Design hard disk layout Install a boot manager A boot loader is installed in the MBR. When a system starts, it loads what is in the MBR to RAM. Under Linux there are two main boot loaders: • Lilo: LInux LOader. • Grub: GRand Unified Boot Loader. A boot loader allows you to select the image that you would like to boot from. A system can contain multiple images (operating systems). Design hard disk layout Install a boot manager Grub can be installed, either by editing the grub configuration file located at /boot/grub/grub.conf or /boot/grub/menu.lst and running grub-install or by invoking the grub shell. When referring to hard disks and partition grub uses the convention (hdx) for hard disks, irrespective of whether they are PATA or SATA disks, and (fdx) for floppy disks, where x refers to the disk number as seen by the BIOS. When a reference to a partition is need the conventions (hdx,n) or (fdx,n) is used, where n is the partition numbered from 0. Design hard disk layout Install a boot manager default=0 timeout=10 splashimage=(hd0,0)/grub/splash.xpm.gz title Linux (2.4.18-14) root (hd0,0) kernel /vmlinuz-2.4.18-14 ro root=/dev/hda5 initrd /initrd-2.4.18-14.img Design hard disk layout Install a boot manager default image that will boot by default (the first entry is 0) timeout prompt timeout in seconds title name of the image root where the 2nd stage bootloader and kernel are e.g (hd0,0) is /dev/hda1 kernel path for the kernel starting from the previous root e.g /vmlinuz ro read-only root the filesystem root initrd path to the initial root disk Design hard disk layout Install a boot manager To install the first stage MBR loader on /dev/hda with grub- install you would run the command grubinstall (hd0) Alternatively grub can be installed through the grub shell but still requires the grub.conf/menu.lst file. The grub shell can be entered by typing grub. To install the boot loader you need to run the following commands in the shell: root (hd0,0) setup (hd0) Managing Shared Libraries Manage shared libraries A library is a set of functions that programs can use to implement their functionalities. When building (linking) a program, those libraries can be statically or dynamically linked to an executable. Static link means that the final program will contain the library function within its file (lib.a). Dynamic link means that the needed libraries are loaded into RAM when the program executes (lib.so). Managing Shared Libraries Manage shared libraries In order to find libraries, required by an application at runtime, Linux needs to know where to find them. By default Linux looks in the following trusted locations for library files: • /lib: - Used mainly by /bin programs.