1. Trang chủ
  2. » Công Nghệ Thông Tin

Red Hat Linux Networking , System Administration (P25) ppt

30 251 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 30
Dung lượng 664,15 KB

Nội dung

fdisk -s partition fdisk [-lu] device The first form uses the -s option to display the size in (blocks) of the disk partition specified by partition and then exits. The second form operates on the disk specified by device. The -l option lists the disk geometry of device, followed by a columnar list of each partition on device showing each partition’s boot status, starting and ending cylinders, total size (in 512- byte blocks), and the partition type. If device is omitted, fdisk lists the same information based on the contents of the file /proc/partitions. The -u option instructs fdisk to show disk and partition sizes in terms sectors instead of cylinders. Omitting -l (second form) starts an interactive fdisk session on device. The parted program manipulates existing partitions. You can use it check, create, delete, resize, move, and copy the following partition types: ■■ ext2 ■■ ext3 ■■ FAT ■■ FAT32 ■■ Linux swap parted’s general syntax is: parted [opts] [dev [cmd [cmd_opts]]] To force parted to run in interactive or batch (script) mode, opts may be -i or -s, respectively. Interactive mode is the default. dev can specify any block device on which partitions can be created, such /dev/hdb or /dev/sdc or even a floppy disk (/dev/fd0). The parted rubber meets the road with the cmd argument and any associated command options specified in cmd_opts. Table 28-5 lists possible parted commands. Table 28-5 GNU parted Commands COMMAND DESCRIPTION check Checks a partition. cp Copies the contents of one partition to another. help Prints parted usage instructions. mkfs Creates a file system on a partition. 684 Chapter 28 36_599496 ch28.qxd 8/30/05 7:24 PM Page 684 Table 28-5 (continued) COMMAND DESCRIPTION mkpart Creates a primary, logical, or extended partition by specifying the starting an ending size in MB. mkpartfs Creates a primary, logical, or extended partition by specifying the starting and ending size in MB and then creates a file system of a specified type on the newly created partition. move Moves a partition by changing the starting and ending blocks, specified in MB. print Displays the current partition table. quit Exits parted. resize Resizes a partition by changing the starting and ending blocks, specified in MB. rm Deletes a partition. select Chooses the device to edit. set Changes or sets flags on a disk partition. Valid flags are boot, root, swap, hidden, raid, lvm, lba, and palo. CAUTION Exercise extreme care when using parted or any other partition editor to resize or manipulate parition tables. The tools themselves usually work fine and don’t exhibit any unexpected behavior. Nonetheless, it is simple for operator error to render a disk unbootable with a stray keystroke. Most of the commands listed in Table 28-5 accept one or more cmd_opts, which are options that specify the device or partition on which to operate, a starting and ending value, and a file system type. For complete details, refer to the parted Info page (info parted); less complete but still useful information can be found in the parted man page (man parted). Creating and Manipulating File Systems mke2fs creates a Linux ext2 or ext3 file system on a disk. Its syntax is: mke2fs [-c | -l list] [-b size] [-i bytes-per-inode] [-j] [-n] [-m reserve] [-F] [-q] [-v] [-L label] [-S] device device indicates the disk partition or other device on which to create the file system. Specifying -n results in a test run; mke2fs goes through the entire Configuring the System at the Command Line 685 36_599496 ch28.qxd 8/30/05 7:24 PM Page 685 creation process but does not actually create the file system. Use -q to sup- press output, for example, when mke2fs is used in a script. Conversely, use -v to generate verbose output. To check the disk for bad blocks while creating the file system, specify -c, or use -l list to read a list of known bad blocks from the file named list. By default, mke2fs calculates file system block sizes based on the size of the underlying partition, but you can specify -b size to force a block size of 1024, 2048, or 4096 bytes. Similarly, to override the default inode size, use -i bytes-per-inode (bytes-per-inode should be no smaller than the block size defined with -b size). -m reserve instructs mke2fs to set aside reserve percent of the file system for the root user. If -m reserve is omitted, the default reserve space is 5 percent. -L label sets the file system’s volume label, or name, to label. Normally, mke2fs refuses to run if device is not a block device (a disk of some sort) or if it is mounted; -F overrides this default. -F is most commonly used to create a file that can be mounted as a loopback file system. -S, finally, causes mke2fs to write only the superblocks and the group descriptors and to ignore the block and inode information. In essence, it attempts to rebuild the high-level file system structure without affecting the file system contents. It should be used only as a final attempt to salvage a badly corrupted file system, and may not work. The manual page recommends running e2fsck immedi- ately after using -S. To create and manipulate swap space, use the mkswap, swapon, and swapoff commands. mkswap initializes a swap area on a device (the usual method) or a file. swapon enables the swap area for use, and swapoff disables the swap space. mkswap’s syntax is: mkswap [-c] device [size] device identifies the partition or file on which to create the swap area and size specifies the size, in blocks, of the swap area to create. size is necessary only if you want a swap area smaller than the available space. If device is a file, it must already exist and be sized appropriately. -c performs a check for bad blocks and displays a list of any bad blocks found. TIP To create a swap file before using mkswap, use the following command: dd if=/dev/zero of=/some/swap/file bs=1M count=128 Replace /some/swap/file with the file you want to create as a swap file. To enable the kernel to use swap devices and files, use the swapon com- mand. Its syntax takes three forms: 686 Chapter 28 36_599496 ch28.qxd 8/30/05 7:24 PM Page 686 swapon -s swapon -a [-ev] swapon [-p priority] [-v] device The first form displays a summary of swap space usage for each active swap device. The second form, normally used in system startup scripts, uses -a to activate all swap devices listed in /etc/fstab. If -e is also specified, swapon ignores devices listed in /etc/fstab that do not exist. The third form acti- vates the swap area on device, and, if -p priority is also specified, gives device a higher priority in the swap system than other swap areas. priority can be any value between 0 and 32,767 (specified as 32767), where higher val- ues represent higher priorities. -v prints short status messages. e2fsck checks a file system for possible corruption and repairs any damage found. e2fsck is an ext2- and ext3-file-system-specific version of the more general fsck command. Ordinarily, you will use fsck, which is a wrapper program that invokes a file system-specific version of fsck depending on the type of file system. For example, if you call fsck on an ext2 or ext3 file system, it will invoke e2fsck; if you call fsck on a ReiserFS file system, fsck invokes fsck.reiserfs. e2fsck’s syntax is: e2fsck [-pcnyfvt] [-b sblock] [-B size] [-l list] device device is the partition (/dev/hda1, for example) to test. -b sblock tells e2fsck to use the backup super block located on block number sblock. -B size specifies block sizes of size bytes. -l list instructs e2fsck to add the block numbers listed in the file name list to the list of known bad blocks. Using -c causes e2fsck to identify bad blocks on the disk. Ordinarily, e2fsck asks for confirmation before repairing file system errors; specifying -p disables any confirmation prompts, -n automatically answers “No” to all questions and sets the file system to read-only, and -y automatically answers “Yes” to all questions. e2fsck’s default behavior is not to check a file system that is marked clean, but using -f forces it to do so. -v enables verbose output. -t generates a timing report at the end of e2fsck’s operation. If e2fsck discovers problems with one of your file systems that it cannot repair automatically, you might be able to use the debugfs program to repair the file system manually. resize2fs makes it possible to resize ext2 and ext3 file systems without destroying existing data and, in certain cases, without having to use fdisk or parted to resize the partition. As with parted, use resize2fs with great care and make sure you have good backups of the data on the file system you intend to resize. Configuring the System at the Command Line 687 36_599496 ch28.qxd 8/30/05 7:24 PM Page 687 The symlinks command scans directories for symbolic links, displays them on the screen, and repairs broken or otherwise malformed symbolic links. Its syntax is: symlinks [-cdrstv] dirlist dirlist is a list of one or more directories to scan for symbolic links. -r causes symlinks to recurse through subdirectories. -d deletes dangling links, symbolic links whose target no longer exists. -c converts absolute links, links defined as an absolute path from /, to relative links, links defined relative to the directory in which the link is located. -c also removes superfluous / and . elements in link definitions. -s identifies links with extra / in their defini- tion and, if -c is also specified, repairs them. To see what symlinks would do without actually changing the file system, specify -t. By default, symlinks does not show relative links; -v overrides this default. To make an existing file system available, it has to be mounted using the mount command. mount’s syntax is: mount -a [-fFnrsvw] [-t fstype] mount [-fnrsvw] [-o fsoptions] device | dir mount [-fnrsvw] [-t fstype] [-o fsoptions] device dir The first two forms use the information in /etc/fstab when mounting file systems. When invoked with no options, mount lists all mounted file systems, and when you specify only –t, fstype lists all mounted file systems of type fstype. fstype will be one of devpts, ext2, iso9660, or vfat, but many other file system types are supported — the complete list of valid types is available in mount’s manual page. The -a option mounts all the file systems listed in /etc/fstab (subject to the restriction of using the -t option as explained in the previous paragraph) that are configured using the auto mount option. (See Table 28-6.) The sec- ond form is most commonly used to override the mount options, using -o fsoptions, listed in /etc/fstab. Note that you only have to specify device, the device containing the file system, or dir, where in the directory hierarchy the file system should be attached. Use the third form to mount file systems not listed in /etc/fstab or to override information it contains. The third form is also the most widely used. In general, it attaches the file system on device to the system’s directory hier- archy at the mount point dir, using a file system type of fstype and the file system options fsoptions. Table 28-6 lists mount’s global options. fsoptions is a comma-delimited list of one or more of the options listed in Table 28-7. 688 Chapter 28 36_599496 ch28.qxd 8/30/05 7:24 PM Page 688 NOTE Because Linux supports so many file systems, this chapter discusses only a few of the many file systems and file system options. mount’s manual page contains a complete list of the file systems and their corresponding mount options that Linux currently supports. Table 28-6 Global Options for the mount Command OPTION DESCRIPTION -a Mounts all file systems, subject to restrictions specified using -t -F Mounts all file systems (used only with -a) in parallel by creating new processes for each file system to mount -f Fakes the mount operation, doing everything but actually mounting the file system -h Displays a short usage message -n Mounts the file system without creating an entry in the mount table (/etc/mtab) -o fsoptions Mounts the file system using the file system-specific options fsoptions -r Mounts the file system in read-only mode -s Ignores options specified with -o that are invalid for the given file system type (the default is to abort the mount operation) -t fstype Restricts mount’s operation to file system types of type fstype (first and second forms) or specifies the file system type of the file system being mounted (third form) -v Prints informational messages while executing (verbose mode) -w Mounts the file system in read/write mode Table 28-7 Common File System Options for the mount Command OPTION TYPE* DESCRIPTION async 1 Enables asynchronous system I/O on the file system auto 1 Enables mounting using the -a option defaults 1 Enables the default options (rw, suid, dev, exec, auto, nouser, async) for the file system dev 1 Enables I/O for device files on the file system exec 1 Enables execution of binaries on the file system (continued) Configuring the System at the Command Line 689 36_599496 ch28.qxd 8/30/05 7:24 PM Page 689 Table 28-7 (continued) OPTION TYPE* DESCRIPTION gid=gid 2,3 Assigns the GID gid to all files on the file system mode=mode 3 Sets the permissions of all files to mode noauto 1 Disables mounting using the -a option nodev 1 Disables I/O for device files on the file system noexec 1 Disables execution of binaries on the file system nosuid 1 Disables set-UID and set-GID bits on the file system nouser 1 Permits only root user to mount the file system ro 1 Mounts the file system in read-only mode remount 1 Attempts to remount a mounted file system rw 1 Mounts the file system in read/write mode suid 1 Enables set-UID and set-GID bits on the file system sync 1 Enables synchronous file system I/O on the file system user 1 Permits nonroot users to mount the file system uid=uid 2,3 Assigns the UID uid to all files on the file system 1 = All file systems, 2 = devpts, 3 = iso9660 To unmount a file system, use the command umount. Its syntax is much simpler, thankfully, than mount’s: umount -a [-nrv] [-t fstype] umount [-nrv] device | dir All of umount’s options and arguments have the same meaning as they do for mount, except for -r. Of course, the options must be understood in the context of unmounting a file system. If -r is specified and unmounting a file system fails for some reason, umount attempts to mount it in read-only mode. To access swap space, use theswapon and swapoff commands. To enable the kernel to use swap devices and files, use the swapon command. Its syntax takes three forms: swapon -s swapon -a [-ev] swapon [-p priority] [-v] device 690 Chapter 28 36_599496 ch28.qxd 8/30/05 7:24 PM Page 690 The first form displays a summary of swap space usage for each active swap device. The second form, normally used in system startup scripts, uses -a to activate all swap devices listed in /etc/fstab. If -e is also specified, swapon ignores devices listed in /etc/fstab that do not exist. The third form activates the swap area on device, and, if -p priority is also specified, gives device a higher priority in the swap system than other swap areas. priority can be any value between 0 and 32,767 (specified as 32767), where higher values rep- resent higher priorities. -v prints short status messages. To deactivate a swap area, use the swapoff command. Its syntax is simple: swapoff -a | device Use -a to deactivate all active swap areas, or use device to deactivate a specific swap area. Multiple swap areas may be specified using white space between device identifiers. Working with Files and Directories This section reviews the basic call syntax of the following commands: ■■ chmod — Modifies file and directory permission settings ■■ chown — Modifies file and directory user ownership ■■ chgrp — Modifies file and directory group ownership ■■ lsattr — Lists special file attributes on ext2 files ■■ chattr — Modifies special file attributes on ext2 files ■■ stat — Shows detailed file information ■■ fuser — Displays a list of process IDs using a file ■■ lsof — Identifies files opened by a process Here are the syntax summaries for chmod, chown, and chgrp: chmod [-cfRv] symbolic_mode file chmod [-cfRv] octal_mode file chown [-cfhRv] owner[:[group]] file chown [-cfhRv] :group file chgrp [-cfhRv] group file chmod, chown, and chgrp accept the common options -c, -v, -f, -R, and file. file is the file or directory to modify, and multiple file arguments can be specified. -R invokes recursive operation on the subdirectories of the cur- rent working directory or of a directory specified by file. -v generates a diagnostic for each file or directory examined. -c generates a diagnostic mes- sage only when it changes a file. -f cancels all but fatal error messages. Configuring the System at the Command Line 691 36_599496 ch28.qxd 8/30/05 7:24 PM Page 691 chmod has two forms because it understands both symbolic and octal nota- tion for file permissions. For both forms, file is one or more files on which permissions are being changed. symbolic_mode uses the symbolic permis- sions notation, while octal_mode expresses the permissions being set using the standard octal notation. CROSS-REFERENCE For a quick refresher on using symbolic and octal permissions notation, refer to the chmod manual page. With the chown and chgrp commands, group is the new group being assigned to file. For the chown command, owner identifies the new user being assigned as file’s owner. The colon (:) enables chmod to change file’s group ownership. The format owner:group changes file’s user and group owners to owner and group, respectively. The format owner: changes only file’s owner and is equivalent to chown owner file. The format :group leaves the owner untouched but changes file’s group owner to group (equivalent to chgrp group file). The lsattr and chattr commands are Linux-specific, providing an inter- face to special file attributes available only on the ext2 and ext3 file systems. lsattr lists these attributes, and chattr sets or changes them. lsattr’s syntax is: lsattr [-adRVv] file file is the file or directory whose attributes you want to display; multiple white space separated file arguments may be specified. -a causes the attrib- utes of all files, such as hidden files, to be listed. -d lists the attributes on direc- tories, rather than listing the contents of the directories, and -R causes lsattr to recurse through subdirectories if file names a subdirectory. chattr’s syntax is: chattr [-RV] [-v version] +|-|=mode file file is the file or directory whose attributes you want to display; multiple white space separated file arguments may be specified. -R causes lsattr to recurse through subdirectories if file names a subdirectory. -v version sets a version or generation number for file. +mode adds mode to file’s attributes; -mode removes mode from file’s attributes; =mode sets file’s attributes to mode, removing all other special attributes. mode can be one or more of the following: ■■ A — Do not change file’s time (last access time) ■■ S — Update file synchronously 692 Chapter 28 36_599496 ch28.qxd 8/30/05 7:24 PM Page 692 ■■ a — File is append-only ■■ c — Kernel automatically compresses/decompresses file ■■ d — File cannot be dumped with the dump command ■■ I — File is immutable (cannot be changed) ■■ s — File will be deleted securely using a special secure deletion algorithm ■■ u — File cannot be deleted The stat command displays detailed file or file system status information. Its syntax is: stat [-l] [-f] [-t] file file specifies the file or directory about which you want information. Use multiple white-space-delimited file arguments to specify multiple files. If -l is used and file is a link, stat operates on the link’s target (the file that is linked) rather than the link itself. Using -f causes stat to display information about file’s file system, not file. Specifying -t results in a shorter (terse) output format suitable for use in scripts. Often, an administrator needs to identify the user or process that is using a file or socket. fuser provides this functionality. Its syntax is: fuser [-a | -s] [-n namespace] [-signal] [-kimuv] name name specifies the file, file system, or socket to query. By default, fuser assumes that name is a filename. To query TCP or UDP sockets, use -n namespace, where namespace is udp for UDP sockets and tcp for TCP sockets (file is the default namespace). -a results in a report for all names specified on the command line, even if they are not being accessed by any process. -s, on the other hand, causes fuser to run silently. You cannot use -s with -a, -u, or -v. -k kills processes using name with the signal SIGKILL; use -signal to specify an alternate signal to send. Use -i (interactive) to be prompted for confirmation before killing a process. Only use -i with -k. -m indicates that name specifies a file system or block device, so fuser lists all processes using files on that file system or block device. -u adds the username of a process’s owner to its output when listing processes. -v, finally, generates a verbose, ps-like listing of processes using the specified name. For example, to see what process and user is using the Berkeley socket file /tmp/.X11-unix/X0, the following command would do: # fuser -u /tmp/X11-unix/X0 /tmp/.X11-unix/X0: 3078(root) Configuring the System at the Command Line 693 36_599496 ch28.qxd 8/30/05 7:24 PM Page 693 [...]... month abbreviations (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec) 5 Day of week 0–7 (0 and 7 both mean Sunday, 1 is Monday) Three letter day abbreviations (Sun, Mon, Tue, Wed, Thu, Fri, Sat) Configuring the System at the Command Line Entries may be single values, a comma-delimited set of values to specify multiple days, a range of values separated by a hyphen (- ), or any combination of... for that field For example, an asterisk in the hour field means a job would execute every hour of the day For example, to run incrback.sh at 4:55 p.m on the 1st and 15th of January, March, June, and September, the crontab entry would look like one of the following: 55 16 1,1 5 1,3 , 6,9 * incrback.sh 55 16 1,1 5 Jan,Mar,Jun,Sep * incrback.sh In this case, the * in the day of the week field is ignored because... file system should be checked, or the file system itself (the default is all mounted file systems) -a includes empty file systems in the display, which would ordinarily be omitted -h uses more familiar display units, such as GB, MB, or KB, rather than default, blocks -k causes df to use block sizes of 1024 bytes, and -m block sizes of 1,0 4 8,5 76 bytes -l limits df’s report to local file systems, ignoring,... $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $) 55 16 1,1 5 1,4 , 6,9 * incrback.sh To remove all of your cron jobs, type crontab -r Once you become comfortable with the crontab format, you might find it most convenient to use crontab’s interactive mode To do so, type crontab -e The interactive mode uses the vi editor, so use vi keystrokes to enter, edit, save your changes, and, of course, to exit... Single-Use Commands The hwclock, date, and rdate commands are single-use commands for setting the system date and time That is, hwclock, date, and rdate have no inherent ability to keep a system s clock synced Rather, you run one of them, the time is set, and you are done Unless executed from cron or another periodic command scheduling service, none of these commands work to keep system time accurate on an... (ntpdate, ntpdc, ntptime, and so forth) that, working together, keep your system s clock set NTP is also quite simple to use on Fedora Core and RHEL systems because Red Hat configured it to sync against their NTP servers, clock.redhat.com All you have to do is start it (if it is not already started): # service ntpd start To make sure NTP starts at each boot, use chkconfig: # chkconfig levels 345 ntpd... [name] name, which can contain multiple white space delimited values, is the name of a file whose file system should be checked, or the file system itself (the default is all mounted file systems) -a displays counts for all files, not just directories -b prints all sizes in bytes -c displays a grand total for names -h uses more familiar display units, such as GB, MB, or KB, rather than default, blocks... seconds, or after t seconds if t is specified One of the most common uses of lsof is to find out what file (or files) are preventing you from unmounting a file system As you might have experienced, you cannot unmount a file system when a file that resides on it is still open If you attempt to do this, umount complains that the file system is busy For example, suppose that you want to unmount /dev/fd 0, which... connectivity, so it must be executed after network has started, perhaps during one of the scripts executed when starting run level 3 Using the Network Time Protocol The Network Time Protocol, or NTP, is a standardized way to keep system time synchronized across a network NTP consists of a daemon, ntpd, a configuration file, /etc/ntp.conf, and a set of supporting utilities (ntpdate, ntpdc, ntptime, and so... 709 710 Chapter 29 THE SHADOW PASSWORD SYSTEM Red Hat Linux, like most, if not all, Linux and UNIX systems, uses shadow passwords because they offer enhanced protection for your system s authentication files During the installation of Red Hat, shadow password protection for your system is enabled by default, as are MD5 passwords, which are an alternative and far more secure method of encrypting passwords . that, working together, keep your system s clock set. NTP is also quite simple to use on Fedora Core and RHEL systems because Red Hat configured it to sync against their NTP servers, clock.redhat.com. All. 1024 bytes, and -m block sizes of 1,0 4 8,5 76 bytes. -l limits df’s report to local file systems, ignoring, for example, NFS mounted file systems. -x lim- its df’s report to the current file system. for set- ting the system date and time. That is, hwclock, date, and rdate have no inherent ability to keep a system s clock synced. Rather, you run one of them, the time is set, and you are done.

Ngày đăng: 07/07/2014, 09:20

TỪ KHÓA LIÊN QUAN