Posts

Showing posts from 2010

A-Z Index of the Apple OS X command line

The tcsh command shell of Darwin (the open source core of OSX) alias Create an alias alloc List used and free memory awk Find and Replace text within file(s) basename Convert a full pathname to just a folder path bash Bourne-Again SHell (Linux) bless Set volume bootability and startup disk options. break Exit from a loop cal Display a calendar case Conditionally perform a command cat Display the contents of a file cd Change Directory chflags Change a file or folder's flags. chgrp Change group ownership chmod Change access permissions chown Change file owner and group chroot Run a command with a different root directory cksum Print CRC checksum and byte counts clear Clear terminal screen cmp Compare two files comm Compare two sorted files line by line complete Edit a command completion [word/pattern/list] continue Resume the next iteration of a loop cp

A-Z Index of the Linux BASH command line

alias Create an alias apropos Search Help manual pages (man -k) awk Find and Replace text, database sort/validate/index break Exit from a loop builtin Run a shell builtin bzip2 Compress or decompress named file(s) cal Display a calendar case Conditionally perform a command cat Display the contents of a file cd Change Directory cfdisk Partition table manipulator for Linux chgrp Change group ownership chmod Change access permissions chown Change file owner and group chroot Run a command with a different root directory cksum Print CRC checksum and byte counts clear Clear terminal screen cmp Compare two files comm Compare two sorted files line by line command Run a command - ignoring shell functions continue Resume the next iteration of a loop cp Copy one or more files to another location cron Daemon to execute scheduled commands crontab Schedule a command to run at a later time c

Uninstalling RMP

Uninstalling a package is just as simple as installing one. Type the following command at a shell prompt: rpm -e foo Note Notice that we used the package namefoo, not the name of the original package filefoo-1.0-1.i386.rpm. To uninstall a package, replace foo with the actual package name of the original package. You can encounter a dependency error when uninstalling a package if another installed package depends on the one you are trying to remove. For example: error: Failed dependencies: foo is needed by (installed) bar-2.0.20-3.i386.rpm To make RPM ignore this error and uninstall the package anyway (which may break the package dependent on it) use the --nodeps option.

Unresolved Dependency

RPM packages may sometimes depend on other packages, which mean that they require other packages to be installed to run properly. If you try to install a package which has an unresolved dependency, output similar to the following is displayed: error: Failed dependencies: bar.so.2 is needed by foo- 1.0-1 Suggested resolutions: bar-2.0.20-3.i386.rpm If you are installing a package from the Red Hat Enterprise Linux CD- ROM set, it usually suggests the package(s) needed to resolve the dependency. Find the suggested package(s) on the Red Hat Enterprise Linux CD- ROMs or from Red Hat Network, and add it to the command: rpm -ivh foo-1.0-1.i386.rpm bar-2.0.20-3.i386.rpm If installation of both packages is successful, output similar to the following is displayed: Preparing... ########################################### [100%] 1:foo ########################################### [ 50%] 2:bar ########################################### [100%] If it does not suggest a package to resolve the dependenc

Conflicting Files

If you attempt to install a package that contains a file which has already been installed by another package, the following is displayed: Preparing... ########################################### [100%] file /usr/bin/foo from install of foo-1.0-1 conflicts with file from package bar-2.0.20 To make RPM ignore this error, use the --replacefiles option: rpm -ivh --replacefiles foo-1.0-1.i386.rpm

Package Already Installed

If a package of the same name and version is already installed, the following output is displayed: Preparing... ########################################### [100%] package foo-1.0-1 is already installed However, if you want to install the package anyway, you can use the -- replacepkgs option, which tells RPM to ignore the error: rpm -ivh --replacepkgs foo-1.0-1.i386.rpm This option is helpful if files installed from the RPM were deleted or if you want the original configuration files from the RPM to be installed.

Installing RPM

RPM packages typically have file names like foo-1.0-1.i386.rpm. The file name includes the package name (foo), version (1.0), release (1), and architecture (i386). To install a package, log in as root and type the following command at a shell prompt: rpm -ivh foo-1.0-1.i386.rpm Alternatively, the following command can also be used: rpm -Uvh foo-1.0-1.i386.rpm If the installation is successful, the following output is displayed: Preparing... ########################################### [100%] 1:foo ########################################### [100%] As you can see, RPM prints out the name of the package and then prints a succession of hash marks as a progress meter while the package is installed. The signature of a package is checked automatically when installing or upgrading a package. The signature confirms that the package was signed by an authorized party. For example, if the verification of the signature fails, an error message such as the following is displayed: error: V3 DSA signa

Finding RPM Packages

Before using any RPM packages, you must know where to find them. An Internet search returns many RPM repositories, but if you are looking for RPM packages built by Red Hat, they can be found at the following locations: The Red Hat Enterprise Linux CD-ROMs The Red Hat Errata Page available at http://www.redhat.com/apps/support/errata/ Red Hat Network

Using RPM

RPM has five basic modes of operation (not counting package building): installing, uninstalling, upgrading, querying, and verifying. This section contains an overview of each mode.

RPM Design Goals

The RPM Package Manager (RPM) is an open packaging system, which runs on Red Hat Enterprise Linux as well as other Linux and UNIX systems. Red Hat, Inc. encourages other vendors to use RPM for their own products. RPM is distributed under the terms of the GPL. The utility works only with packages built for processing by the rpm package. For the end user, RPM makes system updates easy. Installing, uninstalling, and upgrading RPM packages can be accomplished with short commands. RPM maintains a database of installed packages and their files, so you can invoke powerful queries and verifications on your system. If you prefer a graphical interface, you can use the Package Management Tool to perform many RPM commands. Important When installing a package, please ensure it is compatible with your operating system and architecture. This can usually be determined by checking the package name. During upgrades, RPM handles configuration files carefully, so that you never lose your customizations —

Useful Websites For Linux

Refer to the follow resources for more information. http://acl.bestbits.at/ — Website for ACLs

Compatibility with Older Systems

If an ACL has been set on any file on a given file system that files system has the ext_attr attribute. This attribute can be seen using the following command: tune2fs -l A file system that has acquired the ext_attr attribute can be mounted with older kernels, but those kernels do not enforce any ACLs which have been set. Versions of the e2fsck utility included in version 1.22 and higher of the e2fsprogs package (including the versions in Red Hat Enterprise Linux 2.1 and 4) can check a file system with the ext_attr attribute. Older versions refuse to check it.

Archiving File Systems With ACLs

Warning The tar and dump commands do not backup ACLs. The star utility is similar to the tar utility in that it can be used to generate archives of files. The star package is required to use this utility. The command line options for Star are as follows

Retrieving ACLs

To determine the existing ACLs for a file or directory, use the getfacl command. In the example below, the getfacl is used to determine the existing ACLs for a file. getfacl home/john/picture.png The above command returns the following output: # file: home/john/picture.png # owner: john # group: john user::rw- group::r-- other::r-- If a directory with a default ACL is specified, the default ACL is also displayed as illustrated below. john@main /]$ getfacl home/sales/# file: home/sales/ # owner: john # group: john user::rw- user:barryg:r-- group::r-- mask::r-- other::r-- default:user::rwx default:user:john:rwx default:group::r-x default:mask::rwx default:other::r-x

Setting Default ACLs

To set a default ACL, add d: before the rule and specify a directory instead of a file name. For example, to set the default ACL for the /share/ directory to read and execute for users not in the user group (an access ACL for an individual file can override it): setfacl -m d:o:rx /share

Setting Access ACLs

There are two types of ACLs: access ACLs and default ACLs. An access ACL is the access control list for a specific file or directory. A default ACL can only be associated with a directory; if a file within the directory does not have an access ACL, it uses the rules of the default ACL for the directory. Default ACLs are optional. ACLs can be configured: Per user Per group Via the effective rights mask For users not in the user group for the file The setfacl utility sets ACLs for files and directories. Use the -m option to add or modify the ACL of a file or directory: setfacl -m Rules ( ) must be specified in the following formats. Multiple rules can be specified in the same command if they are separated by commas. u: : Sets the access ACL for a user. The user name or UID may be specified. The user may be any valid user on the system. g: : Sets the access ACL for a group. The group name or GID may be specified. The group may be any valid group on the system. m: Sets the effecti

NFS

By default, if the file system being exported by an NFS server supports ACLs and the NFS client can read ACLs, ACLs are utilized by the client system. To disable ACLs on NFS shares when configuring the server, include the no_acl option in the /etc/exports file. To disable ACLs on an NFS share when mounting it on a client, mount it with the no_acl option via the command line or the /etc/fstab file.

Mounting File Systems

Before using ACLs for a file or directory, the partition for the file or directory must be mounted with ACL support. If it is a local ext3 file system, it can be mounted with the following command: mount -t ext3 -o acl For example: mount -t ext3 -o acl /dev/VolGroup00/LogVol02 /work Alternatively, if the partition is listed in the /etc/fstab file, the entry for the partition can include the acl option: LABEL=/work /work ext3 acl 1 2 If an ext3 file system is accessed via Samba and ACLs have been enabled for it, the ACLs are recognized because Samba has been compiled with the --with-acl- support option. No special flags are required when accessing or mounting a Samba share.

Resizing a Partition

Warning Do not attempt to resize a partition on a device that is in use. Before resizing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device). Start parted, where /dev/sda is the device on which to resize the partition: parted /dev/sda View the current partition table to determine the minor number of the partition to resize as well as the start and end points for the partition: print To resize the partition, use the resize command followed by the minor number for the partition, the starting place in megabytes, and the end place in megabytes. For example: resize 3 1024 2048 Warning A partition cannot be made larger than the space available on the device After resizing the partition, use the print command to confirm that the partition has been resized correctly, is the correct partition type, and is the correct file system type. After rebooting the system into normal mode, use the command df to make sure the partition was

Removing a Partition

Warning Do not attempt to remove a partition on a device that is in use. Before removing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device). Start parted, where /dev/sda is the device on which to remove the partition: parted /dev/sda View the current partition table to determine the minor number of the partition to remove: print Remove the partition with the command rm. For example, to remove the partition with minor number 3: rm 3 The changes start taking place as soon as you press Enter, so review the command before committing to it. After removing the partition, use the print command to confirm that it is removed from the partition table. You should also view the output of cat /proc/partitions to make sure the kernel knows the partition is removed. The last step is to remove it from the /etc/fstab file. Find the line that declares the removed partition, and remove it from the file.

Standard Partitions using parted

The utility parted allows users to: View the existing partition table Change the size of existing partitions Add partitions from free space or additional hard drives By default, the parted package is included when installing Red Hat Enterprise Linux. To start parted, log in as root and type the command parted /dev/sda at a shell prompt (where /dev/sda is the device name for the drive you want to configure). A device containing a partition must not be in use if said partition is to be removed or resized. Similarly, when creating a new partition on a device, said device must not be in use. For a device to not be in use, none of the partitions on the device can be mounted, and any swap space on the device must not be enabled. As well, the partition table should not be modified while it is in use because the kernel may not properly recognize the changes. If the partition table does not match the actual state of the mounted partitions, information could be written to the wrong partit

Moving Swap Space

To move swap space from one location to another, follow the steps for removing swap space, and then follow the steps for adding swap space.

Removing a Swap File

To remove a swap file: 1. At a shell prompt as root, execute the following command to disable the swap file (where /swapfile is the swap file): # swapoff -v /swapfile 2. Remove its entry from the /etc/fstab file. 3. Remove the actual file: # rm /swapfile

Removing an LVM2 Logical Volume for Swap

The swap logical volume cannot be in use (no system locks or processes on the volume). The easiest way to achieve this is to boot your system in rescue mode. Refer to for instructions on booting into rescue mode. When prompted to mount the file system, select Skip. To remove a swap volume group (Assuming /dev/VolGroup00/LogVol02) is the swap volume you want to remove: 1. Disable swapping for the associated logical volume: # swapoff -v /dev/VolGroup00/LogVol02 2. Remove the LVM2 logical volume of size 512 MB: # lvm lvremove /dev/VolGroup00/LogVol02 3. Remove the following entry from the /etc/fstab file: /dev/VolGroup00/LogVol02 swap swap defaults 0 0 4. Test that the logical volume has been extended properly: # cat /proc/swaps # free

Reducing Swap on an LVM2 Logical Volume

To reduce an LVM2 swap logical volume (assuming dev/VolGroup00/LogVol01 is the volume you want to extend): 1. Disable swapping for the associated logical volume: # swapoff -v /dev/VolGroup00/LogVol01 2. Reduce the LVM2 logical volume by 512 MB: # lvm lvreduce /dev/VolGroup00/LogVol01 -L -512M 3. Format the new swap space: # mkswap /dev/VolGroup00/LogVol01 4. Enable the extended logical volume: # swapon –va 5. Test that the logical volume has been reduced properly: # cat /proc/swaps # free

Removing Swap Space

Sometimes it can be prudent to reduce swap space after installation. For example, say you downgraded the amount of RAM in your system from 1 GB to 512 MB, but there is 2 GB of swap space still assigned. It might be advantageous to reduce the amount of swap space to 1 GB, since the larger 2 GB could be wasting disk space.You have three options: remove an entire LVM2 logical volume used for swap, remove a swap file, or reduce swap space on an existing LVM2 logical volume.

Creating a Swap File

To add a swap file: Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536. At a shell prompt as root, type the following command with count being equal to the desired block size: dd if=/dev/zero of=/swapfile bs=1024 count=65536 Setup the swap file with the command: mkswap /swapfile To enable the swap file immediately but not automatically at boot time: swapon /swapfile To enable it at boot time, edit /etc/fstab to include the following entry: /swapfile swap swap defaults 0 0 The next time the system boots, it enables the new swap file. After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.

Creating an LVM2 Logical Volume for Swap

In our example we assume /dev/VolGroup00/LogVol02 is the swap volume you want to add. To add a swap volume group please 1. Create the LVM2 logical volume of size 256 MB: # lvm lvcreate VolGroup00 -n LogVol02 -L 256M 2. Format the new swap space: # mkswap /dev/VolGroup00/LogVol02 3. Add the following entry to the /etc/fstab file: /dev/VolGroup00/LogVol02 swap swap defaults 0 0 4. Enable the extended logical volume: # swapon –va 5. Test that the logical volume has been extended properly: # cat /proc/swaps # free

Extending Swap on an LVM2 Logical Volume

In our example we assume /dev/VolGroup00/LogVol01 is the volume you want to extend. To extend an LVM2 swap logical volume please 1. Disable the swapping for the associated logical volume: # swapoff -v /dev/VolGroup00/LogVol01 2. Resize the LVM2 logical volume by 256 MB: # lvm lvresize /dev/VolGroup00/LogVol01 -L +256M 3. Format the new swap space: # mkswap /dev/VolGroup00/LogVol01 4. Enable the extended logical volume: # swapon –va 5. Test that the logical volume has been extended properly: # cat /proc/swaps # free

Extending / Adding Swap Space

Sometimes it happens that you want to add more swap space even after installation. For example, you may upgrade the amount of RAM in your system from 128 MB to 256 MB, but there is only 256 MB of swap space. It might be advantageous to increase the amount of swap space to 512 MB if you perform memory-intense operations or run applications that require a large amount of memory. It is recommended that you extend an existing logical volume. To extend or add swap space, basically you have three options: create a new swap partition create a new swap file extend swap on an existing LVM2 logical volume

What is Swap Space?

It’s an area on disk that temporarily holds a process memory image. When physical memory demand is sufficiently low, process memory images are brought back into physical memory from the swap area on disk. Having sufficient swap space enables the system to keep some physical memory free at all times. This type of memory management is often referred to as virtual memory and allows the total number of processes to exceed physical memory. Virtual memory enables the execution of a process within physical memory only as needed. Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files. Space allocation criteria should be equal to 2x physical RAM for up to 2 GB of physical RAM, and then an additional 1x physical RAM for any amount above 2 GB, but never less than 32 MB. Simply if, Memory in Ram is 512MB then Swap Space will be 512*2 = 1024MB Or if M = Amount of RAM in GB, and S = Amount of swap in GB, then If M <> S = M *2

Useful Websites For Linux

http://www.gnu.org/software/grub/ The home page of the GNU GRUB project. This site contains information concerning the state of GRUB development and an FAQ. http://kbase.redhat.com/faq/FAQ_43_4053.shtm Details booting operating systems other than Linux. http://www.linuxgazette.com/issue64/kohli.html An introductory article discussing the configuration of GRUB on a system from scratch, including an overview of GRUB command line options.

Installed Documentation

/usr/share/doc/grub- / This directory contains good information about using and configuring GRUB, where corresponds to the version of the GRUB package installed. info grub The GRUB info page contains a tutorial, a user reference manual, a programmer reference manual, and a FAQ document about GRUB and its usage.

Additional Resources

This chapter is only intended as an introduction to GRUB. Consult the following resources to discover more about how GRUB works.

Changing Runlevels at Boot Time

Under Red Hat Enterprise Linux, it is possible to change the default runlevel at boot time. To change the runlevel of a single boot session, use the following instructions: When the GRUB menu bypass screen appears at boot time, press any key to enter the GRUB menu (within the first three seconds). Press the a key to append to the kernel command. Add at the end of the boot options line to boot to the desired runlevel.For example, the following entry would initiate a boot process into runlevel 3: grub append> ro root=/dev/VolGroup00/LogVol00 rhgb quiet 3

Configuration File Directives

The following are directives commonly used in the GRUB menu configuration file: chainloader Loads the specified file as a chain loader. Replace with the absolute path to the chain loader. If the file is located on the first sector of the specified partition, use the blocklist notation, +1. color Allows specific colors to be used in the menu, where two colors are configured as the foreground and background. Use simple color names such as red/black. For example: color red/black green/blue default= Replace with the default entry title number to be loaded if the menu interface times out. fallback= Replace with the entry title number to try if the first attempt fails. Hiddenmenu Prevents the GRUB menu interface from being displayed, loading the default entry when the timeout period expires. The user can see the standard GRUB menu by pressing the Esc key. initrd Enables users to specify an initial RAM disk to use when booting. Replace with the absolute path to the initial RA