Upload
minsuk-lee
View
192
Download
1
Tags:
Embed Size (px)
Citation preview
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Linux File Systems and File
Minsuk LeeHansung University, Seoul, Korea
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Linux File System
• In Linux, everything is a file.– Its attribute is different
• Regular File, Directory, Link, Device
• Every file has owner and group.• Every file has permission for– owner, group, and others
• Prebuilt directory architecture :– /etc, /dev, /usr, /sbin, /…
DON’T CHANGE IT !YOU MANAGE YOUR OWN HOME DIRECTORY ~/
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Attribute of a File
• $ ls -l
Attr perm #link owner group file size date time filename----------------------------------------------------------------------------------------rw-r--r-- 1 myuser myuser 164 2011-08-28 14:25 myfile - rwx r-x
r— 0 7 5 4Attribute user group other
Attribute:- : regular file b : block devicec : character de-viced : directoryl : symbolic link p : pipes : socket
File name :256 charactersCase sensitiveNo extensionMost special characters ac-cepted
$ chmod, $chown work here !
permission:r : readablew : writablex : executable (traversable)
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
• Inode has information of a file– Inode also exists in disk– All the attributes, times, owner– Data block locations
Inode (metadata for a File)
inode
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
File link• Link (hard link), Symbolic Link
– myfile and myfile-link shares same disk space• One good usage of hard link is to protect not to be erased acciden-
tally
– myfile-sym-link is a link file with the target file name in it
Inode 블럭
Data 블럭디렉토리
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Permission Masking
• Default permission setting– ‘$ umask mask ‘ : masking 666 (rw-rw-rw-) with mask – default mask value = 022 (rw-r--r--)– ‘x’ field cannot be masked
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
• Some commands needs to change other’s file
Need some mechanism to run command with file owners permis-sion
• $ chmod u+s <executable-file>– Sets UID field in inode attributes– Makes rwx to rws
Set UID option !
THINKSECURITY
!!
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
The Root Directory ‘/’ (1)
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
The Root directory (2)• / : the root directory (top most directory in the system)
– All absolute directory path starts with ‘/’
–There is NO ‘C:\’, ‘D:\’,– every storage is mounted somewhere in directory hier-
archy• /cdrom, /mnt/floppy, …
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
/dev (1)• Device special files : the abstraction to access hardware
devices– block devices : hdd, cdrom, floppy disk, tape, USB memory– character devices : serial port, …– other devices
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
/dev (2)
• IDE hdd– brw-rw---- : b block device, user/group :
rw– Owner : root, group : disk– Device Major, minor number : 8,0– /dev/sda : the Whole IDE disk• /dev/sda1, /dev/sda2, /dev/sda5 : partitions
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Partition table
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Other directories (1)• /bin : Most frequently used commands • /etc : Configuration File directory– System itself, servers, applications, …
• /home : user’s home directories• /lib : shared libraries, kernel modules• /lost+found : area for file system check utility• /mnt : default mount point (not mandatory)– For removable storages (cdrom, usb, floppy, ...)
• /root : home directory for superuser• /sbin : commands for system management– fsck, ifconfig, lsmod, mkfs, reboot…
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Other directories (2)
• /tmp : directory for temporary data • /var : directory for frequently changed data
– Logs, mail spool, print spool, lock files• /sys. /proc : system monitoring (virtual)• /usr : commands/library/data for users
• /boot : files for Boot– Booting Process
• PowerON ROM-BIOS (read MBR) BootLoader Kernel• For embedded devices there is no ROM-BIOS
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Locating files• $ which <filename>
– Search execution file in PATH
• $ whereis <filename>– Search Execution file, source, man page file
• $ locate <filename-pattern>– Search system for the pattern
• Works like ‘$ find ./ -name *pattern*’
– Needs ‘$ updatedb’ to refresh database
CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPANEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
Let’s practice !
• Make link and symbolic link for a file– See what happen if erase files• Erasing the link file, erasing the original file
• Apply umask and generate file with $vi