CIS 191 - Lesson 10
Lesson 10Skills 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
Partition Boot Sector
Data
Master Boot Record (MBR)
Partition Boot Sector
Data
Partition Boot Sector
Data
Partition Boot Sector
Data
Unused Boot Sector
Data
Unused Boot Sector
Making a file system
Superblock
Inode Table
ext2 file system
Data Blocks
mkfs –t ext2 /dev/sda3
CIS 191 - Lesson 9
Making File Systems
Superblock
Inode Table
Data Blocks
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.
ext2 file system
CIS 191 - Lesson 9
ext2 Filesystems
CIS 191 - Lesson 9
The ext2 filesystemBackground
• 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
CIS 191 - Lesson 9
• 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
The ext2 filesystemFragmentation
CIS 191 - Lesson 9
Superblock
Inode Table
Data Blocks
ext2 file system
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.
CIS 191 - Lesson 9
Superblock
Inode Table
ext2 file system
Data Blocks
[simmsben@opus ~]$ls -il letter102609 -rw-r--r-- 1 simmsben cis90 1044 Jul 20 2001 letter
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 hasalligators. You remember Leonard Skinner? He gotptomaine poisoning last night after dinner.
Now I don't want this to scare you, but my bunk mate hasmalaria. You remember Jeffrey Hardy? Their about toorganize 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 eatenby 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 mestay -- I've been here one whole day.
Dearest Father, darling Mother, how's my precious littlebrother? I will come home if you miss me. I will evenlet 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
bigfile 102574bin 102575letter 102609
bigfile 102574bin 102575letter 102609
102609
-
1
simmsben
cis90
1044
2001-07-20
2008-08-08
2008-06-20
Pointer(s) to data blocks
inode number
Type
Number of links
User
Group
Size
Modification time
Access Time
Change time
Pointer(s) to data blocks
rw-r—r-- Permissions
CIS 191 - Lesson 9
The ext2 filesystemData Blocks
CIS 191 - Lesson 9
Partition Boot Sector
Data
Master Boot Record (MBR)
Partition Boot Sector
Data
Partition Boot Sector
Data
Partition Boot Sector
Data
Unused Boot Sector
Data
Unused Boot Sector
Making a file system
Superblock
Inode Table
ext2 file system
Data Blocks
mkfs –t ext2 /dev/sda3
CIS 191 - Lesson 9
mkfs –t type device -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
mkfs command
Use man mke2fs to see all options
CIS 191 - Lesson 9
FYIMaking a file system in a file
Superblock
Inode Table
Data Blocks
Superblock
Inode Table
Data Blocks
Yes, believe it or not, this can be done too
CIS 191 - Lesson 9
FYIMaking a file system in a file
Yes, believe it or not, this can be done too
CIS 191 - Lesson 9
FYIMaking a file system in a file
Yes, believe it or not, this can be done too
CIS 191 - Lesson 9
ManageFilesystems
CIS 191 - Lesson 9
File Systemsext2 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]#
CIS 191 - Lesson 9
File SystemsFile System Creation
mkfs.ext2 (mke2fs)• Creates Linux ext2 file systems
mklost+found• Creates lost and found directory on mounted ext2 file
systemsresize2fs
• Resize an ext2 file systeme2label
• Used to change or view label of ext2 file system
CIS 191 - Lesson 9
File SystemsFile System Manipulation
debugfs/dumpe2fs• File system debugger • Most dangerous and powerful of e2fsprogs
tune2fs• Adjusts file system parameters
uuidgen• Creates universally unique identities
CIS 191 - Lesson 9
ext2 file systemUsing dumpe2fs –h to show superblock information
If you leave off the –h option you will also see the data block status as well.
Superblock
Inode Table
Data Blocks
CIS 191 - Lesson 9
ext2 file systemUsing stat command to show inode details
Note: The name of the file is not kept in the Inode. It is kept as data in a directory file.
Superblock
Inode Table
Data Blocks
CIS 191 - Lesson 9
Moving Files to New Partitions(with cp command)
When copying a directory like /home to another partition use options that don't follow symbolic links, preserve timestamps and are recursive
CIS 191 - Lesson 9
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
tar output shrunk
mkfs output shrunk
Moving Files to New Partitions(with tar command)
You will do this in Lab 7
CIS 191 - Lesson 9
Extended Propertieschattr and lsattr
chattr [-RV] [ + | - | = ] attribute
-R = recursive-V = verboseattributes: 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
CIS 191 - Lesson 9
With A set, access time is not changed when file is accessed
Extended Propertieschattr and lsattr
CIS 191 - Lesson 9
With A removed, access time is updated normally
Extended Propertieschattr and lsattr
CIS 191 - Lesson 9
With i (immutable) set, the file cannot be modified
Extended Propertieschattr and lsattr
CIS 191 - Lesson 9
With a (append only) set, the file can only be appended to
Extended Propertieschattr and lsattr
CIS 191 - Lesson 9
Check andRepair
CIS 191 - Lesson 9
Checking and RepairingWhat 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)
CIS 191 - Lesson 9
Checking and RepairingCheck 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
CIS 191 - Lesson 9
Checking and Repairingfsck - 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 or180 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
CIS 191 - Lesson 9
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
Checking and Repairing[root@benji ~]# fsckfsck 1.39 (29-May-2006)e2fsck 1.39 (29-May-2006)/dev/sda1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may causeSEVERE 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 causeSEVERE 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 causeSEVERE filesystem damage.
Do you really want to continue (y/n)? no
check aborted.[root@benji ~]#
CIS 191 - Lesson 9
You may need to shut down services and change to run level 1 so you can un-mount the filesystem to check it.
Clean, so not checked
-f option forces the check to happen
Checking and RepairingForcing a check on a clean filesystem
CIS 191 - Lesson 9
Checking and Reparinglost+found directory
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!
CIS 191 - Lesson 9
Mounting Filesystems
CIS 191 - Lesson 9
Mounting and Un-mounting file systems • mount [device-file] [directory] • umount [device-file | directory]
Mount information1./etc/fstab (what to mount at boot time)2./etc/mtab (current mount status)
Mounting File Systems
CIS 191 - Lesson 9
/
/bin
/etc
/mnt
/cdrom
On the rh9 VM
/dev
/boot
/home
/rsimms
/grub
/lost+found
/lost+found
/dev/sda1
/dev/sda2
/dev/sda5
/dev/sda6
/floppy
/hgfs
mount command with no arguments shows current mount status in /etc/mtab
Showing current mount status
CIS 191 - Lesson 9
/
/bin
/etc
/mnt
/dir1
On the rh9 VM
/dev
/boot
/home
/rsimms
/grub
/lost+found
/lost+found
/fdir2
/lost+found
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
Making a file system and mounting it
/
/bin /etc /mnt
/cdrom
/dev/boot /home
/rsimms
/grub
/lost+found
/lost+found
/floppy
/hgfs
/lib
/dev/sda6
/dev/sda1
/dev/sda5
Mounting File SystemsLike pinning the tail on the donkey
mount /dev/sda6 /mnt
CIS 191 - Lesson 9
/
/bin /etc /mnt
/dir1
/dev/boot /home
/rsimms
/grub
/lost+found
/lost+found
/dir2
/lost+found
/lib
/dev/sda1
/dev/sda5
Mounting File SystemsLike pinning the tail on the donkey
/dev/sda6
mount /dev/sda6 /mnt
CIS 191 - Lesson 9
Mounting File SystemsCaveats
• 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 /mntumount: /mnt: device is busy[root@rh9 mnt]# cd[root@rh9 root]# umount /mnt[root@rh9 root]#
CIS 191 - Lesson 9
CIS 191 - Lesson 9
[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 0none /proc proc rw 0 0/dev/sda1 /boot ext2 rw 0 0none /dev/pts devpts rw,gid=5,mode=620 0 0/dev/sda5 /home ext3 rw 0 0none /dev/shm tmpfs rw 0 0[root@rh9 root]#
devicemount point
file system type
mount options
dump frequency
fsckpass
Note: spaces added to output above for readability
Mounting File Systemsmount command and /etc/mtab
CIS 191 - Lesson 9
[root@rh9 root]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1LABEL=/boot /boot ext2 defaults 1 2none /dev/pts devpts gid=5,mode=620 0 0LABEL=/home /home ext3 defaults 1 2none /proc proc defaults 0 0none /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
devicemount point
file system type
mount options
dump frequency
fsckpass
Note: spacing modified in output above for readability
Mounting File Systems/etc/fstab
/etc/fstab is used to automatically mount file systems at boot time
CIS 191 - Lesson 9
Usage
CIS 191 - Lesson 9
Disk space allocationdf and du commands
[root@benji bin]# du -sm /*7 /bin9 /boot1 /dev107 /etc1 /home112 /lib1 /lost+found1 /media0 /misc1 /mnt0 /net235 /opt0 /proc66 /root25 /sbin0 /selinux1 /srv0 /sys1 /tmp2370 /usr63 /var[root@benji bin]#
[root@benji mnt]# df -mFilesystem 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
du (disk usage) shows how much space is being used and where -m (show in MB) -s (summarize)
df shows free space on a partition level -m (show in MB)
CIS 191 - Lesson 9
Quotas
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
CIS 191 - Lesson 9
Managing Quotas
• RPM package[root@benji ~]# rpm -qa | grep quotaquota-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
CIS 191 - Lesson 9
Managing Quotas Summary
CIS 191 - Lesson 9
Managing Quotas
CIS 191 - Lesson 9
Managing Quotas
-c option doesn't read existing data files -u checks only user quotas–v is for verbose reporting
CIS 191 - Lesson 9
Managing Quotas[root@benji ~]# ls -l /hometotal 32-rw------- 1 root root 9216 Nov 3 04:14 aquota.userdrwx------ 3 cis191 cis191 1024 Oct 25 15:31 cis191drwx------ 2 frodo hobbits 1024 Nov 2 18:07 frododrwx------ 2 gimli dwarves 1024 Nov 2 18:07 gimlidrwx------ 2 glorfindel elves 1024 Nov 2 18:07 legolasdrwx------ 2 root root 12288 Nov 3 02:58 lost+founddrwx------ 2 gollum hobbits 1024 Nov 2 18:07 smeagol[root@benji ~]# mount/dev/sda1 on / type ext3 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw)/dev/sda5 on /opt type ext3 (rw)/dev/sda3 on /var type ext3 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)/dev/sda7 on /home type ext3 (rw,usrquota)/root/bin/myfs on /mnt type ext2 (rw,loop=/dev/loop0)[root@benji ~]# file /home/aq*/home/aquota.user: data[root@benji ~]# User quota configuration is kept in a
binary file called aquota.user
created when you first run quotacheck command
CIS 191 - Lesson 9
Managing Quotas
CIS 191 - Lesson 9
Managing Quotas
Set soft limit to 2 MB and hard limit to 2.5MB
vi user interface!
CIS 191 - Lesson 9
Managing Quotas
Set soft limit to 4.5 MB and hard limit to 5MB for user gimli. No soft or hard limits on number of inodes
CIS 191 - Lesson 9
Managing Quotas
CIS 191 - Lesson 9
Managing Quotas
CIS 191 - Lesson 9
Managing Quotas
CIS 191 - Lesson 9
New commands:chattr - set extended file attributesfsck - Check and repair file systemdumpe2fs - Dump file system informatione2label - Change a file system labeldebugfs - Debug a file systemdu - Disk usage by directorydf - Disk usage by file systemedquota - specify quotaslsattr - list extended file attributesmkfs - make a file systemmount - mount a filesystemquotacheck - check quotasquotaoff - disable quotasquotaon - turn on quotasrepquota - report quotasstat - show inode informationtune2fs - Change or tune a file systemumount - un-mount a filesystem
New Files and Directories:/etc/fstab/etc/mtablost+foundaquota.user, aquota.group