1 / 59

CIS 191 - Lesson 10

CIS 191 - Lesson 10. Lesson 10 Skills Needed. Create and configure filesystems Mount a filesystem Automatically mount filesystems on reboots Check and repair a filesystem Show disk usage information Set quotas on a file system. CIS 191 - Lesson 9. Making a file system.

edena
Download Presentation

CIS 191 - Lesson 10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 191 - Lesson 10 Lesson 10 Skills Needed • Create and configure filesystems • Mount a filesystem • Automatically mount filesystems on reboots • Check and repair a filesystem • Show disk usage information • Set quotas on a file system

  2. CIS 191 - Lesson 9 Making a file system mkfs –t ext2 /dev/sda3 Master Boot Record (MBR) Partition Boot Sector ext2 file system Data Superblock Partition Boot Sector Inode Table Data Partition Boot Sector Data Partition Boot Sector Unused Boot Sector Data Blocks Data Unused Boot Sector Data

  3. CIS 191 - Lesson 9 Making File Systems Superblock Inode Table Analogy: making a file system on an empty partition is like painting the stripes on a parking lot. It organizes the space and makes it efficient. Data Blocks ext2 file system

  4. CIS 191 - Lesson 9 ext2 Filesystems

  5. CIS 191 - Lesson 9 The ext2 filesystem Background • Original UNIX File System (UFS) • Bootstrap block • Superblock • Cylinder groups • inodes (indexes) • data blocks • cylinder group header • backup copies of superblock • The Fast File System (FFS) from BSD • Intended to overcome file fragment problems • Localize data associated data in cylinders to avoid head thrashing • Put "last" bits of several files in single block • ext2 takes some features of FFS and UFS • ext3 adds journaling

  6. CIS 191 - Lesson 9 The ext2 filesystem Fragmentation • FFS, ext2 Filesystems limit this with cylinder, and block groups • ext2 File Systems tend to have little file fragmentation • Largest contiguous ext2 file limited by block size and block/inode ratio • Defragmenting an ext2 File System • Usually not enough fragmentation to use defragmentation in ext2 • May be bugs in defragmenter

  7. CIS 191 - Lesson 9 ext2 file system • Superblock has: • File system type, label, inode count, block count, etc. about entire file system. • Redundant copies are maintained. • Use: dumpe2fs –h /dev/sda2 • to see / superblock info • inodes have: • file type, permissions, link count, owner, group, size, major and minor numbers, creation date, modification date, access date, pointers to data blocks. • Does not contain filenames which are kept in directories. • Use stat command to see inode information • Data blocks have actual file and directory data. ext2 file system Superblock Inode Table Data Blocks

  8. CIS 191 - Lesson 9 bigfile 102574 bin 102575 letter 102609 102609 inode number ext2 file system Superblock - Type rw-r—r-- Permissions Hello Mother! Hello Father! Here I am at Camp Granada. Things are very entertaining, and they say we'll have some fun when it stops raining. All the counselors hate the waiters, and the lake has alligators. You remember Leonard Skinner? He got ptomaine poisoning last night after dinner. Now I don't want this to scare you, but my bunk mate has malaria. You remember Jeffrey Hardy? Their about to organize a searching party. Take me home, oh Mother, Father, take me home! I hate Granada. Don't leave me out in the forest where I might get eaten by a bear! Take me home, I promise that I won't make noise, or mess the house with other boys, oh please don't make me stay -- I've been here one whole day. Dearest Father, darling Mother, how's my precious little brother? I will come home if you miss me. I will even let Aunt Bertha hug and kiss me! Wait a minute! It's stopped hailing! Guys are swimming! Guys are sailing! Playing baseball, gee that's better! Mother, Father, kindly disregard this letter. Alan Sherman Inode Table 1 Number of links simmsben User cis90 Group Data Blocks 1044 Size 2001-07-20 Modification time 2008-08-08 Access Time 2008-06-20 Change time Pointer(s) to data blocks Pointer(s) to data blocks [simmsben@opus ~]$ls -il letter 102609 -rw-r--r-- 1 simmsben cis90 1044 Jul 20 2001 letter

  9. CIS 191 - Lesson 9 The ext2 filesystem Data Blocks

  10. CIS 191 - Lesson 9 Making a file system mkfs –t ext2 /dev/sda3 Master Boot Record (MBR) Partition Boot Sector ext2 file system Data Superblock Partition Boot Sector Inode Table Data Partition Boot Sector Data Partition Boot Sector Unused Boot Sector Data Blocks Data Unused Boot Sector Data

  11. CIS 191 - Lesson 9 mkfs command • mkfs –t typedevice • -t ext2 • –t ext3 (has journaling) • -t vfat(compatible with Windows) • -t jfs(IBM’s journaled file system) • -t reiserfs • For ext2 or ext3 use: • -N option to specify number of inodes • -m option to specify % blocks reserved for superuser (default 5%) • -L option to set the volume label for the file system • Example:mkfs –t ext3 /dev/sda6 • (puts ext3 file system on 6th partition of 1st SCSI drive) • Example: mkfs –t ext2 –m 0 –N 1000 –L myfiles /dev/sda6 • (puts ext2 file system with 1000 inodes, no space reserved for superuser, volume label “myfiles” on 6th partition of 1st SCSI drive, ) • Note: mkfs is actually a front end for various filesystem builders. • [root@rh9 root]# ls /sbin/mkfs* • /sbin/mkfs /sbin/mkfs.ext2 /sbin/mkfs.jfs /sbin/mkfs.reiserfs • /sbin/mkfs.cramfs /sbin/mkfs.ext3 /sbin/mkfs.msdos /sbin/mkfs.vfat Use man mke2fs to see all options

  12. CIS 191 - Lesson 9 FYI Making a file system in a file Yes, believe it or not, this can be done too Superblock Superblock Inode Table Inode Table Data Blocks Data Blocks

  13. CIS 191 - Lesson 9 FYI Making a file system in a file Yes, believe it or not, this can be done too [root@benji bin]# dd if=/dev/zero bs=1024 count=50000 of=myfs 50000+0 records in 50000+0 records out 51200000 bytes (51 MB) copied, 1.76522 seconds, 29.0 MB/s [root@benji bin]# ls -l myfs -rw-r--r-- 1 root root 51200000 Nov 3 05:07 myfs [root@benji bin]# mkfs -t ext2 myfs mke2fs 1.39 (29-May-2006) myfs is not a block special device. Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 12544 inodes, 50000 blocks 2500 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=51380224 7 block groups 8192 blocks per group, 8192 fragments per group 1792 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961 Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@benji bin]# mount -o loop myfs /mnt [root@benji bin]# cd /home [root@benji home]# cp -apr . /mnt [root@benji home]# cd /mnt [root@benjimnt]# ls -l total 32 -rw------- 1 root root 9216 Nov 3 04:14 aquota.user drwx------ 3 cis191 cis191 1024 Oct 25 15:31 cis191 drwx------ 2 frodo hobbits 1024 Nov 2 18:07 frodo drwx------ 2 gimli dwarves 1024 Nov 2 18:07 gimli drwx------ 2 glorfindel elves 1024 Nov 2 18:07 legolas drwx------ 2 root root 12288 Nov 3 02:58 lost+found drwx------ 2 gollum hobbits 1024 Nov 2 18:07 smeagol [root@benjimnt]#

  14. CIS 191 - Lesson 9 FYI Making a file system in a file Yes, believe it or not, this can be done too [root@benjimnt]# fsck -f /dev/loop0 fsck 1.39 (29-May-2006) e2fsck 1.39 (29-May-2006) /dev/loop0 is mounted. WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? yes Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/loop0: 38/12544 files (2.6% non-contiguous), 2420/50000 blocks [root@benjimnt]#

  15. CIS 191 - Lesson 9 Manage Filesystems

  16. CIS 191 - Lesson 9 File Systems ext2 filesystem utilities [root@benji bin]# ls /sbin/*fs* /sbin/debugfs /sbin/fsck.ext2 /sbin/mkfs.cramfs /sbin/resize2fs /sbin/dosfsck /sbin/fsck.ext3 /sbin/mkfs.ext2 /sbin/tune2fs /sbin/dosfslabel /sbin/fsck.msdos /sbin/mkfs.ext3 /sbin/umount.cifs /sbin/dumpe2fs /sbin/fsck.vfat /sbin/mkfs.msdos /sbin/umount.nfs /sbin/e2fsck /sbin/fstab-decode /sbin/mkfs.vfat /sbin/umount.nfs4 /sbin/findfs /sbin/mkdosfs /sbin/mount.cifs /sbin/fsck /sbin/mke2fs /sbin/mount.nfs /sbin/fsck.cramfs /sbin/mkfs /sbin/mount.nfs4 [root@benji bin]#

  17. CIS 191 - Lesson 9 File Systems File System Creation • mkfs.ext2 (mke2fs) • Creates Linux ext2 file systems • mklost+found • Creates lost and found directory on mounted ext2 file systems • resize2fs • Resize an ext2 file system • e2label • Used to change or view label of ext2 file system

  18. CIS 191 - Lesson 9 File Systems File System Manipulation • debugfs/dumpe2fs • File system debugger • Most dangerous and powerful of e2fsprogs • tune2fs • Adjusts file system parameters • uuidgen • Creates universally unique identities

  19. CIS 191 - Lesson 9 ext2 file system Using dumpe2fs –h to show superblock information [root@rh9 root]# dumpe2fs -h /dev/sda2 dumpe2fs 1.32 (09-Nov-2002) Filesystem volume name: / Last mounted on: <not available> Filesystem UUID: b552eed8-4c9d-4f8f-9edf-dd76037f82bd Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journalfiletypeneeds_recoverysparse_super Default mount options: (none) Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 320640 Block count: 640591 Reserved block count: 32029 Free blocks: 228375 Free inodes: 220820 First block: 0 Block size: 4096 Fragment size: 4096 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 16032 Inode blocks per group: 501 Filesystem created: Fri Jul 18 09:37:33 2008 Last mount time: Fri Jul 18 17:06:16 2008 Last write time: Fri Jul 18 17:06:16 2008 Mount count: 3 Maximum mount count: -1 Last checked: Fri Jul 18 09:37:33 2008 Check interval: 0 (<none>) Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 128 Journal UUID: <none> Journal inode: 8 Journal device: 0x0000 First orphan inode: 229443 [root@rh9 root]# If you leave off the –h option you will also see the data block status as well. Superblock Inode Table Data Blocks

  20. CIS 191 - Lesson 9 ext2 file system Using stat command to show inode details [root@rh9 root]# ls anaconda-ks.cfg install.log install.log.syslog test testdir [root@rh9 root]# ls -l total 36 -rw-r--r-- 1 root root 1220 Jul 18 16:57 anaconda-ks.cfg -rw-r--r-- 1 root root 19626 Jul 18 16:51 install.log -rw-r--r-- 1 root root 2895 Jul 18 16:51 install.log.syslog -rw-r--r-- 1 root root 18 Jul 18 17:24 test drwxr-xr-x 2 root root 4096 Jul 20 18:41 testdir [root@rh9 root]# stat test testdir File: `test' Size: 18 Blocks: 8 IO Block: 4096 Regular File Device: 802h/2050d Inode: 37058 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-07-20 18:40:47.000000000 -0700 Modify: 2008-07-18 17:24:47.000000000 -0700 Change: 2008-07-18 17:24:47.000000000 -0700 File: `testdir' Size: 4096 Blocks: 8 IO Block: 4096 Directory Device: 802h/2050d Inode: 20964 Links: 2 Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-07-20 18:41:08.000000000 -0700 Modify: 2008-07-20 18:41:08.000000000 -0700 Change: 2008-07-20 18:41:08.000000000 -0700 Superblock Inode Table Data Blocks Note: The name of the file is not kept in the Inode. It is kept as data in a directory file.

  21. CIS 191 - Lesson 9 Moving Files to New Partitions (with cp command) [root@benji bin]# mkfs -t ext3 -N 800 -L /home /dev/sda7 mke2fs 1.39 (29-May-2006) Filesystem label=/home OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 800 inodes, 200780 blocks 10039 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 25 block groups 8192 blocks per group, 8192 fragments per group 32 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@benji bin]# mount /dev/sda7 /mnt [root@benji bin]# ls -ai /mnt 2 . 2 .. 11 lost+found [root@benji bin]# ls -idl /mnt 2 drwxr-xr-x 3 root root 1024 Nov 3 02:58 /mnt [root@benji bin]# ls -l /mnt total 12 drwx------ 2 root root 12288 Nov 3 02:58 lost+found [root@benji bin]# cd /home [root@benji home]# cp -apr . /mnt [root@benji home]# [root@benji home]# ls -l /mnt total 22 drwx------ 3 cis191 cis191 1024 Oct 25 15:31 cis191 drwx------ 2 frodo hobbits 1024 Nov 2 18:07 frodo drwx------ 2 gimli dwarves 1024 Nov 2 18:07 gimli drwx------ 2 glorfindel elves 1024 Nov 2 18:07 legolas drwx------ 2 root root 12288 Nov 3 02:58 lost+found drwx------ 2 gollum hobbits 1024 Nov 2 18:07 smeagol [root@benji home]# When copying a directory like /home to another partition use options that don't follow symbolic links, preserve timestamps and are recursive

  22. CIS 191 - Lesson 9 Moving Files to New Partitions (with tar command) [root@benji bin]# mkfs -t ext3 -N 800 -L /home /dev/sda7 mke2fs 1.39 (29-May-2006) Filesystem label=/home OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 800 inodes, 200780 blocks 10039 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 25 block groups 8192 blocks per group, 8192 fragments per group 32 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@benji bin]# mount /dev/sda7 /mnt [root@benji bin]# ls -ai /mnt 2 . 2 .. 11 lost+found [root@benji bin]# ls -idl /mnt 2 drwxr-xr-x 3 root root 1024 Nov 3 02:58 /mnt [root@benji bin]# ls -l /mnt total 12 drwx------ 2 root root 12288 Nov 3 02:58 lost+found [root@benjimnt]# cd /mnt [root@benjimnt]# (cd /home; tar cvf - . ) | tar xvf - ./ ./legolas/ ./legolas/.bashrc ./legolas/.bash_logout ./legolas/.bash_profile ./cis191/ ./cis191/.ssh/ ./cis191/.ssh/known_hosts ./cis191/.bashrc ./cis191/.viminfo ./cis191/.bash_logout ./cis191/.bash_profile ./ ./legolas/ ./cis191/.lesshst ./cis191/.bash_history ./gimli/ ./gimli/.bashrc ./gimli/.bash_logout ./gimli/.bash_profile ./gimli/.hushlogin ./smeagol/ ./smeagol/.bashrc ./smeagol/.bash_logout ./smeagol/.bash_profile ./frodo/ ./frodo/.bashrc ./frodo/.bash_logout ./frodo/.bash_profile ./legolas/.bashrc ./legolas/.bash_logout ./legolas/.bash_profile ./cis191/ ./cis191/.ssh/ ./cis191/.ssh/known_hosts ./cis191/.bashrc ./cis191/.viminfo ./cis191/.bash_logout ./cis191/.bash_profile ./cis191/.lesshst ./cis191/.bash_history ./gimli/ ./gimli/.bashrc ./gimli/.bash_logout ./gimli/.bash_profile ./gimli/.hushlogin ./smeagol/ ./smeagol/.bashrc ./smeagol/.bash_logout ./smeagol/.bash_profile ./frodo/ ./frodo/.bashrc ./frodo/.bash_logout ./frodo/.bash_profile [root@benjimnt]# ls -l total 22 drwx------ 3 cis191 cis191 1024 Oct 25 15:31 cis191 drwx------ 2 frodo hobbits 1024 Nov 2 18:07 frodo drwx------ 2 gimli dwarves 1024 Nov 2 18:07 gimli drwx------ 2 glorfindel elves 1024 Nov 2 18:07 legolas drwx------ 2 root root 12288 Nov 3 02:58 lost+found drwx------ 2 gollum hobbits 1024 Nov 2 18:07 smeagol [root@benjimnt]# mkfs output shrunk You will do this in Lab 7 tar output shrunk This is another way to do the same thing using tar command, () to run as a sub-shell so pwd is not changed and using – as a way to pipe stdout to another tar command for extraction

  23. CIS 191 - Lesson 9 Extended Properties chattr and lsattr • chattr [-RV] [ + | - | = ] attribute • -R = recursive • -V = verbose • attributes: • A = Don't update access time • a = append mode only • c = file gets compressed • d = not backed up by dump • i = immutable • u = contents saved when deleted • lsattr • Lists the ext2 file system's extended permissions

  24. CIS 191 - Lesson 9 Extended Properties chattr and lsattr [root@benji ~]# chattr +A file [root@benji ~]# lsattr file -------A----- file [root@benji ~]# head -1 file QUOTA(1) QUOTA(1) [root@benji ~]# stat file File: `file' Size: 3697 Blocks: 16 IO Block: 4096 regular file Device: 801h/2049d Inode: 520510 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-11-02 18:44:59.000000000 -0800 Modify: 2008-11-02 18:44:59.000000000 -0800 Change: 2008-11-02 18:44:59.000000000 -0800 [root@benji ~]# head -1 file QUOTA(1) QUOTA(1) [root@benji ~]# stat file File: `file' Size: 3697 Blocks: 16 IO Block: 4096 regular file Device: 801h/2049d Inode: 520510 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-11-02 18:44:59.000000000 -0800 Modify: 2008-11-02 18:44:59.000000000 -0800 Change: 2008-11-02 18:44:59.000000000 -0800 [root@benji ~]# With A set, access time is not changed when file is accessed

  25. CIS 191 - Lesson 9 Extended Properties chattr and lsattr [root@benji ~]# chattr -A file [root@benji ~]# lsattr file ------------- file [root@benji ~]# head -1 file QUOTA(1) QUOTA(1) [root@benji ~]# stat file File: `file' Size: 3697 Blocks: 16 IO Block: 4096 regular file Device: 801h/2049d Inode: 520510 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-11-02 18:46:57.000000000 -0800 Modify: 2008-11-02 18:44:59.000000000 -0800 Change: 2008-11-02 18:46:41.000000000 -0800 [root@benji ~]# head -1 file QUOTA(1) QUOTA(1) [root@benji ~]# stat file File: `file' Size: 3697 Blocks: 16 IO Block: 4096 regular file Device: 801h/2049d Inode: 520510 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2008-11-02 18:47:08.000000000 -0800 Modify: 2008-11-02 18:44:59.000000000 -0800 Change: 2008-11-02 18:46:41.000000000 -0800 [root@benji ~]# With A removed, access time is updated normally

  26. CIS 191 - Lesson 9 Extended Properties chattr and lsattr [root@benji ~]# chattr -V =i file chattr 1.39 (29-May-2006) Flags of file set as ----i-------- [root@benji ~]# lsattr file ----i-------- file [root@benji ~]# ls -l file -rw-r--r-- 1 root root 3697 Nov 2 18:44 file [root@benji ~]# chgrp hobbits file chgrp: changing group of `file': Operation not permitted [root@benji ~]# chmod g-r file chmod: changing permissions of `file': Operation not permitted [root@benji ~]# chattr -V -i file chattr 1.39 (29-May-2006) Flags of file set as ------------- [root@benji ~]# lsattr file ------------- file [root@benji ~]# chgrp hobbits file [root@benji ~]# chmod g-r file [root@benji ~]# ls -l file -rw----r-- 1 root hobbits 3697 Nov 2 18:44 file With i (immutable) set, the file cannot be modified

  27. CIS 191 - Lesson 9 Extended Properties chattr and lsattr [root@benji ~]# lsattr file ------------- file You have new mail in /var/spool/mail/root [root@benji ~]# chattr +a file [root@benji ~]# lsattr file -----a------- file [root@benji ~]# echo "text" > file -bash: file: Operation not permitted [root@benji ~]# echo "text" >> file [root@benji ~]# [root@benji ~]# ls -l file -rw----r-- 1 root hobbits 3697 Nov 2 18:44 file [root@benji ~]# chattr -a file [root@benji ~]# echo "text" > file [root@benji ~]# > file [root@benji ~]# With a (append only) set, the file can only be appended to

  28. CIS 191 - Lesson 9 Check and Repair

  29. CIS 191 - Lesson 9 Checking and Repairing What can cause corruption • Causes • Sudden loss of power in power failure • User switching off power improperly • Crash due to kernel or software • Program working on many files crashes • Shows up as: • Unreferenced inodes • Inexplicably large link counts • Unused data blocks not listed in block maps • Bad superblock summary information • Many files using one data block • Data blocks marked as free but being used (and vice-versa)

  30. CIS 191 - Lesson 9 Checking and Repairing Check and repair tools • fsck • Front end for various file checking and repairing tools. • Used to check or repair file systems • Defaults to checking filesystems in /etc/fstab using the 6th field for sequencing the checks • Runs during startup (see /etc/rc.d/rc.sysinit) • Runs much faster when checking ext3 (journaled) file systems • badblocks • Searches block devices for bad blocks

  31. CIS 191 - Lesson 9 Checking and Repairing fsck - File System Consistency Check At startup Linux will check any filesystems that were dirty (not un-mounted cleanly) As a precaution, filesystems are checked every random number of mounts. This number is shown when you created the filesystem: This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@benji ~]# This number can be modified using the tune2fs command with the –c option. Example from Lab 7 follows: tune2fs –c 20 /dev/sda7

  32. CIS 191 - Lesson 9 Checking and Repairing [root@benji ~]# fsck fsck 1.39 (29-May-2006) e2fsck 1.39 (29-May-2006) /dev/sda1 is mounted. WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? no check aborted. e2fsck 1.39 (29-May-2006) /dev/sda5 is mounted. WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? no check aborted. e2fsck 1.39 (29-May-2006) /dev/sda3 is mounted. WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? no check aborted. [root@benji ~]# FYI: If you run fsck without any options or arguments it will cycle through /etc/fstab Follow the advice here and don’t check an active filesystem

  33. CIS 191 - Lesson 9 Checking and Repairing Forcing a check on a clean filesystem Clean, so not checked -f option forces the check to happen You may need to shut down services and change to run level 1 so you can un-mount the filesystem to check it.

  34. CIS 191 - Lesson 9 Checking and Reparing lost+found directory [root@rh9 root]# mkfs -t ext2 /dev/sda6 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 26104 inodes, 104391 blocks 5219 blocks (5.00%) reserved for the super user First data block=1 13 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@rh9 root]# mount /dev/sda6 /mnt [root@rh9 root]# ls /mnt lost+found [root@rh9 root]# ls -l /mnt total 12 drwx------ 2 root root 12288 Jul 21 08:22 lost+found [root@rh9 root]# Note: The lost+found directory is created when you make a ext2 or ext3 file system. This is where the fsck utility will place any recovered data it finds when checking a file system. Don’t delete it!

  35. CIS 191 - Lesson 9 Mounting Filesystems

  36. CIS 191 - Lesson 9 Mounting File Systems • Mounting and Un-mounting file systems • mount [device-file] [directory] • umount [device-file | directory] • Mount information • /etc/fstab (what to mount at boot time) • /etc/mtab (current mount status)

  37. CIS 191 - Lesson 9 Showing current mount status On the rh9 VM mount command with no arguments shows current mount status in /etc/mtab / [root@rh9 root]# mount /dev/sda2 on / type ext3 (rw) none on /proc type proc (rw) /dev/sda1 on /boot type ext2 (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda5 on /home type ext3 (rw) none on /dev/shm type tmpfs (rw) [root@rh9 root]# cat /etc/mtab /dev/sda2 / ext3 rw 0 0 none /proc procrw 0 0 /dev/sda1 /boot ext2 rw 0 0 none /dev/pts devptsrw,gid=5,mode=620 0 0 /dev/sda5 /home ext3 rw 0 0 none /dev/shmtmpfsrw 0 0 [root@rh9 root]# [root@rh9 root]# ls -F /home /boot /mnt /boot: boot.bkernel.h module-info-2.4.20-6 vmlinuz@ chain.blost+found/ os2_d.b vmlinuz-2.4.20-6 config-2.4.20-6 message System.map@ grub/message.ja System.map-2.4.20-6 initrd-2.4.20-6.img module-info@ vmlinux-2.4.20-6 /home: lost+found/ rsimms/ /mnt: cdrom/ floppy/ hgfs/ [root@rh9 root]# /bin /boot /grub /dev/sda1 /lost+found /dev/sda2 /etc /dev/sda5 /dev /dev/sda6 /home /rsimms /lost+found /mnt /cdrom /floppy /hgfs

  38. CIS 191 - Lesson 9 Making a file system and mounting it On the rh9 VM / [root@rh9 root]# mkfs -t ext3 /dev/sda6 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 26104 inodes, 104391 blocks 5219 blocks (5.00%) reserved for the super user First data block=1 13 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@rh9 root]# mount /dev/sda6 /mnt [root@rh9 root]# cd /mnt [root@rh9 mnt]# mkdir dir1 dir2 [root@rh9 mnt]# cd [root@rh9 root]# ls /mnt dir1 dir2 lost+found [root@rh9 root]# umount /mnt [root@rh9 root]# ls /mnt cdrom floppy hgfs [root@rh9 root]# /bin /boot /grub /dev/sda1 /lost+found /dev/sda2 /etc /dev/sda5 /dev /dev/sda6 /home /rsimms mount will overlay the new filesystem on a directory in the current file hierarchy. The old directory is no longer accessible until the new one is un-mounted /lost+found /mnt /dir1 /fdir2 /lost+found

  39. CIS 191 - Lesson 9 Mounting File Systems Like pinning the tail on the donkey mount /dev/sda6 /mnt / /bin /boot /etc /dev /home /lib /mnt /lost+found /cdrom /rsimms /floppy /lost+found /dev/sda5 /hgfs /grub /dev/sda1 /dir1 /fdir2 /lost+found /dev/sda6

  40. CIS 191 - Lesson 9 Mounting File Systems Like pinning the tail on the donkey mount /dev/sda6 /mnt / /bin /boot /etc /dev /home /lib /mnt /lost+found /dir1 /dir2 /rsimms /lost+found /lost+found /dev/sda5 /grub /dev/sda6 /dev/sda1

  41. CIS 191 - Lesson 9 Mounting File Systems Caveats • Don’t mount a file system to a directory you are in. • You can’t un-mount a file system you have cd’ed into: • [root@rh9 mnt]# umount /mnt • umount: /mnt: device is busy • [root@rh9 mnt]# cd • [root@rh9 root]# umount /mnt • [root@rh9 root]#

  42. CIS 191 - Lesson 9 Mounting File Systems mount command and /etc/mtab mount point file system type mount options dump frequency fsck pass device [root@rh9 root]# mount /dev/sda2 on / type ext3 (rw) none on /proc type proc (rw) /dev/sda1 on /boot type ext2 (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda5 on /home type ext3 (rw) none on /dev/shm type tmpfs (rw) [root@rh9 root]# cat /etc/mtab /dev/sda2 / ext3 rw 0 0 none /proc proc rw 0 0 /dev/sda1 /boot ext2 rw 0 0 none /dev/pts devpts rw,gid=5,mode=620 0 0 /dev/sda5 /home ext3 rw 0 0 none /dev/shm tmpfs rw 0 0 [root@rh9 root]# Note: spaces added to output above for readability

  43. CIS 191 - Lesson 9 Mounting File Systems /etc/fstab /etc/fstab is used to automatically mount file systems at boot time [root@rh9 root]# cat /etc/fstab LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext2 defaults 1 2 none /dev/pts devpts gid=5,mode=620 0 0 LABEL=/home /home ext3 defaults 1 2 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0 /dev/sda3 swap swap defaults 0 0 /dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0 /dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0 mount point file system type mount options dump frequency fsck pass device Note: spacing modified in output above for readability

  44. CIS 191 - Lesson 9 Usage

  45. CIS 191 - Lesson 9 Disk space allocation df and du commands [root@benji bin]# du -sm /* 7 /bin 9 /boot 1 /dev 107 /etc 1 /home 112 /lib 1 /lost+found 1 /media 0 /misc 1 /mnt 0 /net 235 /opt 0 /proc 66 /root 25 /sbin 0 /selinux 1 /srv 0 /sys 1 /tmp 2370 /usr 63 /var [root@benji bin]# du (disk usage) shows how much space is being used and where -m (show in MB) -s (summarize) [root@benjimnt]# df -m Filesystem 1M-blocks Used Available Use% Mounted on /dev/sda1 2903 2399 355 88% / tmpfs 252 0 252 0% /dev/shm /dev/sda5 289 232 43 85% /opt /dev/sda3 487 72 390 16% /var /dev/sda7 196 6 181 3% /mnt df shows free space on a partition level -m (show in MB)

  46. CIS 191 - Lesson 9 Quotas

  47. CIS 191 - Lesson 9 Managing Quotas • Set quotas by user or group • Soft and hard limits • Grace period allows temporarily exceeding soft limit • Hard limits cannot be exceeded • Can limit by space usage or number of files • Set on individual partitions

  48. CIS 191 - Lesson 9 Managing Quotas • RPM package • [root@benji ~]# rpm -qa | grep quota • quota-3.13-1.2.3.2.el5 • [root@benji ~]# • Installed by default with CentOS 5 (Benji VM) • Quota binary files kept in partition root directory • aquota.user • aquota.group

  49. CIS 191 - Lesson 9 Managing Quotas Summary • Mount partition with usrquota and/or grpquota • mount -o usrquota /dev/sda7 /home • Create binary quota files (aquota.user, aquota.group) • quotacheck -cuv /dev/sda7 • Turn quotas on and off • quotaon -uv /dev/sda7 • quotaoff -uv /dev/sda7 • Set quotas • edquotagimli • Report on quotas • repquota –a • Replicate quotas for other users • edquota -p gimli `awk -F: '$3 > 499 {print $1}' /etc/passwd`

  50. CIS 191 - Lesson 9 Managing Quotas • The partition must be mounted with usrquota and/or grpquota. • From Lab 7: • mount –o usrquota /dev/sda7 /home • or /etc/fstab • [root@benji ~]# cat /etc/fstab • LABEL=/1 / ext3 defaults 1 1 • devpts /dev/pts devptsgid=5,mode=620 0 0 • tmpfs /dev/shmtmpfs defaults 0 0 • LABEL=/opt /opt ext3 defaults 1 2 • proc /proc proc defaults 0 0 • sysfs /sys sysfs defaults 0 0 • LABEL=/var /var ext3 defaults 1 2 • LABEL=SWAP-sda2 swap swap defaults 0 0 • LABEL=/home /home ext3 usrquota,defaults 1 2 • [root@benji ~]#

More Related