– General Linux 1 – Maintain the integrity of filesystems (Linux Professional Institute Certification) a .˜. /V\ // \\ @._.@ by: geoffrey robertson geoffrey@zip.com.au $Id: gl1.104.2.slides.tex,v 1.3 2003/05/30 05:04:30 waratah Exp $ c 2002 Geoffrey Robertson. Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation—either version 2 of the License or (at your option) any later version. a Copyright 1 Devices, Linux Filesystems & FHS 1.104.1 Create partitions and filesystems 1.104.2 Maintain the integrity of filesystems 1.104.3 Control mounting and unmounting filesystems 1.104.4 Managing disk quota 1.104.5 Use file permissions to control access to files 1.104.6 Manage file ownership 1.104.7 Create and change hard and symbolic links 1.104.8 Find system files and place files in the correct location 2 Maintain the integrity of filesystems Objective Candidates should be able to verify the integrity of filesystems, monitor free space and inodes, and repair simple filesystem problems. This objective includes the commands required to maintain a standard filesystem, as well as the extra data associated with a journaling filesystem. Key files, terms, and utilities include: du df debugfs fsck e2fsck mke2fs dumpe2fs tune2fs 3 Summary of Commands Command du df fsck e2fsck mke2fs debugfs dumpe2fs tune2fs Function Display disk usage Display disk space free Check Filesystem Check an ext2 Filesystem Create an ext2 Filesystem Debug an ext2 Filesystem Dump Filesystem information Adjust parameters on ext2 Filesystem 4 du - Disk Usage • du shows disk usage • du can work with subdirectories or an entire disk • Usage is: du [options] [directory] 5 Options to du Option -a -b -c -h -k -m -s -x Function Show counts for all files & directories Display size in bytes Print total for all arguments after processing Print in human readable form Show size in Kilobytes Display size in Megabytes Display a summary for each argument Skip directories containing other filesystems 6 df - Disk Free • df shows disk space used & available • Default is to display all filesystems • Usage is: df [options] [directory] 7 Options to df Option -a -t fs type -h -k -m -i -l -x fs type Function Show counts for all filesystems Limit listing to fs type Print in human readable form Show size in Kilobytes Display size in Megabytes Display inode information Limit listing to local filesystems Exclude fs type from listing 8 fsck - Check and repair a Linux file system • fsck is used to check and optionally repair a one or more Linux file systems. • filesys can be a device name (e.g. /dev/hdc1, /dev/sdb2), a mount point (e.g. /, /usr, /home), or an ext2 label. • fsck will try to run filesystems on different physical drives in parallel to reduce total amount time to check all of the filesystems. • fsck makes 5 passes on the filesystem: – Pass 1: Check inodes, blocks & sizes – Pass 2: Check directory structure – Pass 3: Check directory connectivity – Pass 4: Check reference counts 9 – Pass 5: Check group summary information 10 fsck Options Option -p -n -y -f -r -v -A -C -N Function Automatically repair without prompting Don’t make changes to filesystem Assume yes to all questions Force check even if fs is clean Interactively prompt for changes Be verbose Check all filesystems in /etc/fstab Display a progress bar Don’t execute, show what would be done 11 fsck error codes When fsck completes, it will return a value ($?) as follows: Code 0 1 2 4 8 16 128 Meaning No errors Errors found & corrected System should be rebooted Filesystem error left uncorrected Operational error Usage or syntax error Shared library error 12 e2fsck - Check a Linux ext2 FS • e2fsck is used to check a Linux second extended file system (e2fs) • e2fsck also supports ext2 filesystems containing a journal, which are also sometimes known as ext3 filesystems. • e2fsck operates in a similar manner to fsck (see man page) 13 mke2fs - Create a Linux ext2 filesystem • mke2fs is used to create an ext2 filesystem • mke2fs takes a device special file as its argument • mkfs.ext2 is the same as mke2fs • To make an ext3 filesystem, you first make an ext2 filesystem and then add a journal to it using tune2fs or use the -j option to mke2fs • Usage is: mke2fs [options] device 14 mke2fs Options Option -V -b blocksize -c -i bytes per inode -j -L label -N inodes -n Use Be verbose Make blocks blocksize bytes Check for bad blocks on device Create an inode for each bytes per inode Create a journal (ext3) Set the volume label Create the fs with specified number of inodes Show what would be done (don’t actually create fs) 15 debugfs - Ext2 filesystem debugger • debugfs is a file system debugger • It can be used to examine and change the state of an ext2 file system. • debugfs is an interactive debugger. It understands a number of commands: cat filespec Dump the contents of the inode filespec to stdout. cd filespec Change the current working directory to filespec. chroot filespec Change the root directory to be the directory file spec. close Close the currently open file system. quit Exit debugfs. 16 dumpe2fs - Dump filesystem information • dumpe2fs prints the super block and blocks group information for the filesystem present on device • Usage is: dumpe2fs [options] device • Common options are: Option -b -h Use Display badblocks on device Display superblock information 17 tune2fs - Adjust filesystem parameters on ext2 fs • tune2fs adjusts tunable filesystem parameters on a Linux ext2 filesystem. • tune2fs can be used to add a journal to an ext2 filesystem. • Usage is: tune2fs [options] device 18 tune2fs - Common options Option -c max-mounts -g group -j -L label -r blocks Use Set no of mounts before fsck is forced Set the group who can use reserved blocks Add a journal to the filesystem Set the volume label Set the number of reserved blocks 19