Tài liệu LPI-101 Junior Level Administration

Tài liệu Tài liệu LPI-101 Junior Level Administration: Version 2.0 Lưu hành nội bộ LPI-101 Junior Level Administration Exam: 117-101 INDEX Chapter 1: Introduction to Linux Chapter 2: Linux Fundamentals Chapter 3: Hardware & Architecture Chapter 4: Install a Linux system Chapter 5: Working on the command line Chapter 6: Process text streams using filters Chapter 7: Perform basic file management Chapter 8: Perform basic file editing operations using vi Chapter 9: The XWindow system Chapter 10: Make and install programs from source Chapter 11: Package Management – RPM & DPKG Chapter 12: Find system files Chapter 13: Search text files using regular expressions Chapter 14: Create and maintain the Linux filesystems Chapter 15: Control mounting and managing quota Chapter 16: Manage files and directories Chapter 17: Manage processes 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 10 January 2007 Introduction to Linux Chapter 01 22 Last updated: 10 January 2007 Objectives ƒ Ans...

pdf621 trang | Chia sẻ: honghanh66 | Lượt xem: 906 | Lượt tải: 0download
Bạn đang xem trước 20 trang mẫu tài liệu Tài liệu LPI-101 Junior Level Administration, để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên
Version 2.0 Lưu hành nội bộ LPI-101 Junior Level Administration Exam: 117-101 INDEX Chapter 1: Introduction to Linux Chapter 2: Linux Fundamentals Chapter 3: Hardware & Architecture Chapter 4: Install a Linux system Chapter 5: Working on the command line Chapter 6: Process text streams using filters Chapter 7: Perform basic file management Chapter 8: Perform basic file editing operations using vi Chapter 9: The XWindow system Chapter 10: Make and install programs from source Chapter 11: Package Management – RPM & DPKG Chapter 12: Find system files Chapter 13: Search text files using regular expressions Chapter 14: Create and maintain the Linux filesystems Chapter 15: Control mounting and managing quota Chapter 16: Manage files and directories Chapter 17: Manage processes 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 10 January 2007 Introduction to Linux Chapter 01 22 Last updated: 10 January 2007 Objectives ƒ Answer the question : Why Linux ? ƒ List some of the key companies using Linux today ƒ Describe the “Value Proposition” associated with Linux 33 Last updated: 10 January 2007 Why Linux ? (becomes popularly) ƒ Linux is a source opened operating system (OS) with all the features of other OSs and it’s free ƒ It’s a very stable, quality, flexible OS ,being continually developed by hundreds of thousands of independent programmers from around the world 44 Last updated: 10 January 2007 Companies using Linux today ƒ Fujitsu ƒ Sony ƒ Amazon.com ƒ Google ƒ and many more ƒ IBM ƒ HP ƒ Cisco ƒ Sun Microsystems ƒ Hitachi -There are many companies using Linux nowadays and the list is growing day after day, even Microsoft -Amazon.com is a online largest bookstore on Internet, the most popular website all over the world with millions visitings per day. -Google is known as the best search engine on worldwide -Germany, Australia, Brazil, are using Linux in government organizations. Even ,China has a OS for themselves based on Linux - Red Flag. 55 Last updated: 10 January 2007 What can the Linux do ? ƒ Linux is used in many ways. It’s deployed as a server, development or workstation with emerging technologies : ª E-mail Servers ª Database Servers ª Network Routers ª And a host of other workstation applications, ªWeb Hosting ª Softwares Development ª File and Print services ª Document Publishing 66 Last updated: 10 January 2007 The “Value” Proposition ƒ Reliability ƒ Scalability ƒ Security ƒ ROI (Return On Investment) ƒ TCO (Total Cost of Ownership) Reliability – You can easily manage the necessary workloads in today’s business environment . – Linux machine can do as a FTP server, Web server, Mail server, DHCP server, DNS server, and run smoothly. – You do NOT need to reboot machine after installing new softwares or services. – Linux machine has never been halted. Scalability – The release of the 2.4 kernel can handle large business workloads that once could only be addressed by closed, proprietary platforms and solutions. Security – The open source model allows for expert auditing and “self” policing of code prior to release – When problems are found, fixes are developed and tested by the group of worldwide programmers. – Viruses are almost non-existent on Linux. 7ROI (Return On Investment) –The open source licensing model allows for no per unit fees or licensing charges. This will significantly reduce IT infrastructure expense when companies are expanded. TCO (Total Cost of Ownership) –Each Linux administrator can maintain a large number of servers and clients. This reduces the total cost of ownership of Linux versus Windows, Netware and other PC platforms. 88 Last updated: 10 January 2007 Summary • Answer the question : Why Linux ? • List some of the key companies using Linux today • Describe the “Value Proposition” associated with Linux 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 10 January 2007 Linux Fundamentals Chapter 02 22 Last updated: 10 January 2007 Objectives • Describe the history of Linux • Describe the General Public License • List the benefits and limitations of Linux • Identify Linux system administration tasks 33 Last updated: 10 January 2007 History of Linux • Linux was created by Linus Tovards in 1991. • It’s based on Minix, a UNIX-liked system, widely used as a teaching • The ability to see the source code. it now became even better than many commercial Unix packages. In 1991, Linus Benedict Torvalds was a second year student of Computer Science at the University of Helsinki and a self-taught hacker. The 21 year old sandy haired soft-spoken Finn loved to tinker with the power of the computers and the limits to which the system can be pushed. But all that was lacking was an operating system that could meet the demands of the professionals. MINIX was good, but still it was simply an operating system for the students, designed as a teaching tool rather than an industry strength one. In August 25, 1991 the historic post was sent to the MINIX news group by Linus ..... /------------------------------------------------------------ From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds) Newsgroups: comp.os.minix Subject: What would you like to see most in minix? Summary: small poll for my new operating system Message-ID: Date: 25 Aug 91 20:57:08 GMT Organization: University of Helsinki Hello everybody out there using minix - I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. I'd like any feedback on things people like/dislike in minix, as my OS resembles it somewhat (same physical layout of the file-system (due to practical reasons) among other things). I've currently ported bash(1.08) and gcc(1.40),and things seem to work.This implies that I'll get something practical within a few months, andI'd like to know what features most people would want. Any suggestions are welcome, but I won't promise I'll implement them :-) Linus (torvalds@kruuna.helsinki.fi) PS. Yes - it's free of any minix code, and it has a multi-threaded fs. It is NOT protable (uses 386 task switching etc), and it probably never will support anything other than AT-harddisks, as that's all I have :-(. \------------------------------------------------------------ 4As it is apparent from the posting, Linus himself didn't believe that his creation was going to be big enough to change computing forever. Linux version 0.01 was released by mid September 1991, and was put on the net. Enthusiasm gathered around this new kid on the block, and codes were downloaded, tested, tweaked, and returned to Linus. 0.02 came on October 5th, along with this famous declaration from Linus. Linux version 0.03 came in a few weeks. By December came version 0.10. Still Linux was little more than in skeletal form. It had only support for AT hard disks, had no login ( booted directly to bash). version 0.11 was much better with support for multilingual keyboards, floppy disk drivers, support for VGA,EGA, Hercules etc. The version numbers went directly from 0.12 to 0.95 and 0.96 and so on. Soon the code went worldwide via ftp sites at Finland and elsewhere. Soon Linus faced some confrontation from none other than Andrew Tanenbaum, the great teacher who wrote MINIX. In a post to Linus, Tanenbaum commented: /------------------------------------------ " I still maintain the point that designing a monolithic kernel in 1991 is a fundamental error. Be thankful you are not my student. You would not get a high grade for such a design :-)" (Andrew Tanenbaum to Linus Torvalds) \------------------------------------------ Linus later admitted that it was the worst point of his development of Linux. Tanenbaum was certainly the famous professor, and anything he said certainly mattered. But he was wrong with Linux, for Linus was one stubborn guy who won't admit defeat. Tanenbaum also remarked that : "Linux is obsolete". Now was the turn for the new Linux generation. Backed by the strong Linux community, Linus gave a reply to Tanenbaum which seems to be most fitting: /------------------------------------------ Your job is being a professor and researcher: That's one hell of a good excuse for some of the brain-damages of minix. (Linus Torvalds to Andrew Tanenbaum) \------------------------------------------ And work went on. Soon more than a hundred people joined the Linux camp. Then thousands. Then hundreds of thousands. This was no longer a hackers toy. Powered by a plethora of programs from the GNU project, Linux was ready for the actual showdown. It was licensed under GNU General Public License, thus ensuring that the source codes will be free for all to copy, study and to change. Students and computer programmers grabbed it. 55 Last updated: 10 January 2007 The Free Software Model • Linux is open source software. All the source code which makes up Linux itself is covered by the GNU General Public License (GPL), which is copyrighted by the Free Software Foundation (FSF) • A crucial aspect of free software is that users are free to make modification, free to cooperate, free to share their bug fixes and improvements •Creating, running and selling proprietary software under Linux is allowed and even encouraged (for example Oracle Database ) because it’s a use of the system rather than a derivative from the Linux sources. •If developers and companies take GPL’d source code and incorporating it into their own non-GPL projects - this is strictly forbidden. •This license is intended allow free use and redistribution of program’s source code as well as any programs derived therefrom. •Use and redistribution GPL softwares is free. You’re allowed to charge for copies of the softwares but can’t prevent others from freely copying it. •If you create and redistribute derivatives of GPL product, they must be covered by the same license as the orginal. 66 Last updated: 10 January 2007 Linux Features • Hardware • Loadable Device Modules • Software • GUI Windows Mangers • Programming Languages Hardware –Runs on many platforms : Alpha, AMD “Hammer” (x86-64 bit), Intel, MIPS, PowerPC, Sparc, Loadable Device Modules –Hardware and software can be added while the system is running. This eliminates the need to restart systems and results in lower downtime and greater reliability Software –To find out softwares works on Linux, check Linux software sites : GUI Windows Mangers –Supports GNOME, KDE, Window Maker,... Programming Languages –C, C++, FORTRAN, Java, Pascal, Perl, Python, PHP,... 77 Last updated: 10 January 2007 Linux Advantages • GUI is optional • Remote Administration is Easy • Rebooting is Uncommon • Viruses Are Almost Non-existent • Greater Security GUI is optional –Linux does not require GUI to function. Using Linux without a windowing system also reduces security risks when Linux system is linked to Internet. Remote Administration is Easy –Linux allows you to remotely handle your system and maintenance tasks, via a network with a command line interface or GUI utilities. Rebooting is Uncommon –The uptime of a Linux system is usually measured in months, even years. System only requires to boot when upgrade hardware or kernel. Viruses Are Almost Non-existent –Programs on Linux run as users, NOT as root, it can not modify important system files. Greater Security –Thousands of programmers examine free software code regularly will quickly discover and repair bugs. So, the security of the code increases greatly whereas in a closed environment 88 Last updated: 10 January 2007 Linux Limitations • There is no formal quality assurance program • SMP Scalability : only scales to up to 16 processors • Documentation is abundant but uneven in quality • ... 99 Last updated: 10 January 2007 Linux Distributions • Debian GNU/Linux – • MandrakeSoft – • RedHat – • Slackware – • Novell SuSE – • TurboLinux – • ... 10 10 Last updated: 10 January 2007 Linux Standards • Linux strives for POSIX compliance. • POSIX is an IEEE specified interface definition for UNIX systems to conform. 11 11 Last updated: 10 January 2007 System Administration • Operator – perform system tasks. • Administrator – building a successful infrastructure, includes system and network design. The roles and responsibilities of a Linux administrator are very similar to other OS administrators, the specifics may differ from what they are used to do administration tasks: Linux administrator use text-based utilities while other OS (Windows) use GUI Operational –backup – recovery –add/remove users –changing password –monitoring system activities – Administrative –recovery planning –security, policy –procedures development –... 12 12 Last updated: 10 January 2007 Summary • Describe the history of Linux • Describe the General Public License • List the benefits and limitations of Linux • Identify Linux system administration tasks 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 10 January 2007 Hardware & Architecture Chapter 03 22 Last updated: 10 January 2007 Objectives • Describe a system boot process. • Understand hardware resource allocation (IRQ, I/O, DMA) • Overview hardware devices: – Network cards and PC Expansion Cards – IDE devices – SCSI devices – USB Devices – Different types of ports LPI Topics: 1.101.1 Configure Fundamental BIOS Settings Candidates should be able to configure fundamental system hardware by making the correct settings in the system BIOS. It also includes the correct setting for IRQ, DMA and I/O addresses for all BIOS administrated ports and settings for error handling. 1.101.3 Configure Modem and Sound cards Ensure devices meet compatibility requirements (particularly that the modem is NOT a win-modem), verify that both the modem and sound card are using unique and correct IRQ's, I/O, and DMA addresses, if the sound card is PnP install and run sndconfig and isapnp, configure modem for outbound dial-up, configure modem for outbound PPP | SLIP | CSLIP connection, set serial port for 115.2 Kbps 31.101.4 Setup SCSI Devices Candidates should be able to configure SCSI devices using the SCSI BIOS as well as the necessary Linux tools. They also should be able to differentiate between the various types of SCSI. This objective includes manipulating the SCSI BIOS to detect used and available SCSI IDs and setting the correct ID number for different devices especially the boot device. It also includes managing the settings in the computer's BIOS to determine the desired boot sequence if both SCSI and IDE drives are used. 1.101.5 Setup different PC expansion cards Candidates should be able to configure various cards for the various expansion slots. They should know the differences between ISA and PCI cards with respect to configuration issues. This objective includes the correct settings of IRQs, DMAs and I/O Ports of the cards, especially to avoid conflicts between devices. It also includes using isapnp if the card is an ISA PnP device. 1.101.6 Configure Communication Devices Candidates should be able to install and configure different internal and external communication devices like modems, ISDN adapters, and DSL switches. 1.101.7 Configure USB devices Candidates should be able to activate USB support, use and configure different USB devices. This objective includes the correct selection of the USB chipset and the corresponding module. It also includes the knowledge of the basic architecture of the layer model of USB as well as the different modules used in the different layers. 44 Last updated: 10 January 2007 Hardware • While Linux supports hardware and most device manufacturers provide Linux drivers, some hardwares does not work with Linux (e.g Winmodems). • Check a hardware compatibility list ( HCL ) at : • If you device isn’t listed on HCL, then check the manufacturer’s website to see if Linux drivers are available. 55 Last updated: 10 January 2007 System Boot process 1. First, the internal power supply turns on. • It takes a bit of time to generate enough power for the rest system. • When there is sufficient power, the processor is ready to execute and it looks to the BIOS ROM for instructions. 2. The BIOS performs the Power-On Self-Test (POST). • If there are no problems found during, then computer beeps once and continues with the boot process - Before the BIOS initiates the actual boot sequence, a built-in diagnostic program called POST checks the hardware and verifies that essential components are present and functioning. After verifying the components, it performs a memory test as the actual boot process begins. - If everything checks out correctly, BIOS emits a beep, otherwise BIOS will emit a series of beeps 66 Last updated: 10 January 2007 System Boot process 3. The BIOS looks for and executes the video card's BIOS program, and initializes the video card. 4. The BIOS looks for any other device ROMs that have BIOSes, such as ITE/ATA hard drives. 5. Now the BIOS displays the startup screen • The BIOS continues to perform more tests, such as the memory count-up test. • Any errors encountered at this point in the process will usually generate an error message on the screen. 77 Last updated: 10 January 2007 System Boot process 6. The BIOS takes more inventory of the hardware on the system. • Modern BIOSes initiate automatic settings at this stage • If the Plug and Play (PnP) standard is supported by the BIOS, then PnP devices are configured at this stage. 7. Now, the BIOS begins to search for a drive to boot. • When the target boot drive is identified, the BIOS looks for the boot information to start the OS. 8. The BIOS starts the process of booting the OS, using the information in the boot sector. 88 Last updated: 10 January 2007 BIOS and CMOS • The settings for the BIOS are stored in the Complementary Metal Oxide Semiconductor, or CMOS. • A small battery in the computer powers the CMOS memory setting, so the settings are retained when the computer is shut down. CMOS: The information includes : time, type and speed of the CPU, hard drive parameters, and the amount of RAM in the computer, 99 Last updated: 10 January 2007 Resource Allocation • Interrupt Requests (IRQ) • Input/output (I/O) addresses • Direct memory access (DMA) To allow peripherals and devices on the PC to communicate directly with system resources, in particular the CPU, the system allocates resources such as lines and channels for each device. These resources are Interrupt Request Lines (IRQ), Input/Output addresses and Direct Memory Access channels (DMA). 10 10 Last updated: 10 January 2007 IRQ • The Interrupt Request Lines allow devices to request CPU time. • The CPU will stop its current activity and process the instructions sent by the device. • IRQs range from 0 to 15. IRQs list: ------------------------- IRQ 0 System Timer IRQ 1 Keyboard IRQ 2 Some video cards IRQ 3 COM2, COM4 IRQ 4 COM1, COM3 IRQ 5 Sound Card IRQ 6 Floppy drive controller IRQ 7 LPT1 (printer port) IRQ 8 CMOS Clock IRQ 9 Redirected to IRQ2 IRQ 10 Free IRQ 11 Free IRQ 12 Free IRQ 13 Math Coprocessor IRQ 14 Hard Drive Controller IRQ 15 Free 11 11 Last updated: 10 January 2007 IRQs and their default devices Secondary ATAPI controller 15First LPT 7 Primary ATAPI controller 14Floppy disk controller 6 Math coprocessor13Some sound cards or second LPT 5 PS/2 Mouse 12COM1 or COM3 4 Varies11COM2 or COM4 3 Varies10Cascade from IRQs 8-15 2 Varies9Keyboard 1 Realtime clock (in CMOS)8System Timer 0 12 12 Last updated: 10 January 2007 I/O Address • These represent specific addresses in the system’s memory map. • The CPU will then communicate with the device by reading and writing to memory at the specified address. - Devices on a PC require a few bytes of RAM located at one or more input/output (I/O) addresses. The information stored within these addresses are shared with the rest of the system. - I/O Addresses are shown in hexadecimal notation. For example, the I/O address associated with COM2 is 0x02f8 13 13 Last updated: 10 January 2007 DMA • Certain devices can access the system’s memory through a DMA channel, • allowing them to write and process data without accessing the CPU. • This can enhance performance. - DMA are used primarily to transfer information to and from memory without the main CPU handling each bit. - Most PCs have eight DMA channels and are typically used by floppy drives, tape drives, and some sound cards. 14 14 Last updated: 10 January 2007 Listing Allocated Resources Command: ƒ dmesg ƒ lspci [-v] Keyworks: ƒ /proc/interrups ƒ /proc/ioports ƒ /proc/dma ƒ /proc/pci # cat /proc/interrupts CPU0 0: 373972114 XT-PIC timer 2: 0 XT-PIC cascade 8: 1 XT-PIC rtc 9: 197348 XT-PIC eth0 10: 30 XT-PIC sym53c8xx 11: 68713 XT-PIC sym53c8xx 14: 28 XT-PIC ide0 NMI: 0 ERR: 0 # lspci 00:00.0 Host bridge: ServerWorks CNB20LE Host Bridge (rev 05) 00:00.1 Host bridge: ServerWorks CNB20LE Host Bridge (rev 05) 00:01.0 PCI bridge: Digital Equipment Corporation DECchip 21152 (rev 03) 00:02.0 PCI bridge: Intel Corp. 80960RP [i960 RP Microprocessor/Bridge] (rev 05) 00:02.1 I2O: Intel Corp. 80960RP [i960RP Microprocessor] (rev 05) 00:04.0 Ethernet controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (rev 08) ... 15 15 Last updated: 10 January 2007 Network cards • The network interface card (NIC) must be supported by the kernel. • To get information about your current card using either of the following: – dmesg – lspci – scanpci – /sbin/lsmod – /proc/interrupts – /etc/modules.conf Commands: • dmesg : The program helps users to print out their bootup messages. • lspci : list all PCI devices • scanpci : scan/probe PCI buses • lsmod : program to show the status of modules in the Linux Kernel Configuration files: • /proc/interrupts : list of currently used interrupts • /etc/modules.conf : configuration file for loading kernel modules. 16 16 Last updated: 10 January 2007 PC Expansion Cards • ISA and PCI are the most common types of expansion cards. • Use pnpdump tool to scan the ISA bus for 'Plug and Play' (PnP) devices. • Since kernel 2.4 PnP initialisation is supported through a kernel module called isapnp.o • With the latest 2.4 kernel there is very little to be done in order to configure these. In the case of ISA buses however, and only with earlier kernels, it was necessary to scan the ISA bus in order to detect existing expansion cards (sound, ethernet, etc). • The isapnptools package provided the pnpdump tool which scanned the ISA bus for 'Plug and Play' (pnp) devices. The output would contain the chipset of the card together with I/O port, DMA and IRQ settings. This output would be redirected to /etc/isapnp.conf where changes could be made if needed. At boot time the isapnp tool would read isapnp.conf and would configure these ISA PnP devices. • Since kernel 2.4 PnP initialisation is supported through a kernel module called isapnp.o 17 17 Last updated: 10 January 2007 Floppy Drives • Have 3 connectors : motherboard, fd0 and fd1 18 18 Last updated: 10 January 2007 • Most hard drives and CD drives are IDE (Integrated Drive Electronics) and conform to AT Attachment Packet Interface (ATAPI). • IDE devices use a 40-pin ribbon to connect to ATAPI controllers • Most PCs have 2 ATAPI controllers: a primary and a secondary. IDE Drives 19 19 Last updated: 10 January 2007 IDE Drives • Each controller can connect to two different IDE drives with one drive designated as the master drive and the other as the slave drive. Controller Position Designation hddSlaveSecondary hdcMasterSecondary hdbSlavePrimary hdaMasterPrimary To optimize your hardware set up with IDE devices, it is best to have only one hard drive and one CD drive. 20 20 Last updated: 10 January 2007 SCSI (Small Computer System Interface) • Pronounced SKUH-zee • Designed to be a high-level, expandable, high- performance interface • SCSI is usually found in Servers and other high-end computers Since SCSI's creation in 1979, multiple forms of SCSI standards have been developed : SCSI-1, SCSI-2, and SCSI-3. They all have two things in common: •All SCSI devices are controlled by a host adapter •All SCSI devices are connected in series, with the last device using a terminator indicating that it is the final device in the chain 21 21 Last updated: 10 January 2007 Types of SCSI and Characteristics 80MBps12 m16-bitSCSI-3 (Ultra2 Wide SCSI) 40MBps3 m16-bitSCSI-3 (Ultra Wide SCSI) 20MBps3 m16-bitSCSI-2 (Wide SCSI) 10MBps3 m8-bitSCSI-2 (Fast SCSI) 5MBps6 m8-bitSCSI-1 SCSI Type Bus Cable Data Transfer There are two main types of SCSI interfaces: - an 8-bit interface with a bus that supports 8 devices, this includes the controller, so there is only space for 7 block devices (tapes, disks, etc) - a 16-bit interface (WIDE) with a bus that supports 16 devices including the controller, so there can only be 15 block devices. 22 22 Last updated: 10 January 2007 SCSI Identified • SCSI devices are uniquely identified using a set of 3 numbers called the SCSI ID: – 1. the SCSI channel – 2. the device ID number – 3. the logical unit number LUN The SCSI Channel Each SCSI adapter supports one data channel on which to attach SCSI devices (disc, CDROM, etc) These channels are numbered from 0 onwards. Device ID number Each device is assigned a unique ID number that can be set using jumpers on the disk. The IDs range from 0 to 7 for 8-bit controllers and from 0 to 15 for 16-bit controllers. Logical Units The Logical Unit Number (LUN) is used to differentiate between devices within a SCSI target number. This is used, for example, to indicate a particular partition within a disk drive or a particular tape drive within a multi-drive tape robot. It is not seen so often these days as host adapters are now less costly and can accommodate more targets per bus. 23 23 Last updated: 10 January 2007 SCSI Detection • All detected devices are listed in the /proc/scsi/scsi file. • scsi_info tool uses the information in /proc/scsi/scsi to printout the SCSI_ID and the model of a specified device. # cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: HP Model: 9.10GB C 80-F512 Rev: Type: Direct-Access ANSI SCSI revision: 02 Note: •That some systems, such as Fedora Core 2/3/.., do not include the scsi_info command (which is a part of the kernel-pcmcia-cs package). •The sg3_utils package contains a number of utilities for manipulating and interrogating aspects of the SCSI subsystem. # sginfo /dev/sda INQUIRY reponse (cmd: 0x12) --------------------------- Device Type 0 Vendor: HP Product: 9.10GB C 80-F512 Revision level: 24 24 Last updated: 10 January 2007 SCSI Device Numbering 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 Internal devices External devices – For SCSI, the type of SCSI bus determines the number of SCSI devices you can have on your computer – Each device is associated with a number that determines the priority in accessing the SCSI bus ( 0-7 , 0-15 ) – SCSI ID 7 is reserved for the SCSI host adapter since 7 has the highest priority. – SCSI numbering, going from highest to lowest in priority. Booting from SCSI disks • The system will boot from the device with SCSI ID 0 by default. This can be changed in the SCSI BIOS which can be configured at boot time. • If the PC has a mixture of SCSI and IDE disks, then the boot order must be selected in the systems BIOS first. 25 25 Last updated: 10 January 2007 SCSI Connecters ==> More from: 26 26 Last updated: 10 January 2007 USB • USB was supported in Kernel 2.2.7 but was not incorporated until the realease of 2.4 kernel • USB data transfer: – USB 1.0 : speed 12Mbs – USB 2.0 : speed from 12Mbps to 480Mbps The new USB 2.0 specification is developed by Intel, Microsoft, NEC, Compaq, Lucent and Phillips. USB 2.0 and current USB 1.1 specification didn't have much difference, still have the advantages like PnP (Plug-And-Play), maximum of 127 USB devices, 5V voltage and one IRQ requirement. But the most important change is transfer speed. - USB 1.0: Released in January 1996. Specified data rates of 1.5 Mbps (Low-Speed) and 12 Mbps (Full-Speed). Did not anticipate or pass-through monitors. Few such devices actually made it to market. - USB 1.1: Released in September 1998. Fixed problems identified in 1.0, mostly relating to hubs. Earliest revision to be widely adopted. - USB 2.0: Released in April 2000. Added higher maximum speed of 480 Mbps (now called Hi-Speed). Current revision. Allowed Low-Speed and Full-Speed to be designated as 2.0 compliant (a major confusion factor to the market). 27 27 Last updated: 10 January 2007 USB ehci-hdc.oEHCI (USB v2.0) usb-uhci.oUHCI (Intel) usb-ohci.oOHCI (Compaq) Kernel ModuleHost controler • Three type of USB host controlers: Compaq, most PowerMacs, iMacs, and PowerBooks, OPTi, SiS, ALi OHCI Intel and VIA chipsetsUHCI USB 2.0 Support requires one of UHCI or OHCI.EHCI ChipsetDriver 28 28 Last updated: 10 January 2007 Displaying USB information • Partial contents of /proc/bus/usb/devices • Using the lsusb command • Using the usbmodules command $ cat /proc/bus/usb/devices T: Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0000 ProdID=0000 Rev= 2.06 S: Manufacturer=Linux 2.6.16.9-ctt uhci_hcd S: Product=UHCI Host Controller S: SerialNumber=0000:00:1d.1 C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 0mA I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms --------- $ usbmodules --device /proc/bus/usb/001/001 usb-storage 29 29 Last updated: 10 January 2007 Hotplugging • used to keep the state of the operating system updated when pluggable hardware devices are added or removed. • In most cases the kernel signals an event by passing parameters to the script /sbin/hotplug. • On Debian systems an alternative to hotplug is provided with the usbmgr package. • This hotplug script runs all the scripts in /etc/hotplug.d (the default is default.hotplug) which in turn starts the appropriate agent listed in /etc/hotplug. • The names of the agents correspond to different attachment types such as ieee1394, net, pci, scsi and usb. • There are two commands that your system might use to handle hot plugging of USB devices, usbmgr (Debian system) or hotplug. According to which you are using, you will find configuration files in the /etc/usbmgr or /etc/hotplug directories. Newer systems are more likely to have hotplug. 30 30 Last updated: 10 January 2007 Other Peripherals • On the back of standard PCs there are ports for specific peripherals: – PS/2 : Used for mice and keyboards – COM : COM is short for serial communications port. Older mice and modems use this port – LPT : The LPT ports are used by printers 31 31 Last updated: 10 January 2007 0x3f8/dev/ttyS04COM1 0x2f8/dev/ttyS13COM2 0x3e8/dev/ttyS24COM3 0x2e8/dev/ttyS33COM4 I/OLinuxIRQDOS • COM ports are also known as serial ports. • COM ports are associated with specific IRQ and I/O addresses COM Ports The modem uses a serial interface for communications. Information is sent through the telephone line as a sequence of bits (serial) over two wires (in and out). Incoming sequential data is translated into parallel data for the PC bus and vice versa for bits of data leaving the computer. The translation is done by a UART chip located on the serial port of the motherboard or inside an internal (PCI) modem. To see which serial ports were detected at boot time on the system, we do the following: # dmesg | grep ttyS ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A One can also use setserial to scan the serial devices: # setserial -g /dev/ttyS[01] /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 /dev/ttyS1, UART: 16550A, Port: 0x02f8, IRQ: 3 -g option this utility will tell you which serial devices are in use 32 32 Last updated: 10 January 2007 Printer Ports (LPT) I/OLinuxIRQDOS 0x278/dev/lp15LPT2 0x378/dev/lp07LPT1 • Most PCs have one physical printer port, though you can get an adapter to set up a second LPT if needed. 33 33 Last updated: 10 January 2007 Summary • Describe a system boot process. • Understand hardware resource allocation (IRQ, I/O, DMA) • Overview hardware devices: – Network cards and PC Expansion Cards – IDE devices – SCSI devices – USB Devices – Different types of ports Key files, terms, and utilities include: /proc/dma /proc/interrupts /proc/ioports /proc/pci pnpdump(8) isapnp(8) setserial(8) lspci(8) SCSI ID /proc/scsi/ scsi_info /proc/dma /proc/interrupts /proc/ioports usb-uhci.o usb-ohci.o /etc/usbmgr/ usbmodules 34 Practices: 1. Use the dmesg command to view the /var/log/dmesg file. Search for keywords such as USB, tty or ETH0. -What are the name of the eth0 network card? __________________________________________________________ - What are the IRQs for the first two serial ports? __________________________________________________________ 2. Investigate the contents of the following files: /proc/ioports /proc/interrupts /proc/pci /proc/dma 3. The PCI bus: - Investigate the output of lspci -v and scanpci –v. What type of ethernet card is present? __________________________________________________________ - Verify that there are as many ‘bus ’ entries listed with lspci and /proc/pci. __________________________________________________________ 4. USB tools: -Use lsmod and lsusb to determine which host controller is used on your system, UHCI, OHCI or EHCI (for USB v 2.0). __________________________________________________________ 5. SCSI devices -Investigate the contents of the file /proc/scsi/scsi. Which SCSI ID is present? __________________________________________________________ 35 Solutions: 1. Use the dmesg command to view the /var/log/dmesg file. Search for keywords such as USB, tty or ETH0. # dmesg | grep usb usbcore: registered new driver usbfs usbcore: registered new driver hub usbcore: registered new driver hiddev usbcore: registered new driver usbhid drivers/usb/input/hid-core.c: v2.0:USB HID core driver SELinux: initialized (dev usbfs, type usbfs), uses genfs_contexts # dmesg | grep tty serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A 00:07: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A 00:08: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A --> The first two serial ports use IRQ4 and IRQ3. # dmesg | grep eth0 e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection e1000: eth0: e1000_watchdog_task: NIC Link is Up 100 Mbps Full Duplex --> This system use “Intel Pro/1000” Network card. 2. Investigate the contents of the following files: # cat /proc/interrupts CPU0 0: 437726085 XT-PIC timer 2: 0 XT-PIC cascade 8: 1 XT-PIC rtc 9: 772300 XT-PIC eth0 10: 30 XT-PIC sym53c8xx 11: 74187 XT-PIC sym53c8xx 14: 28 XT-PIC ide0 NMI: 0 ERR: 0 --> On this example, the NIC use IRQ9 # cat /proc/ioports # cat /proc/pci # cat /proc/dma 36 3. The PCI bus: - Investigate the output of lspci -v and scanpci –v. # lspci -v 01:01.0 Ethernet controller: Intel Corp. 82547GI Gigabit Ethernet Controller Subsystem: Intel Corp.: Unknown device 342f Flags: bus master, 66Mhz, medium devsel, latency 0, IRQ 16 Memory at fc3e0000 (32-bit, non-prefetchable) [size=128K] I/O ports at ac00 [size=32] Capabilities: [dc] Power Management version 2 # scanpci -v pci bus 0x0001 cardnum 0x01 function 0x00: vendor 0x8086 device 0x1075 Intel Corp. 82547GI Gigabit Ethernet Controller CardVendor 0x8086 card 0x342f (Intel Corp., Card unknown) STATUS 0x0238 COMMAND 0x0007 CLASS 0x02 0x00 0x00 REVISION 0x00 BIST 0x00 HEADER 0x00 LATENCY 0x00 CACHE 0x08 BASE0 0xfc3e0000 addr 0xfc3e0000 MEM BASE2 0x0000ac01 addr 0x0000ac00 I/O MAX_LAT 0x00 MIN_GNT 0xff INT_PIN 0x01 INT_LINE 0x09 - Verify that there are as many ‘bus ’ entries listed with lspci and /proc/pci. # lspci 00:00.0 Host bridge: ServerWorks CNB20LE Host Bridge (rev 05) 00:00.1 Host bridge: ServerWorks CNB20LE Host Bridge (rev 05) 00:01.0 PCI bridge: Digital Equipment Corporation DECchip 21152 (rev 03) 00:02.0 PCI bridge: Intel Corp. 80960RP [i960 RP Microprocessor/Bridge] (rev 05) 00:02.1 I2O: Intel Corp. 80960RP [i960RP Microprocessor] (rev 05) 00:04.0 Ethernet controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (rev 08) 00:0f.0 ISA bridge: ServerWorks OSB4 South Bridge (rev 4f) 00:0f.1 IDE interface: ServerWorks OSB4 IDE Controller 01:04.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1010 Ultra3 SCSI Adapter (rev 01) 01:04.1 SCSI storage controller: LSI Logic / Symbios Logic 53c1010 Ultra3 SCSI Adapter (rev 01) 01:06.0 Ethernet controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (rev 08) 01:07.0 VGA compatible controller: ATI Technologies Inc Rage XL (rev 27) # cat /proc/pci PCI devices found: Bus 0, device 0, function 0: Class 0600: PCI device 1166:0009 (rev 5). Master Capable. Latency=64. Bus 37 4. USB tools: -Use lsmod and lsusb to determine which host controller is used on your system, UHCI, OHCI or EHCI (for USB v 2.0). # lsmod Module Size Used by Not tainted autofs 13268 0 (autoclean) (unused) pcnet32 18240 1 mii 3976 0 [pcnet32] ipt_REJECT 3928 6 (autoclean) iptable_filter 2412 1 (autoclean) ip_tables 15096 2 [ipt_REJECT iptable_filter] keybdev 2944 0 (unused) mousedev 5492 0 (unused) hid 22148 0 (unused) input 5856 0 [keybdev mousedev hid] usb-uhci 26348 0 (unused) usbcore 78784 1 [hid usb-uhci] ext3 70784 3 jbd 51892 3 [ext3] BusLogic 100796 3 sd_mod 13452 6 scsi_mod 107128 2 [BusLogic sd_mod] 5. SCSI devices -Investigate the contents of the file /proc/scsi/scsi. Which SCSI ID is present? # cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: SEAGATE Model: ST336807LW Rev: 0C01 Type: Direct-Access ANSI SCSI revision: 03 38 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 18 January 2007 Install a Linux system Chapter 04 22 Last updated: 18 January 2007 Objectives • Identify the types of system, hardware, and network setting necessary for Linux installation • Describe the need for pre-installation procedures • Describe the different types of file system: ext2, ext3, ReiserFS, XFS and JFS • Describe the procedures for CDROM or network installation • List and describe different types of boot loaders • List and describe system initialization, boot sequences, and boot files LPI Topics 1.102.1 Design hard disk layout Candidates should be able to design a disk partitioning scheme for a Linux system. This objective includes allocating filesystems or swap space to separate partitions or disks, and tailoring the design to the intended use of the system. It also includes placing /boot on a partition that conforms with the BIOS' requirements for booting. 1.102.2 Install a boot manager Candidate should be able to select, install, and configure a boot manager. This objective includes providing alternative boot locations and backup boot options (for example, using a boot floppy). 33 Last updated: 18 January 2007 Installation options • Identify Your Hardware – You will be required to identify your hardware during the installation process. The easiest method is to gather your system/component documentation • You can install from: – local CD-ROM – ISO file – Network share Network installation will allow you to install from a volume on a network server, a shared CD-ROM on a remote host, or directly off Internet using ftp or http protocols 44 Last updated: 18 January 2007 Type of Servers and Workstations Personal Desktop –Most of user application, i.e: XWindows, OpenOffice, Music tools, ... Workstation –Most of user application and development component. Server –Server component, i.e: Webserver, Samba server, ftp server, .... Custom –You can select any component as you need. –This mode is useful for expert user. Upgrade Existing System –Only use when you need upgrade your system to new linux version. 55 Last updated: 18 January 2007 Installing From a CD-ROM • It’s commonly used to install Linux. Be sure to create a boot floppy if the distribution or your system is NOT capable of booting from a CD-ROM • Creating a boot floppy : – On Linux : use dd command – On Windows : use rawrite.exe program For example: The SUSE linux does not distrubute iso file for all user. You must pay to get it. Another way, you can install SuSe linux direct from SuSe FTP. So, You must have boot disk before you can install it to your system. 66 Last updated: 18 January 2007 Istallation from Network • FTP, HTTP – Install a Linux direct from FTP or HTTP host. – Example: ftp://ftpserver/linux • NFS server – Install a Linux from NFS server. – Example: nfs://nfsserver/linux If you will be connecting to a network without DHCP, ask these information from administrator : –IP address –Network –Gateway IP address –Name server IP address –Domain name –Hostname If you have DHCP, these information will be provided to the client system automatically 77 Last updated: 18 January 2007 General Steps • Install or Upgrade • Disk Partitioning • Software Choices • Hardware Configuration • System Settings • X Windows System Installation 88 Last updated: 18 January 2007 Disk Partitioning • Disk partitioning: – Divide disk into separate parts, sections. • It prevents unwanted changes affecting to entire disk; • and protects user disk space, improves performance, • Partition type: – primary • up to 4 primary partitions on a drive. – extended • extended partition can be used as a container for logical partitions. – logical • part of extend partition. primary –up to 4 primary partitions on a drive. extended –to get more partitions –extended partition can be used as a container for logical partitions. –only one extended partition per drive. logical –You can create many logical partitions from extend partition. 99 Last updated: 18 January 2007 Disk partition sample • With a 5GB hard disk, you can partition as follow : /boot 100 M / 500 M /usr 3000 M /home 500 M /tmp 200 M /var 200 M /opt 250 M (not required) SWAP 250 M 10 10 Last updated: 18 January 2007 Swap Space • Linux actually uses paging instead of swapping. • Linux can be run without any swap space • A swap partition type: 82 • Can use linux fdisk tool to create swap partition. –Most of people still use the word swapping Swapping traditionally refers to swapping entire processes out to disk. Linux doesn't do that; it pages parts of processes out to disk (virtual memory or swap space) –Linux can be run without any swap space but the performance of the system will suffer. Therefore, it's best if swap space is set aside during the install process –A swap partition is type 82 if you are using the fdisk utility. The amount of swap space you will need depends on the the kinds of applications you intend to run Notes: –Linux can use swap file too. We will discussion to this Topic in LPI-201 11 11 Last updated: 18 January 2007 File System Types • Linux has the capability to support a variety of file systems: ext2, ext3, ReiserFS, JFS , XFS, • ext2 – Development by Redhat – Simple, reasonably fast, reasonably robust – No journaling capability • ext3 – Same as ext2, but has journaling • ReiserFS – First journaling file system supported by Linux ext2 –was implemented in the 2.2 kernel and is found on most Linux machines. While simple and efficient, ext2fs lacks journaling features ext3 –allowing files names up to 256 characters and file system sizes up to 4 terabytes, ext3fs is very similar to ext2fs structurally: in fact, changing a ext2fs file system to an ext3fs is not difficult. The major addition to ext2fs in ext3fs is journaling. Journaling reduces the disk check time to a minimum after a crash and helps reduce the risk of lost data ReiserFS –is another journaling file system as well as a "balanced tree” system. For more information, visit website: – XFS –is also a journaling file system, designed by SGI (Silicon Graphics). It can support very large file size : 8,129 petabytes, about 8,129,000,000 gigabytes JFS –Journaling File System, designed by IBM Notes: Journalling filesystem –reduced time spent recovering a filesystem after a crash –and is therefore in high demand in environments 12 12 Last updated: 18 January 2007 Drive and Partition Names ƒ Drive name: ƒ IDE : /dev/hdx (x = a,b,c,d) ƒ SCSI : /dev/sdx (x= a,b,c,b) ƒ Partition name : ƒ IDE : /dev/hdxn (n=1,2,..) ƒ SCSI : /dev/sdxn (n=1,2,..) Most of hardware on linux is accessed by device files. You can locate it from /dev directory. Hard disk descriptors in /dev begin with hd (IDE) or sd (SCSI), a SCSI tape would be st, and so on. Since a system can have more than one block device, an additional letter is added to the descriptor to indicate which device is considered. Physical block devices hda Primary Master hdb Primary Slave hdc Secondary Master hdd Secondary Slave sda First SCSI disk sdb Second SCSI disk 13 13 Last updated: 18 January 2007 M B R hda1 hda2 hda3 hda4 • Primary Partitions (1,2,3,4) • Primary Partitions (1,2,3) and logical (5,6,7) M B R hda1 hda2 hda3 hda5 hda6 hda7 Drive and Partition Names Disks can further be partitioned. To keep track of the partitions a number is added at the end of each physical device. Partitions hda1 First partition on first hard disk hda2 Second partition on first hard disk sdc3 Third partition on third SCSI disk IDE type disks allow 4 primary partitions, one of which can be extended. The extended partition can further be divided into logical partitions. There can be a maximum of 62 partitions (primary and logical, excluding the extended). Notes: The first logical partition always assign the fifth number. i.e.: /dev/hda5 14 14 Last updated: 18 January 2007 • It’s used to partition a hard disk in preparation for a Linux installation • You must have a plan before partitioning: – number of partitions – what they will be used for – and the space required for each partition Using fdisk -List all disk and partition on system. [root@localhost root]# fdisk -l Disk /dev/sda: 128 heads, 32 sectors, 563 cylinders Units = cylinders of 4096 * 512 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 50 102384 83 Linux /dev/sda2 51 484 888832 83 Linux /dev/sda3 485 563 161792 82 Linux swap Disk /dev/sdb: 64 heads, 32 sectors, 102 cylinders Units = cylinders of 2048 * 512 bytes Device Boot Start End Blocks Id System 15 15 Last updated: 18 January 2007 fdisk Commands a toggle a bootable flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty MS-DOS partition table p print the partition table q quit without saving changes t change a partition's system id v verify the partition table w write table to disk and exit x extra functionality (experts only) Use the t command to assign a partition ID type to each partition that you’re going to create ext2 : 83 swap : 82 16 16 Last updated: 18 January 2007 Partition Attributes • Primary or extended partition – specify one as extended if you want to add logical partitions • Partition number – begin at one, unless you are keeping an existing partition • General category: – Specify the first cylinder to be used – The last cylinder to be used, or specify the total space required by entering the following: • +nK or • +nM + is the plus symbol n is the number of Kilobytes or Megabytes K is Kilobytes M is Megabytes 17 Demo: using fdisk - Slit /dev/sdb to multi partition – create first primary partition [root@localhost root]# fdisk /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-102, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-102, default 102): +10M Command (m for help): p Disk /dev/sdb: 64 heads, 32 sectors, 102 cylinders Units = cylinders of 2048 * 512 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 11 11248 83 Linux - Create extend partition Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 2 First cylinder (12-102, default 12): Using default value 12 Last cylinder or +size or +sizeM or +sizeK (12-102, default 102): Using default value 102 18 - Create first logical partition Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (12-102, default 12): Using default value 12 Last cylinder or +size or +sizeM or +sizeK (12-102, default 102): +10M Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (23-102, default 23): Using default value 23 Last cylinder or +size or +sizeM or +sizeK (23-102, default 102): Using default value 102 Disk /dev/sdb: 64 heads, 32 sectors, 102 cylinders Units = cylinders of 2048 * 512 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 11 11248 83 Linux /dev/sdb2 12 102 93184 5 Extended /dev/sdb5 12 22 11248 83 Linux /dev/sdb6 23 102 81904 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. save tasks and exit 19 19 Last updated: 18 January 2007 Other Partitioning Methods • There are other disk partitioning: – cfdisk • uses interactive text menus instead of commands – Partition Magic – Disk Druid – parted – ... The parted is an open source tool that aims to do more-or-less what PartitionMagic does. GNU Parted features a simpler, text-based user interface, though, and it's not nearly as polished. Nonetheless, GNU Parted is extremely useful in helping to manage partitions as your needs for disk storage space change. Before proceeding with any partition resizing tool, be aware that dynamic partition resizing is inherently dangerous! A power outage, bug, or other problem during dynamic partition resizing can wreak havoc with your partitions -- possibly even with partitions you're not modifying. You should always back up your data before using one of these tools! To resize a partition, GNU Parted must resize not just the partition (that part's easy), but also the data structures on the partition -- that is, the filesystem on the partition. Unfortunately, resizing a filesystem is a tricky proposition. If a filesystem is shrunk, data stored beyond the new end point of the partition must be moved. If a filesystem is expanded, fixed data structures may need to be expanded, necessitating the movement of files or other data structures. Overall, expanding a filesystem is usually easier than shrinking one. It's also usually easier to change the filesystem's end point than to change its starting point. In fact, GNU Parted supports resizing ext2fs, ext3fs, and ReiserFS partitions only by changing the end point. More about the parted: 20 20 Last updated: 18 January 2007 Software choices • Decide what software or packages will be installed Select software When you choose “Custom” install, you can select any component as you need by check on it. 21 21 Last updated: 18 January 2007 Hardware Configuration • Basic hardware is usually configured after the OS and the software has been installed, such as: – mouse – video card – monitor – network card – ..... The GUI environment, X Window System, can be installed and configured during installation by most distributions 22 22 Last updated: 18 January 2007 Linux Boot Loader • boot loader give interface for choose OS • Boot loaders include: – LILO • the Linux LOader – GRUB • GRand Unified Bootloader – LOADLIN • an MS-DOS boot loader – Choose-OS • a menu-based, fully-configurable modular boot loader for Linux – ..... –GRUB (GRand Unified Bootloader), which is installed by default, is a very powerful boot loader. GRUB can load a variety of free operating systems, as well as proprietary operating systems with chain-loading (the mechanism for loading unsupported operating systems, such as DOS or Windows, by loading another boot loader). –LILO (LInux LOader) is a versatile boot loader for Linux. It does not depend on a specific file system, can boot Linux kernel images from floppy diskettes and hard disks, and can even boot other operating systems. –LOADIN: You can load Linux from MS-DOS. Unfortunately, this requires a copy of the Linux kernel (and an initial RAM disk, if you have a SCSI adapter) to be available on an MS-DOS partition. The only way to accomplish this is to boot your Red Hat Linux system using some other method (for example, from a boot diskette) and then copy the kernel to an MS-DOS partition. 23 23 Last updated: 18 January 2007 The 1024 Cylinder Limit • The boot loader uses BIOS functions to load the kernel into memory. • Some BIOS can NOT boot from a partition containing the bootloader using cylinders numbered over 1023. When the system is booted, the BIOS reads sector 0 (known as the MBR - the Master Boot Record) from the first disk (or from floppy or CDROM), and jumps to the code found there - usually some bootstrap loader. These small bootstrap programs found there typically have no own disk drivers and use BIOS services. This means that a Linux kernel can only be booted when it is entirely located within the first 1024 cylinders, unless you both have a modern BIOS (a BIOS that supports the Extended INT13 functions), and a modern bootloader (a bootloader that uses these functions when available). This problem (if it is a problem) is very easily solved: make sure that the kernel (and perhaps other files used during bootup, such as LILO map files) are located on a partition that is entirely contained in the first 1024 cylinders of a disk that the BIOS can access - probably this means the first or second disk. Thus: create a small partition, say 10 MB large, so that there is room for a handful of kernels, making sure that it is entirely contained within the first 1024 cylinders of the first or second disk. Mount it on /boot so that LILO will put its stuff there. Most systems from 1998 or later will have a modern BIOS. 24 24 Last updated: 18 January 2007 LILO boot loader • Be used on x86 systems • How to install ? – Install LILO manually from the package – Let your Linux automatically install LILO • Where to install ? – first 1024 logical cylinders – On a diskette – In the boot sector of a primary or logical Linux partition on the first harddisk – Master Boot Record LILO with the `lba32' and `linear' options An invocation of /sbin/lilo (the boot map installer) stores a list of addresses in the boot map, so that LILO (the boot loader) knows from where to read the kernel image. By default these addresses are stored in (c,h,s) form, and ordinary INT13 calls are used at boot time. When the configuration file specifies lba32 or linear, linear addresses are stored. With lba32 also linear addresses are used at boot time, when the BIOS supports extended INT13. With linear, or with an old BIOS, these linear addresses are converted back to (c,h,s) form, and ordinary INT13 calls are used. Thus, with lba32 there are no geometry problems and there is no 1024 cylinder limit. Without it there is a 1024 cylinder limit. What about the geometry? 25 25 Last updated: 18 January 2007 LILO Configuration file # cat /etc/lilo.conf timeout=50 default=linux boot=/dev/hda root=/dev/hda1 message=/boot/message image=/boot/vmlinuz-2.4.7-10 label=linux read-only root=/dev/hda5 ... The boot loader and the BIOS must agree as to the disk geometry. /sbin/lilo asks the kernel for the geometry, but there is no guarantee that the Linux kernel geometry coincides with what the BIOS will use. Thus, often the geometry supplied by the kernel is worthless. In such cases it helps to give LILO the `linear' option. The advantage is that the Linux kernel idea of the geometry no longer plays a role. The disadvantage is that lilo cannot warn you when part of the kernel was stored above the 1024 cylinder limit, and you may end up with a system that does not boot. 26 26 Last updated: 18 January 2007 LILO command options • /sbin/lilo -q – queries the LILO map • /sbin/lilo -R – sets default command line for next reboot • /sbin/lilo -I – reports the path name ofcurrent kernel • /sbin/lilo {-u | -U} – uninstalls LILO Links: ftp://metalab.unc.edu/pub/Linux/system/boot/lilo/ 27 27 Last updated: 18 January 2007 LILO boot options • You can define additional hardware and memory options using boot options • Add boot options to lilo.conf – by adding lines of the following format: append=“” • Parse options at boot LILO: Example LILO: linux single LILo: init=/bin/bash Many programs can accept options on the command line when they are started. Most Linux boot loader are no exception to this rule. Several very important low- level configuration options can change the behavior of the kernel when they are passed to it at boot time 28 28 Last updated: 18 January 2007 GRUB (GRand Unified Bootloader) • GRUB can boot multiple OS • How to install ? – Install GRUB manually from package – Linux automatically install GRUB • Where to install ? – first 1024 logical cylinders – On a diskette – In the boot sector of a primary or logical Linux partition on the first harddisk – In the Master Boot Record GRUB is a very powerful boot loader, which can load a wide variety of free operating systems, as well as proprietary operating systems with chain-loading. GRUB is designed to address the complexity of booting a personal computer; both the program and this manual are tightly bound to that computer platform, although porting to other platforms may be addressed in the future. One of the important features in GRUB is flexibility; GRUB understands filesystems and kernel executable formats, so you can load an arbitrary operating system the way you like, without recording the physical position of your kernel on the disk. Thus you can load the kernel just by specifying its file name and the drive (and the partition) where the kernel resides. To let GRUB know the drive and the file name, you can either type in them manually via the command-line interface, or use the nice menu interface through which you can easily select which OS it boots. To allow you to customize the menu, GRUB will load a preexisting configuration file. Note that you can not only enter the command-line interface whenever you like, but also you can edit specific menu entries prior to using them. 29 29 Last updated: 18 January 2007 GRUB boot options • With GRUB bootloader, options can add at boot by use e command Notes: –After you update /etc/grub.conf file. You DON’T need to run any thing to update the configuration /etc/grub.conf 30 30 Last updated: 18 January 2007 LOADLIN • It’s a MS-DOS program that can launch a Linux kernel from DOS prompt. • This is very useful if you have hardware that relies on MS-DOS driver. 31 31 Last updated: 18 January 2007 System boot 1. Power on self test (POST) ROM bios routines 2. System boot (boot loader) 3. The kernel is uncompressed and loaded into memory 4. The root filesystem is mounted 5. The init daemon is started. 32 32 Last updated: 18 January 2007 Summary • Identify the types of system, hardware, and network setting necessary for Linux installation • Describe the need for pre-installation procedures • Describe the different types of file system: ext2, ext3, ReiserFS, XFS and JFS • Describe the procedures for CDROM or network installation • List and describe different types of boot loaders • List and describe system initialization, boot sequences, and boot files Key files, terms, and utilities include: / (root) filesystem /var filesystem /home filesystem swap space partitions cylinder 1024 /etc/lilo.conf /boot/grub/grub.conf lilo grub-install MBR first stage boot loader 33 Do a local CD installation (or network installation). The following points outline a suggested strategy. Preparations - 1 ftp server with Linux sources/ 10 students -1 First Linux (bootable) disk / 3 students -1 CD Driver + 1 HDD with at least 5GB / 1 Computer -1 Computer / 1 Student. 1./ Installation Type: choose "Custom" 2./ Disk Partitioning Setup: Partition the disk manually with Disk Druid, use ext3 filesystem for all partitions, except SWAP partition. This is a suggestion for a partitioning scheme using about 5GB of hard disk space. If you have more space available then make /usr, / , ... larger. /boot 100 M / 500 M /usr 3000 M /home 500 M /tmp 200 M /var 200 M /opt 250 M (not required) SWAP 250 M Notice that SWAP is a filesystem type and that no mount point is defined 3./ Install Bootloader: Install GRUB on MBR. 4./ Packages to install: (the names may vary from one distribution to another) "X Window System" + "GNOME desktop environment" OR "KDE desktop environment" "Editors" "Graphical Internet" "Software Development" [This is important, we will need this to compile packages later] 34 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 18 January 2007 Working on the command line Chapter 05 22 Last updated: 18 January 2007 Objectives • Describe and use the Linux shell and environment • Interactive the shell • List common environment commands • Use streams, pipes, and redirects LPI-101 Topics: 1.103.1: Work on the command line Candidates should be able to Interact with shells and commands using the command line. This includes typing valid commands and command sequences, defining, referencing and exporting environment variables, using command history and editing facilities, invoking commands in the path and outside the path, using command substitution, applying commands recursively through a directory tree and using man to find out about commands 1.103.4: Use streams, pipes, and redirects Candidates should be able to redirect streams and connect them in order to efficiently process textual data. Tasks include redirecting standard input, standard output, and standard error, piping the output of one command to the input of another command, using the output of one command as arguments to another command and sending output to both stdout and a file. 33 Last updated: 18 January 2007 The Command Line • A basic way to interact with a computer system. • The shell prompt, ending with: – $ : normal user – # : root user (uid=0) • Shell programs are called scripts Overview A basic way to interact with a computer system is to use the command line. The shell interprets the instructions typed in at the keyboard. The shell prompt (ending with $ or # for user root) indicates that it is ready for user input. The shell is also a programming environment which can be used to perform automated tasks. Shell programs are called scripts. 44 Last updated: 18 January 2007 • Shell is basically an interactive environment from which a user communicates with the operating system • There are several shells available: HW Kernel sh ell shell sh el l The SHELL ... /bin/bashBourne Again shell /bin/tcshTom's C shell /bin/kshKorn shell /bin/shBourne shell /bin/cshC shell 55 Last updated: 18 January 2007 • bash is a default shell on most Linux distributions. • A new shell is started when you running the program. • Each shell will have a separate environment The SHELL 66 Last updated: 18 January 2007 ƒ Usually, there are three components in command line: Command : what the system will do : or , how the command will do {Arguments}: where the command will apply to ƒ Sometimes you won't need option or argument, depending on the command Command {Arguments} Command Line Basic Syntax Options (or switch) : • Usually start with a dash, “-”, followed by one or more letters. They usually stands for certain words. • Some commands, such as rm,ls, use a switch -r, -R, or --recursive to indicate that the commands is to be executed recursively through directories 77 Last updated: 18 January 2007 • Example: $ date Command $ date mmddhhmmyy Command and argument $ cal 12 2000 Command and two arguments $ uname -a Command and option $ uname -rpns Command and multiple options $ uname -r -p -n -s Command and multiple options Command Line Examples 88 Last updated: 18 January 2007 Shell Configuration Files • Type of configuration files : – Global (system-wide) : apply to all users. – Local : apply to each user. • bash configuration files : – Global: /etc/profile – Local: • ~/.bash_profile • ~/.bash_login • ~/.profile 99 Last updated: 18 January 2007 • As in most programming languages, bash allows the use of variables. • There are also several global variables available that are set by the shell : #0-$9, $#, ... ƒ Environment is all settings that help program’s running correctly. ƒ There are two type of variables: • Predefined • User defined Variables Under bash and almost all other shells, the user can define environment variables, which are stored internally as ASCII strings. One of the handiest things about environment variables is that they are a standard part of the UNIX process model. This means that environment variables not only are exclusive to shell scripts, but can be used by standard compiled programs as well. When we "export" an environment variable under bash, any subsequent program that we run can read our setting, whether it is a shell script or not. 10 10 Last updated: 18 January 2007 Variables • Initialise a variable: • Reference a variable: • Example: # VAR=‘Hello world !’ # echo $VAR Hello world ! variable-Name=value $variable-Name Notes: You should learn more about bash script from LPI-102 course. 11 11 Last updated: 18 January 2007 ... Name of the computer HOSTNAME User's home directoryHOME Current shell (usually /bin/bash) SHELL Current working directoryPWD Preferred viewer (more, less) PAGER Current X displayDISPLAY Shell promptPS1, PS2 List of directories to search for commands, separated by colon ' : ' PATH Predefined variables The following list shows the meanings of the special characters used to define the PS1 and PS2 prompt strings. \t - time \d - date \n - newline \s - Shell name \W - The current working directory \w - The full path of the current working directory. \u - The user name \h - Hostname \# - The command number of this command. \! - The history number of the current command 12 12 Last updated: 18 January 2007 Special variables parameters list$1..$9 script name$0 number of parameter$# 0 if the last command was executed successfully 1 otherwise $? represents the PID of the running shell$$ represents the PID value of the last child process$! 13 13 Last updated: 18 January 2007 Using the bash Shell • Ctrl+Alt+F[1-8] : switch between virtual consoles • Auto complete : use TAB key • up and down arrow keys : get history commands (store in ~/.bash_history) • Ctrl+Z • Ctrl+C 14 14 Last updated: 18 January 2007 Using the bash Shell • wildcard characters : * matchs any of zero or more characters ? matchs any single characters • Example : # ls image?.jp*g image1.jpg image3.jpeg ( but do NOT list image20.jpg file) 15 15 Last updated: 18 January 2007 Command History and Editing • History is a mechanism that allows user can get previous executed commands. • ~/.bash_history – Save executed commands – Each command has a corresponding number in history file –History is a mechanism that allows user can get previous executed commands. Then you can edit it before executing. –Executed commands will be saved in ~/.bash_history when you exit the shell. During session, they are temporary stored in buffer –Each command has a corresponding number in history file 16 16 Last updated: 18 January 2007 Reexecutes the most recent command containing string !? Repeats the last command but replaces string1 with string2 ^^ Reexecutes the most recent command starting with string ! Reexecutes the current command minus n!- Reexecutes command n from history ! Command History and Editing • List of useful command work with history: While using history substitution can be useful for executing repetitive commands, command history editing is much more interactive. To envision the concept of command history editing, think of your entire bash history (including that obtained from your ~/.bash_history file) as the contents of an editor's buffer. In this scenario, the current command prompt is the last line in an editing buffer, and all of the previous commands in your history lie above it. All of the typical editing features are available with command history editing, including movement within the "buffer," searching, cutting, pasting, and so on. Once you're used to using the command history in an editing style, everything you've done on the command line becomes available as retrievable, reusable text for subsequent commands. The more familiar you become with this concept, the more useful it can be. 17 17 Last updated: 18 January 2007 common commands ƒ Linux (Unix) is case-sensitive, “ls” , “LS” are different commands ƒ Entering command sequences ƒ Example: $ ls $ ps ƒ Same with $ ls; ps Command line utilities are an extremely powerful way to complete day-to-day activities, you should be familiar with it ƒRemember : Linux (Unix) is case-sensitive, “ls” , “LS” are different commands ƒMore information about a command can be found using man pages. Entering command sequences There may be times when it is convenient to place multiple commands on a single line. Normally, bash assumes you have reached the end of a command (or the end of the first line of a multiple-line command) when you press Return. To add more than one command to a single line, the commands can be separated and entered sequentially with the command separator , a semicolon. Using this syntax, the following commands: $ ls $ ps are, in essence, identical to and will yield the same result as the following single-line command that employs the command separator: $ ls; ps 18 18 Last updated: 18 January 2007 Bash Scripting • Any number of executable commands from the command line can be placed in a text file. • Bash scripts must begin with the following line : #!/bin/bash • " #! " pronouned "she-bang" Any number of executable commands from the command line can be placed in a text file. If this file is given execute permissions, it can be run like any program by type on command line. This is called a script. 19 19 Last updated: 18 January 2007 Bash Scripting • Example bash script that uses conditions $cat newdir.sh #!/bin/bash if [ $# -lt 1 ]; then echo Usage: $0 directory_name exit fi if [ -d "$1” ]; then echo Directory $1 already exists else mkdir $1 fi This script accept parameter (directory) from command line, then create the directory if it does not exists. Use this script: $ ls $ newdir Usage: newdir directory_name $ newdir mydir $ ls mydir $ newdir mydir Directory mydir already exists 20 20 Last updated: 18 January 2007 Environment Variables commands • pwd – Identify current working directory. – displays the absolute path name. • set – shows all variables (local and exported) • env – shows only exported variables • unset – used to remove variables 21 21 Last updated: 18 January 2007 • export – shows exported variables • export – make as exported (global) variables Environment Variables commands VAR=value VAR=?? parent child LOCAL export VAR=value VAR=value parent child GLOBAL -When you defile new variable as local variable (without export), any child processes can not use it. -Global variable (with export) allow child processes use it. 22 22 Last updated: 18 January 2007 • echo – Printing text to the screen • exec – Executing a command • man [section] command – Display online help • ~/.bash_profile – Users environment stuff and startup programs. Environment Variables commands Printing text to the screen The the bash shell uses the echo command to print text to the screen. # echo “this is a short line” Executing a command using exec The interactive shell is often referred to as the session leader and will be the parent process of any new process started from the shell which is then called a child process. There are two methods available to execute a new command: exec and fork. By default a process will use the fork method. To force a process to use the exec method the command is proceeded by the exec command: # exec xeyes Notice that when xeyes is terminated the parent process will also exit. A useful example is a window manager started with exec in such a way that the X11 server will exit once the window manager is closed. Change ~/.bash_profile content You can any text editor to change ~/.bash_profile content. New content is available after you re-login or run: $ source ~/.bash_profile $ . ~/.bash_profile Same result 23 23 Last updated: 18 January 2007 Redirection Standard Error (stderr) Default: Screen Standard Out (stdout) Default: Screen shell Standard Input (stdint) Default: Keyboard Standard input (abbreviated stdin) This file descriptor is a text input stream. By default it is attached to your keyboard. When you type characters into an interactive text program, you are feeding them to standard input. As you've seen, some programs take one or more filenames as command-line arguments and ignore standard input. Standard input is also known as file descriptor 0. Standard output (abbreviated stdout) This file descriptor is a text output stream for normal program output. By default it is attached to your terminal (or terminal window). Output generated by commands is written to standard output for display. Standard output is also known as file descriptor 1. 24 24 Last updated: 18 January 2007 • Redirection can refer to file descriptors in addition to files. • >n redirects from File Descriptor n • >&n redirects to File Descriptor n Standard errorstderr2 Standard outputstdout1 Standard inputstdin0 File Descriptors Standard error (abbreviated stderr) This file descriptor is also a text output stream, but it is used exclusively for errors or other information unrelated to the successful results of your command. By default standard error is attached to your terminal just like standard output. This means that standard output and standard error are commingled in your display, which can be confusing. You'll see ways to handle this later. Standard error is also known as file descriptor 2. 25 25 Last updated: 18 January 2007 Redirecting Input (stdin) command < filename command 0< filename • Command format: • Example: $ mailx user1 < ~/dante On the example: The mailx command accepts input from stdin (~/dante) 26 26 Last updated: 18 January 2007 Redirecting Output (stdout) • Command format: • Example: $ ls -l > directory_content.list command > filename command 1> filename When you sets redirecting to filename, the filename will be created and overwrite the old filename, if it exists. To prevent overwriting, you should run: set –o noclobber 27 27 Last updated: 18 January 2007 Redirecting stdout in Append Mode • Command format: • Example: $ cat /etc/passwd > my_file; cat my_file $ echo "That’s my passwd file" >> my_file command >> filename On Append mode, the filename should be appended if it exists. Other hand, the new filename should be created. 28 28 Last updated: 18 January 2007 • Command format: • Example: $ Date 2> errorfile $ cat errorfile ksh: Date: not found command 2> error_filename command 2> /dev/null Redirecting stderr -On the first form, all error should be written to error_filename. -On the second form, all error should be deleted ! Sometime, you need write stdout and stderror to same output file, use this form: $ command >out_file 2>&1 29 29 Last updated: 18 January 2007 • Use the ' | ' character • Output of command1 becomes input of command2 • Example: # ls –l |grep samba Piping command1 | command2 The shell enables you to pass the output of one command to the input of another command. This connection is known as a pipe ( | ). 30 30 Last updated: 18 January 2007 • read from standard input and write to standard output and files • Example: #cat file.txt | tail -3 | tee initial_tail | head -1 Brian # cat initial_tail Brian Aoife Lia Using tee commands tee [options] files Sometimes, you'll want to run a program and send its output to a file while at the same time viewing the output on the screen. The tee utility is helpful in this situation. This command read from standard input and write both to one or more files and to standard output (analogous to a tee junction in a pipe). Option -a : Append to files rather than overwriting them. Example Suppose you're running a pipeline of commands cmd1, cmd2, and cmd3: $ cmd1 | cmd2 | cmd3 > file1 This sequence puts the ultimate output of the pipeline into file1. However, you may also be interested in the intermediate result of cmd1. To create a new file_cmd1 containing those results, use tee: $ cmd1 | tee file_cmd1 | cmd2 | cmd3 > file1 The results in file1 will be the same as in the original example, and the intermediate results of cmd1 will be placed in file_cmd1. 31 31 Last updated: 18 January 2007 • Build and execute command lines from standardinput • Options: – n Max arguments per invocation of cmd – p Interactive mode • Example $ ls /etc/*.conf | xargs cat Using xargs command xargs [options] [cmd] [initial-arguments] 32 32 Last updated: 18 January 2007 Summary • Describe and use the Linux shell and environment • Interactive the shell • List common environment commands • Use streams, pipes, and redirects Key files, terms, and utilities include: tee xargs ~/.bash_history ~/.profile < << > >> | . bash echo env exec export man pwd set unset 33 Practice: Get started with the command line Starting a terminal window There are many different kinds of terminal windows on a Linux system. Use Ctrl+Alt+F1..6 login to multi console. The shell Try the commands below, see what they do, and make sure you understand. ls The "ls" command will show a list of the files and directories in the current directory: $ ls pwd The "pwd" command will print the path to the current directory: $ pwd /.automount/spiderman2/root/export/home1/hm You will be in your home directory when you start the terminal window. man Display on-line manual pages $ man ls $ man pwd more You can use "more" to see the output of a command, one page at a time. Try $ ls /usr/lib | more Remember, you can use "q" to quit. cat Prints the content of a file on the screen. Try $ cat /etc/passwd echo "Echo" will print the text you type, to the screen: $ echo "Hello Linux" sort Sort lines in file alphabetically $ sort /etc/passwd 34 Pipes and redirection > Redirect stdout Stdout (standard output) from a program usually goes to the terminal. Example: $ echo "Hello Linux" The output "Hello Linux “ is displayed on the screen. But you can redirect stdout to a file instead of the terminal: $ echo "Hello Linux" > testfile3 If the file exist it will be overwritten. If it does not exist, it will be created. Test it with cat testfile3. >> Append stdout to file Append something to a file, not overwriting previous entires: $ echo "12345678" >> testfile3 Check it with cat testfile3. < Redirect stdin Usually, stdin (standard input) is what you type on your keyboard, or what comes from the previous program, if in a pipe line. But you can get stdin from a file instead: $ cat < testfile3 Now, try setting some programs together in a row: $ cat /etc/printcap | sort > testfile4 $ cat /etc/sysconfig/network | grep HOSTNAME $ grep -r "inode" /usr/src/linux | more Starting a program from the command line You can start a graphical application from the command line by typing its name. Try $ xclock Start konqueror from the command line in "background mode" $ xclock & 35 Variables 1. Do the following - Assign the value 'virus' to the variable ALERT. # ALERT='virus' - Verify that it is defined using the set command: # set |grep ALERT - Is ALERT listed when using env instead of set? _____ - Next type bash. Can you access the ALERT variable? # bash # echo $ALERT What is the value of ALERT: ______ ( is it blank? Why ?) - Type exit (or ^D) to return to your original session. - Use the export command to make ALERT a global variable. # export ALERT - Verify that it is a global (env) variable. # env | grep ALERT - Next type bash again. Can you access the ALERT variable? # bash # echo $ALERT What is the value of ALERT: ______ ( is it blank? Why ?) 2. Change PS1 value - Get current PS1 value # echo $PS1 - Using appropriate quotes change your PS1 variable to include the full path to your working directory. (replace the \W by a \w) PS1='[\u@\h \w ]\$ ' What does PS1 look like?______ 36 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 10 January 2007 Process text streams using filters Chapter 06 22 Last updated: 10 January 2007 Objectives • Apply filters to text streams. • Modify the stream output. • Using standard UNIX commands in the GNU textutils package. LPI-101 Topics: 1.103.2 Process text streams using filters Candidates should should be able to apply filters to text streams. Tasks include sending text files and output streams through text utility filters to modify the output, and using standard UNIX commands found in the GNU textutils package. 33 Last updated: 10 January 2007 cat command – an acronym for concatenate, lists a file to stdout • Options – n inserts consecutive numbers before all lines of the target file(s). – b only the non-blank lines. – v echoes nonprintable characters, using ^ notation. cat [options] [files] - To display the entire file without having to press RETURN for each page use the cat command. Example: $ cat /etc/passwd Will display the entire contents of the file /etc/passwd. - cat can also be used to create a file. Example: $ cat >newfile Will create a new file or replace the existing file 'newfile'. After the command, enter the text for each line. To close the file, use control-D. 44 Last updated: 10 January 2007 more Command – Displays text one screen at a time. – uses the [Spacebar] and the [B] key for forward and backward navigation. • Options – c clean before display more [options] [files] 55 Last updated: 10 January 2007 tac Command – Opposite of cat (displays files in reverse order) • Example tac [file] # tac file1.txt 5 eeeee 4 ddddd 3 ccccc 2 bbbbb 1 aaaaa # cat file1.txt 1 aaaaa 2 bbbbb 3 ccccc 4 ddddd 5 eeeee Named for the common command cat, tac prints files in reverse to standard output. Without a filename or with -, it reads from standard input. By default, tac reverses the order of the lines, printing the last line first. 66 Last updated: 10 January 2007 cut Command – Filters out fields or columns • Options – d : chardefine field delimiter (default is tab) – c : listcut by column position – f : listcut by field number cut [options] [files] The cut command is a handy program for extracting pieces of a line of text. The most useful options are "-d" and "-f", which are for setting the "delimiter" character that separates items, and for telling Cut which "fields" you want it to print. 77 Last updated: 10 January 2007 cut Command • Example # id uid=500(dobriain) gid=100(users) groups=100(users) # id | cut -d' ' -f1,2 uid=500(dobriain) gid=100(users) cut [options] [files] 88 Last updated: 10 January 2007 expand Command – Convert tabs to spaces. • Options – i : Initial; convert only at start of lines. – t tabs : Specify tab stops, in place of default 8 spaces expand [options] [files] Convert tabs in each FILE to spaces, writing to standard output. With no FILE, or when FILE is -, read standard input. 99 Last updated: 10 January 2007 expand Command • Example # more file.txt qwerty uiop asdfgh jkl zxcv bnm 1234 5678 9012 1234 # expand -t2 file.txt qwerty uiop asdfgh jkl zxcv bnm 1234 5678 9012 1234 expand [options] [files] 10 10 Last updated: 10 January 2007 unexpand Command – Convert spaces to tabs. • Options – t tabs : Specify tab stops, in place of default 8 spaces unexpand [options] [files] Convert strings of initial whitespace, consisting of at least two spaces and/or tabs, to tabs. Read from standard input if given no file or a file named -. 11 11 Last updated: 10 January 2007 unexpand Command • Example # more file3.txt qwerty uiop asdfgh jkl zxcv bnm 1234 5678 9012 1234 # unexpand -t2 file3.txt qwerty uiop asdfgh jkl zxcv bnm 1234 5678 9012 1234 unexpand [options] [files] 12 12 Last updated: 10 January 2007 fmt Command – Text formatter • Options – p : Combines only lines having STRING prefix – u : Uniform spacing, one space between words, two after sentences – w : Maximum length of line width (default is 75 columns) fmt [options] [files] Convert text to specified width by filling lines and removing newlines. Concatenate files on the command line, or read text from standard input if - (or no file) is specified. By default, preserve blank lines, spacing, and indentation. fmt attempts to break lines at the end of sentences and avoid breaking lines after a sentence's first word or before its last. 13 13 Last updated: 10 January 2007 join Command – Join common lines of sorted file1 and sorted file2 • Options – 1 n : Join on field N of file 1 – 2 n : Join on field N of file 2 join [options] file1 file2 Join lines of two sorted files by matching on a common field. If either file1 or file2 is -, read from standard input. 14 14 Last updated: 10 January 2007 join Command • Example # join -1 1 -2 1 file1.txt file2.txt 1 aaaaa AAAAA 2 bbbbb BBBBB 3 ccccc CCCCC 4 ddddd DDDDD 5 eeeee EEEEE # more file2.txt 1 AAAAA 2 BBBBB 3 CCCCC 4 DDDDD 5 EEEEEE # more file1.txt 1 aaaaa 2 bbbbb 3 ccccc 4 ddddd 5 eeeee 15 15 Last updated: 10 January 2007 split Command – Splits a file into pieces • Options – b size : Split file into pieces no bigger than SIZE – l count : Split file into pieces with at the most COUNT lines • Example # split -l3 file.txt # ls file.txt xaa xac xab split [Options] [infile] [outfile] 16 16 Last updated: 10 January 2007 nl Command – Number of lines of FILE • Options – s : Separate text from line number with CHARACTER nl [options] [files] 17 17 Last updated: 10 January 2007 nl Command • Example # more file.txt # nl –s'-' file.txt Diarmuid 1-Diarmuid Cian 2-Cian Conor 3-Conor Majella 4-Majella Brian 5-Brian Aoife 6-Aoife Lia 7-Lia nl [options] [files] 18 18 Last updated: 10 January 2007 od Command – A command used to make an octal, decimal, hexadecimal, or ASCII dump of a file • Options – x : Hexadecimal dump – c : shows ASCII characters handy when you need to see ASCII characters such as \n (new line) \t (tab)) od [options] [files] Dump the specified files to standard output. The default is to dump in octal format, but other formats can be specified. With multiple files, concatenate them in the specified order. If no files are specified or file is -, read from standard input. 19 19 Last updated: 10 January 2007 od Command • Example # more file1 aaaaaa bbbbbb cccccc # od -c file1 0000000 a a a a a a \n b b b b b b \n c c 0000020 c c c c \n 0000040 od [options] [files] 20 20 Last updated: 10 January 2007 paste Command – Merges corresponding lines in several files to create a columnar output • Options – d :Allows you to specify the character to use as the delimiter paste [options] [files] Merge corresponding lines of one or more files into tab-separated vertical columns. 21 21 Last updated: 10 January 2007 paste Command • Example # paste -d# file1.txt file2.txt 1 aaaaa#1 AAAAA 2 bbbbb#2 BBBBB 3 ccccc#3 CCCCC 4 ddddd#4 DDDDD 5 eeeee#5 EEEEE # more file2.txt 1 AAAAA 2 BBBBB 3 CCCCC 4 DDDDD 5 EEEEEE # more file1.txt 1 aaaaa 2 bbbbb 3 ccccc 4 ddddd 5 eeeee 22 22 Last updated: 10 January 2007 pr Command – Used to format text files according to certain specified options • Options – n : Formats output with n columns; default is 1 – d : Double spaces the output – h : Allows you to specify a STRING as the page header – ln : Specify the length of the page lines (default is 66) – wn : Sets the line length (default is 72) pr [options] [files] Convert a text file or files to a paginated, columned version, with headers. If - is provided as the filename, read from standard input. 23 23 Last updated: 10 January 2007 pr Command • Example # pr README 2005-05-17 09:28 README Page 1 Java(TM) 2 Runtime Environment, Standard Edition Version 1.4.2 The Java(TM) 2 Runtime Environment is intended for software developers and vendors to redistribute with their applications. The Java 2 Runtime Environment contains the Java virtual machine, runtime class libraries, and Java application launcher that are necessary to run programs written in the Java programming language. It is not a development environment and does not contain development tools such as compilers or debuggers. For development tools, see the Java 2 SDK, Standard Edition. ............. 24 24 Last updated: 10 January 2007 sort Command – Sorts lines of the named file • Options – d Sort alphabetically – n Sort numerically – r Reverse order – t Seperator field character – k Sort column (start by 1) sort [options] [files] Sort the lines of the named files. Compare specified fields for each pair of lines; if no fields are specified, compare them by byte, in machine collating sequence. If no files are specified or if the file is -, the input is taken from standard input. 25 25 Last updated: 10 January 2007 sort Command • Example # more file.txt Diarmuid Cian Conor Majella Brian Aoife Lia # sort file.txt Aoife Brian Cian Conor Diarmuid Lia Majella 26 26 Last updated: 10 January 2007 uniq Command – remove duplicate lines from a sorted file • Options – d : Only print duplicate lines • Example uniq [options] [files] # uniq file3 aaaaa bbbbb ccccc ddddd # cat file3 aaaaa bbbbb bbbbb ccccc ddddd Remove duplicate adjacent lines from sorted file1, sending one copy of each line to file2 (or to standard output). Often used as a filter. Specify only one of -d or -u. 27 27 Last updated: 10 January 2007 head Command – Prints the first 10 lines of each FILE to standard output • Options – n : Print the first NUMBER of lines (rather than default of 10) – q : Don't print headers giving file name when using multiple files head [options] [files] Print the first few lines (default is 10) of one or more files. If files is missing or -, read from standard input. With more than one file, print a header for each file. 28 28 Last updated: 10 January 2007 head Command • Example # head -n3 file.txt Diarmuid Cian Conor head [options] [files] Examples Display the first 20 lines of phone_list: head -20 phone_list Display the first 10 phone numbers having a 202 area code: grep '(202)' phone_list | head 29 29 Last updated: 10 January 2007 tail Command – Print the last few lines of one or more files. • Options – n m or -m Prints the last m lines. The default is 10. +m Print from line number m to end of file. – f Continuously display a file as it is actively written by another process. tail [options] [files] Print the last few lines of one or more files (the "tail" of the file or files). When more than one file is specified, a header is printed at the beginning of each file, and each is listed in succession. 30 30 Last updated: 10 January 2007 tail Command • Example # cat file1.txt 1 aaaaa 2 bbbbb 3 ccccc 4 ddddd 5 eeeee # tail -2 file1.txt 4 ddddd 5 eeeee # tail +2 file1.txt 2 bbbbb 3 ccccc 4 ddddd 5 eeeee 31 31 Last updated: 10 January 2007 tr Command – Translates characters in a file from one form to another • Example # cat file.txt | tr "[A-Z]" "[a-z]" diarmuid cian conor majella brian aoife lia tr [options] [string1] [string2] Translate characters. Copy standard input to standard output, substituting characters from string1 to string2 or deleting characters in string1. 32 32 Last updated: 10 January 2007 wc Command – A command that counts all the characters, words, and lines in a file • Options – c : Counts the characters – l : Counts the lines – w : Counts the words wc [options] [files] Examples Count the number of users logged in: who | wc -l Count lines in the file named by variable $file (don't display filename): wc -l < $file 33 33 Last updated: 10 January 2007 Summary • Apply filters to text streams. • Modify the stream output. • Using standard UNIX commands in the GNU textutils package. Key files, terms, and utilities include: Links: Alphabetical Directory of Linux Commands pr sort split tac tail tr unexpand uniq wc cat cut expand fmt head join nl od paste 34 Practice: Process text steams and filters Login as hocvien user Copy /etc/X11/XF86Config (or /etc/X11/xorg.conf) to your home directory and rename to practice6 1. Use cat command display practice6 with numbering to all lines. Then do same thing with nl command. What is different? _____________________________ 2. Print number of lines in the practice6 file, without file name, into screen. 3. Output the number of characters in practice6. Compare this to the size in an ls -l listing. 4. Count the number of objects in the Data directory, do not including hidden objects. 5. Print the rest of the practice6 file starting at line 90, with line number, to screen. 6. Output lines 20-30 of the practice6 file , with line number, to screen. 7. Do the following: • Type this command into your shell: (this command print date value, every 1 second, to thedate file.) $ while true; do date >> thedate; sleep 1; done • Open new console, login as hocvien, run folloing command. How about result?___________________________________ $ tail -f thedate • Use ctrl+c hotkey to exit the tail –f command and the while command too. 8. Print only username from file /etc/passwd to screen. 9. Look at the output of the date command. Using cut and column positions, create the labs9 file that contains the month and the day of the month. 35 Solution: Process text steams and filters Login as hocvien user Copy /etc/X11/XF86Config (or /etc/X11/xorg.conf) to your home directory and rename to practice6 [hocvien@CTT ~]$cp /etc/X11/xorg.conf ~/practice6 1. Use cat command display practice6 with numbering to all lines. Then do same thing with nl command. nl command donot add line number to blank lines. [hocvien@CTT ~]$cat -n practice6 [hocven@CTT ~]$nl practice6 2. Print number of lines in the practice6 file, without file name, into screen. [hocvien@CTT ~]$ wc -l practice6 | cut -d' ' -f1 3. Output the number of characters in practice6. Compare this to the size in an ls -l listing. [hocvien@bb ~]$ ls -l practice6 -rw-r--r-- 1 hocvien hocvien 2798 Dec 28 11:35 practice6 [hocvien@bb ~]$ wc -c practice6 2798 practice6 4. Count the number of objects in the Data directory, do not including hidden objects. [hocvien@bb ~]$ ls -1 demo practice4 practice5 practice6 [hocvien@bb ~]$ ls -1 | wc -l 4 36 5. Print the rest of the practice6 file starting at line 90, with line number, to screen. [hocvien@bb ~]$ cat -n practice6 | tail +90 90 EndSection 91 92 Section "Screen" 93 Identifier "Screen0" 94 Device "Videocard0" 95 Monitor "Monitor0" 96 DefaultDepth 24 97 SubSection "Display" 98 Viewport 0 0 99 Depth 16 ......... 6. Output lines 20-30 of the practice6 file , with line number, to screen. [hocvien@bb ~]$ cat -n practice6 | tail +20 | head -11 20 FontPath "unix/:7100" 21 EndSection 22 23 Section "Module" 24 Load "dbe" 25 Load "extmod" 26 Load "fbdevhw" 27 Load "glx" 28 Load "record" 29 Load "freetype" 30 Load "type1" [hocvien@bb ~]$ 7. Use ctrl+c hotkey to exit the tail –f command and the while command too. 8. Print only username from file /etc/passwd to screen. [hocvien@bb ~]$ cut -d: -f1 /etc/passwd root bin daemon ........ 37 9. Look at the output of the date command. Using cut and column positions, create the labs9 file that contains the month and the day of the month. [hocvien@bb ~]$ date Thu Dec 28 14:38:58 ICT 2006 [hocvien@bb ~]$ date | cut -d' ' -f2,3 > lab9 [hocvien@bb ~]$ cat lab9 Dec 28 [hocvien@bb ~]$ 38 1Linux Junior Level Administration - LPI 101 1 SaigonCTT All rights reservedLast updated: 10 January 2007 Perform basic file management Chapter 07 22 Last updated: 10 January 2007 Objectives • File system basic • Directory Hierarchy • Path naming • File management commands • File globbing LPI-101 Topics: 1.103.3: Perform basic file management Candidates should be able to use the basic UNIX commands to copy, move, and remove files and directories. Tasks include advanced file management operations such as copying multiple files recursively, removing directories recursively, and moving files that meet a wildcard pattern. This includes using simple and advanced wildcard specifications to refer to files. 33 Last updated: 10 January 2007 • File systems are used to store files in an organized structure • It is important to have an understanding of how to navigate it and how to create, move, copy and remove file

Các file đính kèm theo tài liệu này:

  • pdflpi_101_student_guide_v2_0_2477.pdf