Cosc 4750 File Systems • Which would you expect to find in a “filesystem”? – – – – – Processes serial ports inter-process communication channels Shared memory segments applications and files • All of them are in a UNIX filesystem • UNIX unifies all objects of the O/S into the filesystem – consistent programming interface, easy access from the shell File system components • There are 4 main components – A namespace • Way of naming things and arranging them in a hierarchy – an API • A set of system calls for navigation and manipulating nodes – Security Model • a scheme for protecting, hiding, and sharing things File system components (2) – An implementation • Code that ties the logical model to an actual disk • Pathnames – the directory structure can be as deep as needed, but no name can be longer and 255 characters – But a full pathname can not be accessed properly when it is longer than 4,095 characters File system components (3) • Special characters such as the space, *, ?, and others must either be backslashed or the path must be in double quotes – cat My\ File.txt – cat “My File.txt” • NEVER put a dash as the first character. The – is taken as parameter to the program, not as the filename. Mount/unmouting file systems • You can use the mount command and umount command • mount a usb drive into the filesystem – mount /dev/sdc1 /media/usb • Assuming /dev/hdc4 is the device for the usb drive. • And the /media/usb directory already exists. – mount /media/usb • This assumes usb drive is listed in the /etc/fstab file. • umount /media/usb – unmounts the usb drive from the filesystem Problems unmounting • Unix will not allow you umount a file system that is in use. • umount /home • umount: /home: device is busy – A file is open or a user’s current working directory is on the file system – To find them, you can use the fuser –mv <file system> command • fuser –mv /home • Show all processes user the /home file system – You can also use lsof command on RedHat/Fedora and SuSE installations. File Structure • Most UNIX system follow this convention: – – – – – – – – – – /home (/people) where the user dir. are at /usr system info and applications /usr/local local software (that you install) /usr/bin /bin standard utilities (like ls, grep) /usr/etc where SA utilities are located. /etc system configurations /dev system devices /var system logs and other system info /proc kernel and system info, also images of running processes /boot (linux only), where the kernel and other files are located for booting. File Types • • • • • • • regular files directories character device files block device files UNIX domain sockets Named pipes (FIFOs) Symbolic links -rwx-----drwx-----crwx-----brwx-----srwx-----prwx-----lrwx------ Setting permissions • Use chmod • Can be used in 2 ways – chmod u+x <file> – chmod 700 <file> • Chmod ugo + rx <file> or chmod a + rx <file> u = user, g=group o= world • and chmod ugo – w <file> or chmod a – w <file> • numeric 0 ---, 1 --x , 2 -w-, 3 -wx, 4 r--, 5 r-x, 6 rw-, 7 rwx • so, chmod 744 <file> is -rwxr--r-- Extra bits • There is 1 more field for setuid, setgid, and the “sticky bit” • chmod 4755 <file>, enable setuid – The file runs as the owner, instead of who is actually running it. • chmod 2755 <file>, enable setgid – The file runs as the group • chmod 1755 <file>, enable stick bit – It used leave the program in memory, but is historical and linux silently ignores it. Directory Permissions • • • • For directories, the permission are r: view the contents of the directory, ls x: you can enter the directory, cd w: you can create a file in the directory – without it, in linux you can not modify a file either. • SUN, sgi, etc… implement permissions slightly differently. – you don't need write permissions on the directory to modify a file in the directory. Links • Soft links – the “file” is a redirect to where the “real” file is • All file and directory permissions apply. – Can be used across physical hard drives – deleting the link doesn’t delete the file. The “real” file can be deleted and the link will not work anymore. • Hard links – the “file” is a connected directly to the other file. Only the file permissions of the linked file apply. – Can not be used across physical hard drives. – If you deleted the “real” file, the contents still exist for the linked file or vise versa Links (2) • directories can only be soft linked • Using hard links, file locking does not work • ln –s <target file> <linked filename> – creates a soft link • ln <target file> <linked filename> – creates a hard link Note on size limits • The size of a file and filesystem are dependent on block size FileSystem Type Max File Max Filesystem Ext3 2TB 16TB Ext4 16TB 50TB XFS 500TB 500TB • Block size will effect allocation that can be made in a file, this are using 4K block size Extra attributes • For the ext2, ext3, and ext4 fs • Use lsattr to view, chattr to set/unset – Anyone can set • A, Never update access time • d, no backup (dump will ignore the file) • S, write with no buffering (sort of works) – Causes more problems then is worth. – Only root can set • a, only allow write in append mode • i, make file immutable and undeletable – listed, but don’t work • c, keep contents compressed (transparently) • s, physically erase (write over) when deleted • u, save contents on deletion to permit recovery Default permissions • use the umask command – – – – – the system default is to create all files with -rw-r--r-directories default to drwxr-xr-x umask lists the default permissions in reverse so chmod 755 (rwxr-xr-x), umask 022 For better security you may want to use a • umask 137 (-rw-r----) • umask 177 (-rw-------) • command: set umask 137 Ext4 file system • Ext4 (fourth extended filesystem) – Journaling file system like ext3 – Adopted into the kernel 2.6.28 released Dec 2008 – Support volumes up 1 exabyte and files up to 16 Terabytes – Sub directory limit now 64,000 (32,000 limit in ext3) Ext4 file system (2) • Performance improvements – Delayed allocation, improves performance and reduces fragmentation • Block allocation decisions based on actual file size. • Disadvantage – Delay allocation may lead to data lost in a crash, because old file is already removed, but new data is not written yet. – Ext3 either the old file or new file exists. Quotas • Linux only (others implement differently) – NOTE: quotas and NFS don't work well together. Locally it will tell the user they have exceeded quota, via NFS it may silently discard the file. • add command usrguota and grpquota to /etc/fstab file for each partition using quotas # quotacheck –c /home – creates /home/aquota.user # quotacheck –vug /home – builds a table of disk usage • See chapter 11 for startup scripts. Quotas (2) • Creating quota rules • command edquota –u <user> – NOTE: by default invokes the vi editor – uses blocks instead of kilobytes • a block equals 1K – 512000 blocks is 500MB – 7168000 blocks is 700 MB. – See chapter 11 for more information Quotas (3) • Checking quotas # repquota –a – display a listing of all users, with used space, quota limit, over quota, etc. • using du #du – h –c –s /home/ugrad/* – lists each undergrad's directory with amount of space used (-h show K, M, or GB -c show total at end) Logical Volumes • Technique to deploy large logical volumes, instead of several smaller physical volumes – Can span multiple physical hard drives. – Example: • (3) 9.1 GB drives, use 100 for /boot on one drive • 9.1GB x 3 – 100MB gives about 27GB of space to use, say 20 GB /home and 7Gb for / partation. – Later another 9.1 GB added to extend the volume and then (with ext3) used to expand the /home partition (giving about 29GB). • Note: LVM supports up to 2TB with LVM 2 and 8 Exabytes with 64bit. Q&A