By the time you have completed Ubuntu Linux Secrets you will be well-prepared to utilize your Ubuntu workstation or server to its fullest.. Ubuntu Linux Secrets also walks the seasoned
Trang 3Ubuntu Linux
Secrets
Trang 5Ubuntu Linux
Secrets
Richard Blum
Trang 610475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 6011, fax (201)
748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with
respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including
without limitation, warranties of fitness for a particular purpose No warranty may be created or extended by sales or
promotional materials The advice and strategies contained herein may not be suitable for every situation This work is
sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional
ser-vices If professional assistance is required, the services of a competent professional person should be sought Neither the
publisher nor the author shall be liable for damages arising herefrom The fact that an organization or web site is referred
to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher
endorses the information the organization or web site may provide or recommendations it may make Further, readers
should be aware that Internet web sites listed in this work may have changed or disappeared between when this work
was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974 or outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its
affiliates, in the United States and other countries, and may not be used without written permission Ubuntu is a
regis-tered trademark of Canonical Limited Linux is a regisregis-tered trademark of Linus Torvalds All other trademarks are the
property of their respective owners Wiley Publishing, Inc is not associated with any product or vendor mentioned in this
book.
Wiley also publishes its books in a variety of electronic formats Some content that appears in print may not be available
in electronic books.
Trang 7—Proverbs 24:3–4 (NIV)
Trang 8About the Author
Richard Blum has worked in the IT industry for over 20 years as both a systems and
network administrator During that time he has administered UNIX, Linux, Novell, and Microsoft servers, as well as helped manage desktop workstations on a 3,500-user net-work He has used Linux since the days of loading the system from floppy disks and has utilized Ubuntu workstations and servers in his environment
Rich has a bachelor of science degree in electrical engineering and a master of science degree in management, specializing in management information systems, from Purdue
University He is the author of several Linux books, including Linux Command Line and Shell Script Bible, Professional Assembly Language Programming, Network Performance Open Source Toolkit, sendmail for Linux, Running qmail, Postfix, and Open Source E‑mail Security He’s also a coauthor of Professional Linux Programming, and Linux for Dummies, 8th Edition When he’s not being a computer nerd, Rich plays bass guitar for his church
worship band and enjoys spending time with his wife, Barbara, and their two daughters, Katie Jane and Jessica
Trang 10Finally, I would like to thank my parents, Mike and Joyce Blum, for their dedication and support while raising me, and my wife, Barbara and daughters, Katie Jane and Jessica, for their love, patience, and understanding, especially while I was writing this book.
Trang 11Contents at a Glance
Introduction xxv
Part 1: Starting Out with Ubuntu 1
Chapter 1: What is Ubuntu? 3
Chapter 2: Playing with the LiveCD 25
Chapter 3: Installing Ubuntu 47
Chapter 4: Exploring the Desktop 79
Part 2: Starting Out with Ubuntu 107
Chapter 5: File Management 109
Chapter 6: Working With Text 135
Chapter 7: The OpenOffice Suite 161
Chapter 8: Network Applications 197
Chapter 9: Evolution 227
Chapter 10: Image Manipulation 255
Chapter 11: Using Audio 277
Chapter 12: Using Video 295
PART 3: Managing Your Workstation 313
Chapter 13: Software Installs and Updates 315
Chapter 14: Networking 337
Chapter 15: External Devices 367
Chapter 16: The Display 387
Chapter 17: Users and Groups 407
Chapter 18: Basic Administration 425
Chapter 19: The Ubuntu Command Line 441
PART 4: Using the Ubuntu Server 467
Chapter 20: DNS Server 469
Chapter 21: Web Server 493
Chapter 22: Samba and Print Server 521
Chapter 23: Email Server 547
Chapter 24: Database Server 579
Trang 12Part 5: Programming in Ubuntu 605
Chapter 25: Shell Scripts 607
Chapter 26: Perl and Python 637
Chapter 27: C Programming 661
Chapter 28: Java 687
Chapter 29: Ruby 713
Chapter 30: PHP 741
Index 771
Trang 13Introduction xxv
Part 1: Starting Out with Ubuntu 1
Chapter 1: What is Ubuntu? 3
What Is Linux? 4
The Linux Kernel 4
The GNU Utilities 11
The Linux Desktop Environment 13
Linux Distributions 19
Core Linux Distributions 19
Specialized Linux Distributions 20
The Linux LiveCD 21
What Is Ubuntu? 22
Ubuntu Versions 22
Ubuntu Release Schedule 23
Ubuntu Cousins 24
Summary 24
Chapter 2: Playing with the LiveCD 25
The Ubuntu LiveCD 26
Downloading Ubuntu 26
Downloading from the Web 27
Using BitTorrent to Download 29
Verifying the File 32
Creating the LiveCD 34
Burning CDs in Linux 34
Burning CDs in Mac OS X 34
Burning CDs in Windows 36
Booting the LiveCD 36
The Boot Process 37
Using Ubuntu 37
The LiveCD Desktop 39
Storing Files 40
Running Ubuntu in Windows 42
The Wubi Project 43
Installing in Windows 43
Running Ubuntu in Windows 44
Summary 45
Trang 14Chapter 3: Installing Ubuntu 47
Preparing Your PC 48
System Requirements 48
Creating a Place for Ubuntu 51
Installing from the LiveCD 57
Select a Language 58
Select a Time Zone 58
Select a Keyboard 58
Prepare the Disk Space 60
Create a Login ID 63
Migrate Documents and Settings 64
Review Options 66
Installing from the Alternate Install CD 67
Guided Partitions 68
Manual Partitions 69
Server Installation 70
Main Installation 70
Server Programs 71
Upgrading Ubuntu 75
Summary 77
Chapter 4: Exploring the Desktop 79
Desktop Features 80
The Top Panel 81
The Desktop Workspace 86
The Bottom Panel 87
Modifying the Desktop 89
Adding to the Panel Menus 89
Adding Panel Applets 92
Adding Desktop Icons 96
Desktop Appearance 97
The Desktop Theme 98
The Background 99
Fonts 100
Interface 100
Visual Effects 101
Accessibility Features 101
Preferred Applications 102
Keyboard Features 104
Mouse Features 104
Summary 106
Part 2: Starting Out with Ubuntu 107
Chapter 5: File Management 109
The Linux Filesystem 110
Filepaths 110
Filenames 113
Trang 15Nautilus 113
Nautilus Window Components 113
Browser Versus Spatial Mode 119
Modifying Nautilus Windows 120
Handling Files 125
Creating New Files and Folders 125
Copying and Moving Files 126
Running Programs 126
Deleting Files 128
File Properties 128
Basic Properties 128
Emblems 129
Permissions 130
Open With 132
Notes 133
Summary 133
Chapter 6: Working With Text 135
The gedit Editor 136
Starting gedit 136
Basic gedit Features 137
Setting Preferences 138
The Character Map 141
The vim Editor 143
The Basics of vim 143
Editing Data 145
Copy and Paste 146
Search and Substitute 146
The emacs Editor 147
Using emacs on the Console 148
Using emacs in GNOME 152
The Tomboy Notes Application 154
Starting Tomboy Notes 154
Creating Notes 155
Editing Notes 156
Organizing Notes 157
Changing Preferences 157
Tomboy Add-ins 159
Summary 159
Chapter 7: The OpenOffice Suite 161
The OpenOffice.org Suite 162
Word Processing 163
Writer Features 163
Working with Writer Files 167
Spreadsheets 168
The OpenOffice.org Calc Layout 168
Working with Calc Files 173
Trang 16Presentations 174
Using the Presentation Wizard 174
Taking a Tour of OpenOffice.org Impress 176
Working with Impress Files 179
Database 180
Getting Help from the Wizard 180
Taking a Tour of Base 183
Working with Tables 184
Drawing 186
Taking a Tour of OpenOffice.org Draw 186
Working with Draw Files 189
Math 190
Starting Math 190
The Math Layout 191
Working with Math 193
Summary 195
Chapter 8: Network Applications 197
The Ubuntu Internet Software Suite 198
Ekiga 198
Firefox 200
Walking Through Firefox 201
Configuring Firefox 203
Working with Add-ons 210
Pidgin 212
Using the Pidgin Instant Messenger 213
Pidgin Preferences 215
Remote Desktop Viewer 216
Terminal Server Client 218
Transmission 220
gFTP 222
Summary 224
Chapter 9: Evolution 227
The Evolution Suite 228
Starting Evolution 228
Obtain Email Client Info 229
Run the Wizard 229
The Evolution Window 238
The Menu Bar 238
The Toolbar 239
The Search Tool 240
The Message List 240
The Sidebar 242
The Switcher 242
The Preview Pane 242
Trang 17Using Evolution 242
Sending Messages 242
Changing the Configuration 244
Mail Filtering 247
Filtering Messages 247
Filtering Spam 249
Backing Up Evolution 250
Using the Address Book 250
Accessing the Calendar and Tasks 252
Calendar 252
Tasks 253
Summary 254
Chapter 10: Image Manipulation 255
Eye of GNOME Image Viewer 256
Using the Image Viewer 256
Supported File Types 260
The GIMP Image Editor 261
Starting GIMP 261
GIMP Basic Tools 261
Using GIMP 263
F-Spot Photo Manager 268
The F-Spot Layout 268
Using the F-Spot Editor 273
Summary 276
Chapter 11: Using Audio 277
Audio File Basics 278
Controlling Sound in Ubuntu 279
Sound Preferences 280
The Sound Applet 282
Rhythmbox 284
Playing Audio CDs 284
Playing Audio Files 286
Listening to Internet Audio 288
Ripping Audio CDs 289
Brasero 290
Sound Recorder 291
Playing Audio Files from Nautilus 292
Summary 294
Chapter 12: Using Video 295
Video Formats 296
The Totem Movie Player 297
The Totem Interface 298
The Totem Preferences Settings 301
Trang 18Watching Web Clips 302
Checking Your Plug-ins 303
Adding Plug-ins 304
More Video Support 306
Editing Videos 307
Installing Kino 308
The Kino Interface 309
The Kino Preferences Settings 310
Summary 311
PART 3: Managing Your Workstation 313
Chapter 13: Software Installs and Updates 315
Software Management in Ubuntu 316
Software Packages 316
Software Repositories 316
Configuring Software Repositories 317
Installing Updates 319
The Update Manager 319
Using the Update Manager Applet 321
Installing New Applications 322
The Add/Remove Applications Window 322
Adding a New Application 324
Removing an Application 326
Installing New Packages 327
The Synaptic Layout 328
Installing Packages 331
Removing Packages 333
Command-Line Package Management 333
Setting Repositories 333
Apt-get Commands 334
Summary 336
Chapter 14: Networking 337
Networking Basics 338
Internet Connection Types 338
Ethernet Connections 341
Connecting to the Network 343
GNOME PPP 343
Network Manager 345
Network Tools 349
Devices 350
Ping 351
Netstat 352
Traceroute 354
Port Scan 355
Trang 19Lookup 355
Finger 357
Whois 357
Firewalls 358
Installing Firestarter 359
Starting Firestarter 360
Using Firestarter 360
Summary 364
Chapter 15: External Devices 367
Printers 368
The Printer Configuration Tool 368
Printer Server Settings 369
Adding a New Printer 370
Modifying Printer Properties 372
Scanners 376
Detecting the Scanner 376
Scanning a Document 379
The Work Area 380
Digital Cameras 383
Portable Music Players 385
Summary 386
Chapter 16: The Display 387
The X Windows System 388
What Is X Windows? 388
Linux X Windows Software 389
The X.Org Configuration 390
Ubuntu Video Configuration 394
The Screen Resolution Utility 394
Setting Compiz Fusion Features 396
Monitor and Video Cards 401
Using 3-D Cards 403
Ubuntu 3-D Support 403
Viewing Restricted Hardware Drivers 404
Summary 404
Chapter 17: Users and Groups 407
The User Administration Tool 408
Adding Users 408
Modifying Users 412
Deleting Users 413
Ubuntu Groups 414
Adding Groups 416
Modifying Groups 417
Deleting Groups 418
User and Group Files 418
The Users File 418
Trang 20The Groups File 419
Using the Command Line 420
Understanding File Permissions 421
File Properties 421
Changing File Permissions 422
Summary 423
Chapter 18: Basic Administration 425
Monitoring the System 426
System 426
Processes 427
Resources 429
File Systems 430
Log Files 431
Ubuntu Log Files 431
The System Log Viewer 432
Starting Services 433
Starting and Stopping Services 433
Service Properties 435
Sessions 436
Startup Programs 437
Options 437
Disk Usage Analyzer 438
Summary 440
Chapter 19: The Ubuntu Command Line 441
The GNOME Terminal Program 442
Session Tabs 442
The Menu Bar 443
The Command-Line Parameters 446
Command-Line Basics 447
Setting the Command Prompt 447
The bash Manual 449
Traversing Directories 451
File and Directory Listing 452
File Handling 458
Directory Handling 464
Summary 466
PART 4: Using the Ubuntu Server 467
Chapter 20: DNS Server 469
History of Computer Names 470
Domain Names 470
DNS Structure 470
Finding Domains 472
Trang 21DNS Database Records 473
DNS Protocol 478
Ubuntu as a DNS Client 478
Configuring DNS Client Files 479
Ubuntu Client DNS Programs 480
Ubuntu as a DNS Server 486
The named Files 486
Using named as a Local Cache Server 488
Using named as a Master DNS Server 489
Summary 492
Chapter 21: Web Server 493
Ubuntu Web Servers 494
Web Scripting Languages 494
The LAMP Platform 498
The Tomcat Platform 498
The Apache Web Server 499
Apache Configuration Files 500
Apache Modules 500
Creating Virtual Hosts 502
Testing the Apache Server 503
The MySQL Software 506
Accessing the Server 506
Changing the Root Password 507
The phpMyAdmin Tool 508
The PHP Software 510
The PHP Configuration Files 510
PHP Extensions 511
Using PHP 513
Tomcat 514
Tomcat Configuration 515
Testing Tomcat 515
Managing Tomcat 518
Summary 520
Chapter 22: Samba and Print Server 521
What Is Samba? 522
The Ubuntu Samba Environment 523
Samba Programs 523
Samba Configuration Files 524
Creating a Samba Server 531
Editing the smb.conf File 531
Defining Samba Passwords 532
Managing Samba 533
The Samba Client 533
The smbclient Program 533
Interacting with a Windows Share 534
Connecting from Windows 537
Trang 22The CUPS Print Server 539
Printing in Linux 539The CUPS Software 541CUPS Configuration 541Managing CUPS Printers 542Summary 546
Chapter 23: Email Server 547
How Email Works 548
Mail Transfer Agent 549Mail Delivery Agent 551Mail User Agent 553Postfix Setup 557
Postfix Core Programs 558Postfix Message Queues 559Postfix Utility Programs 560Postfix Configuration Files 561Postfix Lookup Tables 562Installing Postfix 563
Internet Site 563Internet with SmartHost 564Satellite System 565Local Only 566Configuring Postfix 567
Wizard Windows 566Modifying Configuration Settings 573procmail 574
The procmailrc File 574Using procmail 576Summary 578
Chapter 24: Database Server 579
The MySQL Server 580
The MySQL Server Files 580The mysql Command 585Using mysql 588The PostgreSQL Server 590
The PostgreSQL Files 591The psql Command 594Using psql 597Working with Databases 599
Creating a Database 599Managing Users 600Building Tables 602Adding and Viewing Data 603Summary 604
Trang 23Part 5: Programming in Ubuntu 605
Chapter 25: Shell Scripts 607
Using Multiple Commands 608
Creating a Script File 608
Displaying Output 610
Using Variables 612
Environment Variables 612User Variables 613The Backtick 615
Redirecting Input and Output 616
Output Redirection 616Input Redirection 617Pipes 618
Performing Math 620
The expr Command 620Using Brackets 622
A Floating-Point Solution 623Exiting the Script 626
Checking the Exit Status 627The exit Command 628Structured Commands 629
The if-then-else Statement 629The test Command 631Summary 636
Chapter 26: Perl and Python 637
What Is Perl? 638
Working with Perl 638
Command-Line Interpreter 639Creating a Perl Program 640Perl Programming 640
Using Variables in Perl 641Structured Commands 644Perl Operators 646Regular Expressions 648Perl Command-Line Arguments 650Perl Modules and CPAN 651
Summary 659
Trang 24Chapter 27: C Programming 661
C Programming in Ubuntu 662
The GNU Compiler 662The GNU Assembler 665The GNU Linker 668The GNU Debugger Program 671The GNU objdump Program 674The GNU Profiler Program 676Writing C Programs 681
C Program Format 681Sample Program 684Summary 685
Chapter 28: Java 687
The Java Development Environment 688
Java Programs 688Platforms 689Ubuntu Java Environments 690
Using OpenJDK 691
Installing OpenJDK 692OpenJDK Components 692Java Development Environments 693
Command-Line Tools 694NetBeans 703Eclipse 707Summary 711
Chapter 29: Ruby 713
What Is Ruby? 714
Ruby on the Web 714Ruby on Rails 715Installing Ruby 715
Ruby Components 715Installing Ruby in Ubuntu 716Working with Ruby Code 719
Interactive Ruby 719Scripting with Ruby 720Embedded Ruby 721The Ruby Language 722
Variables 722Structured Commands 725Object-Oriented Programming 730
Creating Classes 730Using Objects 731Adding Methods 732
Trang 25Ruby on Rails 732
Creating a Project 733Testing the Project 736Summary 739
Chapter 30: PHP 741
What Is PHP? 742
PHP in Ubuntu 743
Core Installation 743PHP Extensions 745Working with PHP 747
Defining PHP Code 747PHP Output 749The PHP Language 751
PHP Variables 751Iterating Through Arrays 754Structured Commands 754Including External Files 756Working with MySQL 759Object-Oriented PHP 760
Creating a Class in PHP 761Creating Objects 761Writing OOP Code in PHP 762Expanding on OOP 763Class Constructors 765PECL and PEAR 768
Summary 768
Index 771
Trang 27Welcome to Ubuntu Linux Secrets Like all books in the Secrets series, you can expect to
find both hands-on tutorials and real-world practical application information, as well as reference and background information that provides a context for what you are learning
This book is a fairly comprehensive resource on the Ubuntu Linux distribution By the
time you have completed Ubuntu Linux Secrets you will be well-prepared to utilize your
Ubuntu workstation or server to its fullest
Who Should Read This Book
If you’re new to the Linux world, you’ll benefit greatly from this book’s hands-on approach
The book walks through all of the steps required for setting up an Ubuntu Linux system, guiding you through the pitfalls and offering practical advice for getting your Ubuntu workstation up and running It then walks through all of the applications you’ll find on your new system, showing you how to use the office productivity software; work with images, audio and video clips on your desktop; run CDs and DVDs; and interact with the Internet
If you’re an advanced Linux enthusiast, you’ll also benefit from Ubuntu Linux Secrets
Nowadays it’s easy to get lost in the graphical world of prebuilt desktop packages Most desktop Linux distributions try their best to hide the Linux system from the typical user
However, there are times when you have to know what’s going on under the hood This book shows you how to use the Ubuntu administration features to manage your system, including monitoring programs, users, and disk space It shows how to access the Linux command-line prompt and what to do once you get there It also explains how to use your Ubuntu system as a complete program development platform, discussing how to program using shell, Perl, and Python scripts; the C, Java, and Ruby programming languages; and the PHP web-scripting language
Ubuntu Linux Secrets also walks the seasoned system administrator through how to use
the various server software packages included in the Ubuntu server distribution It cusses how to set up a complete web server using both the LAMP and Tomcat web servers and a database server using the popular MySQL or the feature-rich PostgreSQL database package, how to interact on a Microsoft Windows network using the Samba software, and how to create an email server for your home or organization
dis-How This Book Is Organized
This book is organized to lead you through the basics of the Ubuntu Linux distribution features, from installing your system to using the installed applications The book is divided into five parts, each one building on the previous parts
Part 1 starts you out on your Ubuntu Linux journey by helping you get your Ubuntu system running Chapter 1, “What Is Ubuntu?” walks through the complicated world of Linux distributions, describing why there are so many distributions and what the Ubuntu
Trang 28Linux distribution has to offer After explaining the basics of the Ubuntu system, Part 1 continues with
Downloading and working with the Ubuntu LiveCD (Chapter 2)
♦
♦Installing Ubuntu on your PC (Chapter 3)
♦
♦Exploring the features of the GNOME desktop (Chapter 4)
♦
♦
In Part 2, the book takes you through the features you’ll find in the Ubuntu workstation:
Working with files and folders in Ubuntu (Chapter 5)
♦
♦Working with text files using the Ubuntu text editors (Chapter 6)
♦
♦Using the OpenOffice.org office productivity suite (Chapter 7)
♦
♦Becoming familiar with the Ubuntu Network applications (Chapter 8)
♦
♦Accessing your email with the Evolution email software (Chapter 9)
♦
♦Working with image files (Chapter 10)
♦
♦Playing and ripping CDs (Chapter 11)
♦
♦Playing DVDs and watching video clips from the Internet (Chapter 12)
♦
♦Part 3 shows you how to manage your Ubuntu system:
Installing and updating software packages (Chapter 13)
♦
♦Configuring network access (Chapter 14)
♦
♦Installing and using external devices such as printers and scanners (Chapter 15)
♦
♦Configuring your display and setting up multiple monitors (Chapter 16)
♦
♦Adding new users (Chapter 17)
♦
♦Controlling running programs and monitoring the system (Chapter 18)
♦
♦Using the Ubuntu command line (Chapter 19)
♦
♦
In Part 4, you’ll see how to install and configure the Ubuntu server packages:
Creating a domain name server (DNS) (Chapter 20)
♦
♦Maintaining a web server for dynamic web applications (Chapter 21)
♦
♦Using Samba to interact with other devices on a Microsoft Windows network
♦
♦(Chapter 22)Managing a complete email server (Chapter 23)
♦
♦Running a full-featured database server using either MySQL or PostgreSQL
♦
♦(Chapter 24)The last section of the book, Part 5, demonstrates how to use your Ubuntu workstation as
a complete programming development environment:
Writing and running shell scripts from the Ubuntu command line (Chapter 25)
♦
♦Working with Perl and Python scripts to manipulate data (Chapter 26)
♦
♦Using the C programming language to create professional applications
♦
♦(Chapter 27)Installing the Java programming environment to write applications (Chapter 28)
♦
♦Installing Ruby to write local and web applications (Chapter 29)
♦
♦Using PHP on the Ubuntu LAMP server to write dynamic web applications
♦
♦(Chapter 30)
Trang 29Conventions and Features
There are many different organizational and typographical features throughout this book designed to help you get the most of the information
Secrets
When the author wants to provide additional information to help you get the most out of your Ubuntu system, the information will appear in a Secrets sidebar, separate from the main chapter material
Minimum Requirements
To get the most from the Ubuntu workstation software you must have a PC with at least a 700-MHz processor, 384 MB of system memory (RAM), 8 GB of disk space, and a graph-ics card capable of at least 1024 × 768 resolution It also helps to have a sound card if you plan on working with audio and video, and a network card if you plan on interacting with
a local network or the Internet
Where to Go from Here
Once you’ve completed Ubuntu Linux Secrets you’ll be well on your way to being an
Ubuntu Linux guru In the ever-changing world of Linux, it’s always a good idea to stay
in touch with new developments The Ubuntu Linux distribution comes out with a new version every 6 months, adding new features and removing some older ones To keep your knowledge of Ubuntu fresh, it’s important to stay well informed Find a good Linux forum on the web and monitor what’s going on in the Linux world There are many popular sites, such as Slashdot and Distrowatch, that provide up-to-the-minute information about advances in Linux It’s also a good idea to keep an eye on the Ubuntu distribution site itself Each new release goes through a series of beta releases, which are a great way to
be introduced to new features before they’re released in the next version
The information in the Secrets sidebars is important and is set off in a separate paragraph with a special icon Secrets provide additional information about things
to watch out for, tips on how to better use a feature, or background information that helps in understanding a topic
Trang 31Starting Out with Ubuntu
Chapter 1: What Is Ubuntu?
Chapter 2: Playing with the LiveCD Chapter 3: Installing Ubuntu Chapter 4: Exploring the Desktop
Trang 33What is Ubuntu?
Secrets in This Chapter
The Linux Kernel The GNU Utilities The Linux Desktop Environments Linux Distributions
Ubuntu Linux
1
Trang 34One of the most confusing features of Linux is the concept of a distribution Many
novice Linux users get confused about what a distribution is and why there are so many of them
Before diving into the world of Ubuntu, it often helps to have an understanding of what Linux is and how it relates to Ubuntu This will help you understand where Ubuntu came from, and you’ll have a better idea of which flavor of Ubuntu is right for you With that in mind, this chapter explains what Linux and Linux distributions are, then it explains the pieces that specifically make up the Ubuntu Linux distribution It finishes by walking through different Ubuntu distributions and discussing what each provides
What Is Linux?
If Ubuntu is your first experience with Linux, you may be confused about why there are so many different versions of it I’m sure you have heard various terms such as “distribution,”
“LiveCD,” and “GNU” when looking at Linux packages—and have been confused
Trying to wade through the world of Linux for the first time can be a tricky experience
Even for experienced Linux users, trying to figure out the features that distinguish ferent distributions can be tricky This section walks through exactly what Linux is and describes each of its components
dif-For starters, there are four main parts of a Linux system:
The Linux kernel
♦
♦The GNU utilities
♦
♦Windows management software
♦
♦Application software
♦
♦Each of these four parts has a specific job in the Linux system However, each of the parts
by itself isn’t very useful You need all of them in one package to have a Linux system
Figure 1-1 shows a basic diagram of how the parts fit together to create the overall Linux system
This section describes these four main parts in detail and gives you an overview of how they work together to create a complete Linux system
The Linux Kernel
The core of the Linux system is the kernel The kernel controls all of the hardware and ware on the computer system, allocating hardware when necessary, and executing software when required
soft-If you’ve been following the Linux world at all, no doubt you’ve heard the name Linus Torvalds Linus is the person responsible for creating the first Linux kernel software, when
he was a student at the University of Helsinki He intended it to be a copy of the UNIX system, at the time a popular operating system used at many universities
After developing the Linux kernel, Linus released it to the Internet community and ited suggestions for improving it This simple process started a revolution in the world of computer operating systems Soon Linus was receiving suggestions from students as well
solic-as professional programmers from around the world
Trang 35Application Software
WindowsManagement
SystemUtilities
Linux kernel
computer hardware
Figure 1-1: The Linux system
Allowing anyone to change programming code in the kernel would result in complete chaos Therefore, to simplify things, Linus acted as a central point for all improvement suggestions It was ultimately Linus’s decision whether or not to incorporate suggested code in the kernel This same concept is still in place with the Linux kernel code, except instead of Linus controlling the kernel code alone, a team of developers has taken on the task
The kernel is primarily responsible for four main functions:
System memory management
♦
♦Software program management
♦
♦Hardware management
♦
♦Filesystem management
♦
♦The following sections explore each of these functions in more detail
System Memory Management
One of the primary functions of the operating system kernel is memory management
Not only does the kernel manage the physical memory available on the server, it can also
create and manage virtual memory, or memory that does not actually exist.
It does this by using space on the hard disk, called the swap space The kernel swaps the
contents of virtual memory locations back and forth from the swap space to the actual physical memory This process allows the system to think there is more memory available than what physically exists (as shown in Figure 1-2)
Trang 36Virtual Memory
PhysicalMemory
Swap Space
The Kernel
Figure 1-2: The Linux system memory usage
The memory locations are grouped into blocks called pages The kernel locates each page
of memory in either the physical memory or the swap space It then maintains a table of the memory pages that indicates which pages are in physical memory and which pages are swapped out to disk
The kernel keeps track of which memory pages are in use and automatically copies memory pages that have not been accessed for a period of time to the swap space area
(called swapping out) When a program wants to access a memory page that has been
swapped out, the kernel must make room for it in physical memory by swapping out a different memory page and swap in the required page from the swap space Obviously, this process takes time, and it can slow down a running process The process of swapping out memory pages for running applications continues for as long as the Linux system is running
You can see the current status of the memory on a Ubuntu system by using the System Monitor utility, as shown in Figure 1-3
The Memory graph shows that this Linux system has 380.5 MB of physical memory It also shows that about 148.3 MB is currently being used The next line shows that there is about 235.3 MB of swap space memory available on this system, with none in use at the time
By default, each process running on the Linux system has its own private memory pages
One process cannot access memory pages being used by another process
The kernel maintains its own memory areas For security purposes, no processes can access memory used by the kernel processes Each individual user on the system also has
a private memory area used for handling any applications the user starts
Often, however, related applications run that must communicate with each other One
way to do this is through data sharing To facilitate data sharing, you can create shared memory pages.
Trang 37Figure 1-3: The Ubuntu System Monitor utility, showing the current memory usage.
A shared memory page allows multiple processes to read and write to the same shared memory area The kernel maintains and administers the shared memory areas, control-ling which processes are allowed access to the shared area
The special ipcs command allows us to view the current shared memory pages on the system Here’s the output from a sample ipcs command:
test@testbox:~$ ipcs -m - Shared Memory Segments -key shmid owner perms bytes nattch status0x00000000 557056 test 600 393216 2 dest0x00000000 589825 test 600 393216 2 dest0x00000000 622594 test 600 393216 2 dest0x00000000 655363 test 600 393216 2 dest0x00000000 688132 test 600 393216 2 dest0x00000000 720901 test 600 196608 2 dest0x00000000 753670 test 600 393216 2 dest0x00000000 1212423 test 600 393216 2 dest0x00000000 819208 test 600 196608 2 dest0x00000000 851977 test 600 393216 2 dest0x00000000 1179658 test 600 393216 2 dest0x00000000 1245195 test 600 196608 2 dest0x00000000 1277964 test 600 16384 2 dest0x00000000 1441805 test 600 393216 2 desttest@testbox:~$
Trang 38Each shared memory segment has an owner that created the segment Each segment also has a standard Linux permissions setting that sets the availability of the segment for other users The key value is used to allow other users to gain access to the shared memory segment.
Software Program Management
The Linux operating system calls a running program a process A process can run in the
foreground, displaying output on a display, or it can run in the background, behind the scenes The kernel controls how the Linux system manages all the processes running on the system
The kernel creates the first process, called the init process, to start all other processes on
the system When the kernel starts, it loads the init process into virtual memory As the kernel starts each additional process, it allocates to it a unique area in virtual memory to store the data and code that the process uses
Most Linux implementations contain a table (or tables) of processes that start cally on boot-up This table is often located in the special file /etc/inittabs However, the Ubuntu Linux system uses a slightly different format, storing multiple table files in the /etc/event.d folder by default
automati-The Linux operating system uses an init system that utilizes run levels A run level can
be used to direct the init process to run only certain types of processes, as defined in the /etc/inittabs file or the files in the /etc/event.d folder There are seven init run levels in the Linux operating system Level 0 is for when the system is halted, and level
6 is for when the system is rebooting Levels 1 through 5 manage the Linux system while it’s operating
At run level 1, only the basic system processes are started, along with one console
ter-minal process This is called Single User mode Single User mode is most often used for
emergency filesystem maintenance when something is broken Obviously, in this mode only one person (usually the administrator) can log into the system to manipulate data
The standard init run level is 3 At this run level most application software, such as work support software, is started Another popular run level in Linux is 5 This is the run level where the system starts the graphical X Window software and allows you to log in using a graphical desktop window
net-The Linux system can control the overall system functionality by controlling the init run level By changing the run level from 3 to 5, the system can change from a console-based system to an advanced, graphical X Window system
Later on, in Chapter 19, “The Command Line,” you’ll see how to use the ps command to view the processes currently running on the Ubuntu system Here are a few lines extracted from the output of the ps command:
test@testbox~$ ps axPID TTY STAT TIME COMMAND
Trang 39All other processes that start after the init process are assigned PIDs in numerical order
No two processes can have the same PID
The third column shows the current status of the process The first letter represents the state the process is in (S for sleeping, R for running) The process name is shown in the last column Processes that are in brackets have been swapped out of memory to the disk swap space due to inactivity You can see that some of the processes have been swapped out, but the running processes have not
Hardware Management
Still another responsibility for the kernel is hardware management Any device that the Linux system must communicate with needs driver code inside the kernel code The driver code allows the kernel to pass data back and forth to the device, acting as a intermedi-ary between applications and the hardware Two methods are used for inserting device driver code in the Linux kernel:
Drivers compiled in the kernel
♦
♦Driver modules added to the kernel
♦
♦Previously, the only way to insert a device driver code was to recompile the kernel
Each time you added a new device to the system, you had to recompile the kernel code
This process became even more inefficient as Linux kernels supported more hardware
Fortunately, Linux developers devised a better method to insert driver code into the ning kernel
run-Programmers developed the concept of kernel modules to allow you to insert driver code
into a running kernel without having to recompile the kernel Also, a kernel module can
be removed from the kernel when the device is finished being used This improvement greatly simplified and expanded the use of hardware with Linux
Trang 40The Linux system identifies hardware devices as special files, called device files There
are three classifications of device files:
Character
♦
♦Block
♦
♦Network
♦
♦
Character device files are for devices that can handle data only one character at a time
Most types of modems and terminals are created as character files Block files are for
devices that can handle data in large blocks at a time, such as disk drives
The network file types are used for devices that use packets to send and receive data These
devices include network cards and a special loopback mechanism that allows the Linux system to communicate with itself using common network programming protocols
Linux creates special files, called nodes, for each device on the system All communication
with the device is performed through the device node Each node has a unique number pair that identifies it to the Linux kernel The number pair includes a major and a minor device number Similar devices are grouped into the same major device number The minor device number is used to identify a specific device within the major device group
This is an example of device files on a Linux server:
test@testbox~$ ls -al sda*
brw-rw 1 root disk 8, 0 2008-05-07 11:42 /dev/sdabrw-rw 1 root disk 8, 1 2008-05-07 11:42 /dev/sda1brw-rw 1 root disk 8, 2 2008-05-07 11:42 /dev/sda2brw-rw 1 root disk 8, 5 2008-05-07 11:42 /dev/sda5test@testbox~$ ls -al ttyS*
crw-rw 1 root dialout 4, 64 2008-05-07 11:42 /dev/ttyS0crw-rw 1 root dialout 4, 65 2008-05-07 11:42 /dev/ttyS1crw-rw 1 root dialout 4, 66 2008-05-07 11:42 /dev/ttyS2crw-rw 1 root dialout 4, 67 2008-05-07 11:42 /dev/ttyS3test@testbox~$
The sda device is the first SCSI hard drive, and the ttyS devices are the standard IBM-PC COM ports The list shows all of the sda devices that were created on the sample Ubuntu system Similarly, the list shows all of the ttyS devices created
The fifth column is the major device node number Notice that all of the sda devices have the same major device node, 8, while all of the ttyS devices use 4 The sixth column is the minor device node number Each device within a major number has a unique minor device node number
The first column indicates the permissions for the device file The first character of the missions indicates the type of file Notice that the SCSI hard drive files are all marked as block (b) device, while the COM port device files are marked as character (c) devices
per-Filesystem Management
Unlike some other operating systems, the Linux kernel can support different types of systems to read and write data to hard drives Besides having over a dozen filesystems of its own, Linux can read and write to filesystems used by other operating systems, such as Microsoft Windows The kernel must be compiled with support for all types of filesystems that the system will use Table 1-1 lists the standard filesystems that a Linux system can use to read and write data