47
CIT 500: IT Fundamentals Packages and Filesystems 1

CIT 500: IT Fundamentals Packages and Filesystems 1

Embed Size (px)

Citation preview

Page 1: CIT 500: IT Fundamentals Packages and Filesystems 1

CIT 500: IT Fundamentals

Packages and Filesystems

1

Page 2: CIT 500: IT Fundamentals Packages and Filesystems 1

Topics

1. Packages1. The software installation problem2. UNIX package managers3. Dependencies4. Advanced package managers

2. Filesystems1. Filesystem types2. Integrity and repair3. Permissions and attributes

2

Page 3: CIT 500: IT Fundamentals Packages and Filesystems 1

Software Installation

1. CustomizationSelect options like language.Select file set.

2. Install new files in appropriate locations.3. Modify existing configuration files.4. Make software available to user.

Shell configuration (PATH, etc.)GUI configuration (menu, icons, etc.)

3

Page 4: CIT 500: IT Fundamentals Packages and Filesystems 1

What’s the problem?

What prerequisites does your software have?What prereqs do your prereq packages have?

How do you handle conflicts?What if two programs install/modify same file?

Does your install work on every type of computer?How do you handle upgrades?

What if user has customized configuration?What if ownerships/permissions have changed?What if user needs old and new versions?

How do you uninstall software?4

Page 5: CIT 500: IT Fundamentals Packages and Filesystems 1

Package Manager Features

• Build management.• Dependency tracking.• Querying.• Reversibility.• Verification.• Version control.

5

Page 6: CIT 500: IT Fundamentals Packages and Filesystems 1

UNIX Package Management Systems

deb: Debian system uses dpkg and APT.pkgadd: Solaris packaging system.portage: Gentoo uses with emerge.ports: BSD ports system.RPM: Redhat packaging system.tgz: Tarballs used by Slackware.

6

Page 7: CIT 500: IT Fundamentals Packages and Filesystems 1

dpkg

Debian package system– Original version created in 1993– APT introduced in 1998

Distributions– Debian– Knoppix– Linspire– MEPIS– Ubuntu

dpkg on other OS– Fink on MacOS X

7

Page 8: CIT 500: IT Fundamentals Packages and Filesystems 1

RPMRPM Package Manager

– Originally stood for Red Hat Package Manager– Came with Red Hat Linux 2.0 in 1995.

Distributions– Red Hat– Red Hat Enterprise Linux (also CentOS)– Fedora– Mandriva– SUSE

RPMs are not compatible between distributions.RPM on other OS

– AIX– Novell Netware

8

Page 9: CIT 500: IT Fundamentals Packages and Filesystems 1

RPM Package Names

<name>-<version>-<release>.<arch>.rpm Name: name of the software package.Version: version of the software package.Release: release version of the RPM.Arch: architecture (i386, noarch, ppc, etc.)If Arch is src, RPM contains source code for

building the package.

9

Page 10: CIT 500: IT Fundamentals Packages and Filesystems 1

RPM Package Contents

IdentificationIdentifies package and RPM version.

SignatureChecksum and digital signature.

HeaderPackage and version information.Specifies dependencies on other packages.

PayloadActual files to install.Stored as cpio archive compressed with gzip.Use rpm2cpio to obtain cpio archive.

10

Page 11: CIT 500: IT Fundamentals Packages and Filesystems 1

Using RPM

1. Install2. Uninstall3. Upgrade4. Query5. Verify

11

Page 12: CIT 500: IT Fundamentals Packages and Filesystems 1

Installing a Package1. Check the package and the files it wants to install. 2. Perform preinstallation tasks.3. Uncompress the files and copy them in the proper

locations 4. Perform post-processing tasks 5. Update the RPM Database

> rpm -ivh foo-1.0-1.i386.rpm

Preparing... ########################################### [100%]

1:foo ########################################### [100%]

12

Page 13: CIT 500: IT Fundamentals Packages and Filesystems 1

Upgrading a PackageUninstall + install, retaining configuration files.

Will install a package if no older version.Will remove all older versions.

Typically use –U instead of –i for installs too.

> rpm -Uvh foo-1.0-1.i386.rpm

Preparing... ########################################### [100%]

1:foo ########################################### [100%]

13

Page 14: CIT 500: IT Fundamentals Packages and Filesystems 1

Uninstalling a PackageCompletely removes package from system.

> rpm -e foo-1.0-1

> rpm –q foo

package foo is not installed.

14

Page 15: CIT 500: IT Fundamentals Packages and Filesystems 1

Dependencies

Prevent install/removal if unfulfilled.

# rpm -e setup error: Failed dependencies: setup is needed by (installed) basesystem-8.0-1 setup >= 2.0.3 is needed by (installed) initscripts-

6.95-1 setup >= 2.5.4-1 is needed by (installed)

filesystem-2.1.6-5 setup is needed by (installed) xinetd-2.3.7-2 setup is needed by (installed) dump-0.4b28-4 # rpm -q setup

setup-2.5.20-1

15

Page 16: CIT 500: IT Fundamentals Packages and Filesystems 1

RPM Database

Tracks global package information:– List of all packages– Dependencies between packages

For each package, stores:– Name, version, and architecture (-q)– Information fields, including description (-qi)– List of files (-ql), config files (-qc), doc files (-qd)– Date of install

16

Page 17: CIT 500: IT Fundamentals Packages and Filesystems 1

Querying the RPM Database# rpm -q telnettelnet-0.17-31.EL4.3# rpm -ql telnet/usr/bin/telnet/usr/share/man/man1/telnet.1.gz# rpm -qi telnetName : telnet Relocations: (not)Version : 0.17 Vendor: CentOSRelease : 31.EL4.3 Build Date: Tue 14 Jun 2005Install Date: Sat 11 Feb 2006 Build Host: build5Group : Applications/Internet Src RPM: telnet-0.17.src.rpmSize : 87254 License: BSDSignature : DSA/SHA1, Tue 14 Jun 2005, Key ID a53d0bab443e1821Packager : Johnny Hughes <[email protected]>Summary : Client program for telnet remote login protocol.Description :Telnet is a popular protocol for logging into remote systemsover the Internet. The telnet package provides a command linetelnet client.

17

Page 18: CIT 500: IT Fundamentals Packages and Filesystems 1

Querying the RPM Database# rpm -qc bash/etc/skel/.bash_logout/etc/skel/.bash_profile/etc/skel/.bashrc# rpm -qd sendmail/usr/share/man/man1/mailq.sendmail.1.gz/usr/share/man/man1/newaliases.sendmail.1.gz/usr/share/man/man5/aliases.sendmail.5.gz/usr/share/man/man8/mailstats.8.gz/usr/share/man/man8/makemap.8.gz/usr/share/man/man8/praliases.8.gz/usr/share/man/man8/rmail.8.gz/usr/share/man/man8/sendmail.sendmail.8.gz/usr/share/man/man8/smrsh.8.gz

18

Page 19: CIT 500: IT Fundamentals Packages and Filesystems 1

Searching all Packages# rpm -qa | grep telnettelnet-0.17-31.EL4.3# rpm -qa | grep pypython-2.3.4-14.1pyOpenSSL-0.6-1.p23rpm-python-4.3.3-11_nonptlpygtk2-2.4.0-1python-devel-2.3.4-14.1python-ldap-2.0.1-2pyxf86config-0.3.19-1libxml2-python-2.6.16-6python-elementtree-1.2.6-4python-sqlite-1.1.6-1dbus-python-0.22-12.EL.5pyparted-1.6.8-2python-urlgrabber-2.9.6-2

19

Page 20: CIT 500: IT Fundamentals Packages and Filesystems 1

Searching all Packages

Find recently installed packagesrpm -qa --last

Find packages that are disk hogsrpm -qa --qf "%{size} %{name}\n" | sort –n

The --qf (queryformat) option can printarch, name, size, version, distribution, etc.

20

Page 21: CIT 500: IT Fundamentals Packages and Filesystems 1

Querying Files and Packages

Find which package a file belongs to:# rpm -qf /usr/bin/telnet

telnet-0.17-31.EL4.3

# rpm -qf /etc/security/limits.conf

pam-0.77-66.11

Querying packagesAdd –p to any query to apply it to a .rpm file instead of to

an installed package.

21

Page 22: CIT 500: IT Fundamentals Packages and Filesystems 1

Verifying PackagesVerifying a package returns nothing if ok

# rpm -V telnet

Returns errors if package has problems# rpm -V telnet-server

missing c /etc/xinetd.d/telnet

missing /usr/sbin/in.telnetd

missing d /usr/share/man/man5/issue.5.gz

22

Page 23: CIT 500: IT Fundamentals Packages and Filesystems 1

RPM OptionsSpecify multiple RPMs at once.

RPM will re-order installs to resolve dependencies.

Prefix: install in new location.rpm --prefix /usr/local –Uvh *.rpm

Oldpackage: revert to an older versionrpm --oldpackage –Uvh foo-0.9-2.i386.rpm

Forcing install, upgrade, or removal--force allows overwriting of files/packages.--nodeps allows install w/o dependency check.

23

Page 24: CIT 500: IT Fundamentals Packages and Filesystems 1

Dependency Resolution

Higher level tools handle dependenciesup2date, yum, yast, urpmi

Automatic resolution + downloading.1. Find dependencies in RPM headers.2. Download dependencies, check their headers.3. Repeat.4. Install after all RPMs downloaded.

24

Page 25: CIT 500: IT Fundamentals Packages and Filesystems 1

Yellow Dog Updater Modified– Rewrite of YUP from Yellow Dog Linux.– Used by many RPM-based distributions.

Automatically syncs repo metadata.– Prevents problems arising from out of data

package information on local system.– Wastes time when local data up to date.

25

Page 26: CIT 500: IT Fundamentals Packages and Filesystems 1

Yum Installs

yum install pkg: finds specified package, downloads it, and installs it.

yum remove pkg: remove the specified package from the system.

yum update <pkg>: updates specified package or updates all packages if no package specified.

26

Page 27: CIT 500: IT Fundamentals Packages and Filesystems 1

yum list <option> <pkgspec>Options:

available: list packages available to be installed.installed: list installed packages like rpm –qa.extras: lists installed packages that are not available on any

currently configured repo.recent: lists packages added to repositories in last 7 days.updates: lists updates for any installed packages.

Package Specifications:bashbash-3.10\*sh\*.i386

27

Page 28: CIT 500: IT Fundamentals Packages and Filesystems 1

Yum Commands

check-update: lists updates, returns 100 if any updates available.

clean: removes yum cache files.deplist: list all dependencies for a package.info: list package data like rpm –qiyum provides: find which package provides the specified

command, i.e. yum provides \*bin/ls.yum search: lists packages whose name, summary,

description, or URL matches the specified search term.

28

Page 29: CIT 500: IT Fundamentals Packages and Filesystems 1

Package Sources

Sources– Local files (CD/DVD or hard disk)– Red Hat Network commercial sites for RHEL– CentOS network official mirrors for CentOS– Unofficial network repositories like RPMforge

Source configurationup2date: /etc/sysconfig/rhn/sources

yum: /etc/yum.conf, /etc/yum/repos.d

29

Page 30: CIT 500: IT Fundamentals Packages and Filesystems 1

Finding RPMs

1. The Red Hat Enterprise Linux CD-ROMs2. The Red Hat Errata Page available at

http://www.redhat.com/apps/support/errata/ 3. A Red Hat FTP Mirror Site available at

http://www.redhat.com/download/mirror.html4. Dag RPM Repository at

http://dag.wieers.com/home-made/apt/

5. Search for RPMs at www.rpmfind.net.6. Search for RPMs at rpm.pbone.net.

30

Page 31: CIT 500: IT Fundamentals Packages and Filesystems 1

Filesystem Types

Disk-based Filesystems– Filesystems designed to store files to a fixed or removable

permanent storage device.

Flash Filesystems– Flash can only be written to 1000s of times.– Re-arrange block usage to avoid writing too many times to

any one block on flash.

Journaling Filesystems– Modify how writes are done to provide greater data

integrity in case of a system crash.

31

Page 32: CIT 500: IT Fundamentals Packages and Filesystems 1

Filesystem Tree Structure/

bin boot tmp usr var

ls grub bin lib X11R6

vmlinuzmenu.lst

less

zip bin lib

xclock xterm

32

Page 33: CIT 500: IT Fundamentals Packages and Filesystems 1

Journaling Filesystems

Problem: writing to file involves many disk writes1. Modify inode to change file size2. (potentially) Add new data block to used block map3. (potentially) Add pointer to new data block4. Write to new data block

Journaling filesystems perform writes by:1. Write blocks to journal.2. Wait for write to be committed to journal.3. Write blocks to filesystem.4. Discard blocks from journal.

33

Page 34: CIT 500: IT Fundamentals Packages and Filesystems 1

Common Disk-based Filesystems

Extended Filesystem– ext2: first full featured UNIX fs for Linux in 1993

• Recommended use: USB + other solid state drives.– ext3: ext2 + journalling– ext4: faster version of ext3 with larger file support

Microsoft Filesystems– FAT: inefficient disk usage, slow, 8+3 filenames

• 16- and 32-bit versions used on flash storage– NTFS: modern filesystem, many versions

• Supports long + old 8+3 filenames for compatibility

34

Page 35: CIT 500: IT Fundamentals Packages and Filesystems 1

Ext2 Disk Data Structures

35

Page 36: CIT 500: IT Fundamentals Packages and Filesystems 1

Inode Block Addressing

Slide #36

Page 37: CIT 500: IT Fundamentals Packages and Filesystems 1

Creating a Filesystem

Select a disk partition to create filesystem onfdisk –l /dev/sda will list partitions on 1st diskfdisk –l /dev/sdb will list partitions on 2nd disk, etc.

Run mke2fs –v /dev/sda2Creates ext2 filesystem on 2nd partition of 1st diskWipes any data already existing on that filesystemAdd a –j option to create an ext3 journaling fs.

37

Page 38: CIT 500: IT Fundamentals Packages and Filesystems 1

Mounting a Filesystem

1. Create a mountpointmkdir -p /stor/video

2. Mount filesystem on chosen directorymount -t ext3 /dev/sda2 /stor/video

3. Use filesystem4. Unmount filesystem when done

umount /dev/sda2Happens automatically at reboot or shutdown

38

Page 39: CIT 500: IT Fundamentals Packages and Filesystems 1

Automatic MountingFilesystems in /etc/fstab are mounted on boot.

Use mount to see current mounted filesystems.

# /etc/fstab: static file system information.

#

# <device> <mnt pt> <type> <options> <dump> <pass>

proc /proc proc defaults 0 0

/dev/sda1 / ext3 defaults 0 1

/dev/sda2 none swap sw 0 0

/dev/sda3 /home ext3 defaults 0 1

/dev/sdb1 /backup ext3 defaults 0 0

39

Page 40: CIT 500: IT Fundamentals Packages and Filesystems 1

Checking Filesystem Integrity

fsck utility performs consistency checks– Are used blocks actually used?– Do inodes point to any unused blocks?– Are used inodes pointed to by directory entries?

and repairs inconsistencies if– Sysadmin enters ‘y’ in interactive mode.– Sysadmin uses ‘-y’ argument to do all repairs.

Run fsck with unmounted partition as arg:fsck –y /dev/sda2

40

Page 41: CIT 500: IT Fundamentals Packages and Filesystems 1

Access Control: PermissionsRead

– You can read the file with cat, more, etc.

Write– You can modify the file with vi, OpenOffice, etc.

Execute– You can run the file if it’s a program.

41

Page 42: CIT 500: IT Fundamentals Packages and Filesystems 1

Three Sets of Permissions

42

Page 43: CIT 500: IT Fundamentals Packages and Filesystems 1

Access Control Commands

Changing File Access Privilegeschmod [options] octal-mode filechmod [options] symbolic file

43

Page 44: CIT 500: IT Fundamentals Packages and Filesystems 1

POSIX ACLs

Specify individual groups and users.Basic ACL user/group refers to owner.POSIX ACLs allow specifying users + groups.

To add/modify permissions for a user:setfacl –m u:username:rw- filename

To add/modify permissions for a group:setfacl –m g:groupname:rw- filename

44

Page 45: CIT 500: IT Fundamentals Packages and Filesystems 1

ACL Examples$ getfacl acltest

# file: acltest

# owner: waldenj

# group: waldenj

user::rw-

group::r--

other::r--

$ setfacl -m u:trutat:rw- acltest

$ getfacl acltest

# file: acltest

# owner: waldenj

# group: waldenj

user::rw-

user:trutat:rw-

group::r--

mask::rw-

other::r--

45

Page 46: CIT 500: IT Fundamentals Packages and Filesystems 1

File Attributes

Attributes extend file permissions:a: append-only (only root can set)i: immutable (read-only, only root can set)s: safe-delete (overwrite, not supported yet)

Use lsattr to view attributes.Most files do not have any attributes set.

Use chattr to set attributes.chattr +i /boot/vmlinuz*

46

Page 47: CIT 500: IT Fundamentals Packages and Filesystems 1

References

1. Syed Mansoor Sarwar, Robert Koretsky, Syed Ageel Sarwar, UNIX: The Textbook, 2nd edition, Addison-Wesley, 2004.

2. Nicholas Wells, The Complete Guide to Linux System Administration, Thomson Course Technology, 2005.

47