Advanced Operating Systems - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Advanced Operating Systems

Description:

The Linux file system plays a big role in the way you ... You can use this command to take away the possibility of others prying into your private stuff. ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 38
Provided by: tihe
Category:

less

Transcript and Presenter's Notes

Title: Advanced Operating Systems


1
Advanced Operating Systems
Tonga Institute of Higher Education
Lecture 5 Filesystems
2
Linux Filesystems
  • The Linux file system plays a big role in the way
    you interact with Linux. It's important to know
    where things go, how to access them and where to
    find things that you need
  • The typical Linux distribution will have a root
    directory at / and a bunch of folders coming
    from that root directory. Usually like,
  • cdrom home opt tmp
  • dev lib proc usr
  • bin etc lostfound
  • root var boot floppy
  • mnt sbin

3
What's Inside those Folders?
  • The /bin directory (which you can see by typing
    ls /bin contains many of the most common
    commands you'll use.
  • This is where cp and rm and mv all live,
    among hundreds of other of commands that have
    some purpose in Linux
  • The /etc directory is generally for
    configuration files.
  • This is where the kernel and the operating system
    will expect to find things like the list of users
    on the system, the list of passwords, services,
    modules and so on

4
Looking inside /etc
  • Files that are important
  • /etc/passwd this contains a list of users and
    their usernames. It used to contain passwords,
    but it was insecure
  • /etc/shadow this is where passwords are saved
    in encrypted format, only the root user can see
    this file
  • /etc/lilo.conf will show the different
    operating systems available to boot off of
  • /etc/group the list of groups on the system
  • /etc/hosts contains a list of hostnames and IP
    addresses. Used a lot before DNS became popular
  • /etc/fstab information about your partitions
  • You'll also find config files for other programs,
    as well as folders about services that we'll talk
    about

5
Filesystems
  • The /usr directory is usually reserved for
    programs and commands that all users can use on
    the system.
  • Most of your programs will get saved in
    /usr/bin and /usr/sbin
  • It's good that this partition has a lot of space,
    because you'll always be adding new programs to
    your system for different users to use.
  • The /boot directory is where the Linux kernel
    is saved along with other things necessary to
    boot up your computer after you turn it on.
  • If you want to make your computer not work, start
    deleting things from /boot

6
Filesystems
  • The /root folder is a special place just for
    the root user. No one else will be able to open
    or see anything inside. It's usually a good place
    to save things that you don't want anyone to see
    or use
  • The /sbin folder is a special folder of
    commands and programs that only the root user can
    use. These include things like shutdown to turn
    off the computer
  • The /tmp folder is for temporary files. Things
    that are not important. Everyone has access to
    read, write and delete files in this folder. It
    will be used by different programs to save things
    that it will delete later

7
Filesystems
  • The /var is a directory for certain files that
    may change their size (ie. variable size)
  • For example, there are a few excellent databases
    for Linux. One is called MySQL. Normally, MySQL
    keeps its data in a subdirectory of /var called
    /var/mysql/. It is also the normal place where
    email servers store their incoming mail. Again,
    email varies in size as well. (/var/mail/ folder)
  • The /lib is for library files, that's where the
    name /lib comes from. Programs may use libraries
    to carry out their functions. Different programs
    use the same libraries, so Linux will store them
    here so that every program knows where to find
    them. You will probably not have to worry about
    this directory much unless you start getting
    messages like 'can't find shared library...'.
    That will sometimes happens when you've
    downloaded some program and had to compile it
    yourself from source

8
Filesystems
  • The /home directory contains users files and
    folders. When you log in, this is the first
    folder you'll find yourself in. Every user on the
    system will have their own home directory that
    they can use to save whatever they need.
  • The /proc directory contains information about
    processes that are running and things like how
    much memory they're using. It will also contain
    important things about the system that the kernel
    will need to use. Things like memory, devices and
    filesystems. You can see the files are not even
    writeable for the root user. This is because no
    one should change these things manually

9
Filesystems
  • The /dev directory is a folder that contains
    files that represent actually devices that are
    connected to your computer. Things like hard
    drives, CD-Roms, DVD-Drives, floppy drives and so
    on.
  • Everything in Linux is just a file and it's no
    different in the /dev directory. When a program
    needs to access a device, like a floppy drive, it
    will access the file for the floppy drive
  • If you look inside the /dev drive you'll see
    hundreds of files. You don't have that many
    things connected to your computer, so what are
    they all? Mostly, just in case you want to add
    more things to your computer in the future.

10
The real filesystem
  • We talked about where data is stored in the
    filesystem, now we need to know exactly about
    filesystems
  • MS-Windows, from Windows 95 on up uses file
    systems called 'vfat' (old) or 'ntfs.' (new).
    Linux uses a different system called 'ext3'.
    There are also other types of file systems out
    there. There are actually hundreds of types. They
    are really just different ways to save data on
    your hard disk. You may have chosen to have both
    Windows and Linux installed in your computer.
  • Sometimes, you might have to access files in the
    Windows partition of your hard drive.
  • You would use a command called 'mount' to do
    that. You would also have to indicate as an
    option in that command that the file system you
    want to access or "mount" is a Windows 'vfat'
    file system

11
Mount
  • The mount command is the way for Linux to connect
    to a different device or file system. For
    example, to connect to your Microsoft partition,
    if that partition is named /dev/hdb, use...
  • root_at_usp root mount -t vfat /dev/hdb
  • On the same idea, you may want to store some
    files on a floppy or access data on a floppy that
    someone has given to you.
  • You would also have to use the command 'mount'
    before you copied data to or got data from a
    floppy disk. If that person is a Windows user,
    then you would have to indicate once again that
    the file system is 'vfat'. If you want to copy
    data from your Linux partition to a floppy, you
    would have to format and then "mount" the floppy
    as a Linux 'ext2' file system.

12
Making floppies
  • Most floppies sold on the market are
    pre-formatted for MS-Windows. You can copy data
    from Linux to a Windows formatted floppy with no
    problem. If you want to copy Linux files to a
    floppy to be used in another Linux machine or to
    be used by you later in Linux, then it might be
    better to format the floppy for Linux's ext2 file
    system (one that is a little older than ext3).
  • To create a linux floppy "by hand", you would
    place a floppy in the drive and type
  • mke2fs /dev/fd0
  • The command is an abbreviated way of saying "make
    an ext2 file system". The other part is the
    device, your floppy drive, which is known to
    Linux as "fd0" (floppy drive 0). As we mentioned
    in the first part of the course, everything is a
    file in Linux, including your floppy drive.

13
Mounting file systems
  • Though some windows managers for Linux have ways
    for clicking on an icon to access a floppy drive,
    usually in Linux the floppy drive or other device
    must be "mounted". That means basically, making
    it temporarily a part of your Linux file system.
    In other words, telling Linux that it is a file
    to be written to or copied from.
  • To access a floppy disk from the command line of
    our shell, we would use the command mount and
    type the following (remember you need to be
    working as 'root' to do this)
  • mount -t ext2 /dev/fd0 /floppy

14
Mounting
  • Mounting this floppy assumes a couple of things
  • you have a floppy disk in the drive
  • in this example, the floppy type
    (indicated by the option -t) is a Linux formatted
    floppy. If you want to mount a Windows floppy,
    change the option to -t vfat
  • in your root directory (you can get to
    it by typing cd /), you have a directory called
    floppy. If you don't, you should create it (mkdir
    floppy). Some Linux distributions create this
    automatically during the installation process.
    Some don't.

15
Mounting
  • When we typed
  • mount -t ext2 /dev/fd0 /floppy
  • We told Linux that our floppy disk is now part of
    our Linux file system (/dev/fd0) and that any
    files we would like to store on that disk will be
    copied to /floppy, as if it were just another
    directory on our Linux system.
  • If you did it right, typing the command 'df' (the
    command to see how much free disk space) should
    include something like this
  • /dev/fd0 1390 649 669 49 /floppy

16
Mounting
  • Now, to copy to and from the floppy disk, you
    would type
  • cp my_file /floppy
  • If you wanted to create individual subdirectories
    on the floppy, you would first change to the
    /floppy directory
  • cd /floppy
  • Then you would use the mkdir command to create
    the directories you want. You can also use the
    command
  • cp -r my_directory/ /floppy
  • to copy the directory automatically to the
    floppy.

17
Mounting other devices
  • You can also use the mount command to copy to and
    from other devices.
  • If you would like to get some files from a
    CD-ROM, the standard command to do this is
  • mount -t iso9660 /dev/hdb /cdrom
  • The type, iso9660 is the standard file system for
    a CD. The device (/dev/hdb) is the type of CD-ROM
    and the mount point (/cdrom) should exist. If it
    doesn't, you should create it in the root
    directory with 'mkdir', just as you may have done
    with the /floppy directory.
  • Remember that the concept of CD-ROM is read only.
    You won't be able to write to this type of CD-ROM
    drive. A message will tell you that when you
    mount this type of device.

18
Mounting another partition of the hard disk.
  • Many people may have preferred to install Linux
    along with another operating system. You may have
    Linux and Windows installed in the same computer.
    If you would like to access files on the Windows
    partition you would type the following command
  • mount -t vfat /dev/hda1 /mnt
  • Windows is always in the primary partition, so
    that's why we've used the device /hda1 (hard disk
    partition 1). The choice for /mnt is the standard
    mount point in this case. You may use the /mnt
    directory to mount the other devices (floppies,
    CDs) as well.

19
Unmounting file system
  • Mounting file systems that aren't part of the
    standard Linux system is considered a temporary
    condition in Linux. Now that we know how to mount
    these outside file systems in Linux, the
    important thing now is to learn how to unmount it
    when we're finished using it.
  • In the old days, if you didn't unmount, you could
    mess up your system. Today you can usually get
    away with it, but notice that you can't eject a
    CD until you have unmounted the disc
  • To unmount a device, use the command below
  • umount /floppy
  • Notice, it's umount and NOT unmount. You also
    type the place of the thing you have mounted, not
    the device.

20
Permissions for Files
  • Linux has inherited from UNIX the concept of
    ownerships and permissions for files.
  • This is basically because it was conceived as a
    networked system where different people would be
    using a variety of programs, files, etc.
  • Obviously, there's a need to keep things
    organized and secure. We don't want an ordinary
    user using a program that could potentially trash
    the whole system.
  • We also don't want someone's wife reading their
    love letters to another woman

21
File Permissions
  • If you run the command 'ls -l' in your home
    directory, you will get a list of files that may
    include something like this
  • -rw-r--r-- 1 bob users 1892 Jul 10 1830
    notes.txt
  • This basically says, interpreting this from RIGHT
    to LEFT that the file, notes.txt was created at
    630 PM on July 10 and is 1892 bytes large. It
    belongs to the group users (i.e, the people who
    use this computer). It belongs to bob in
    particular and it is one (1) file. Then come the
    file permission symbols.

22
File Permissions
  • -rw-r--r-- 1 bob users 1892 Jul 10 1830
    notes.txt
  • So what do the symbols 'rw-rr--' mean?
  • The slash marks - separate the permissions into
    three types
  • The first part refers to the owner's (bob's)
    permissions.
  • The slash mark - before the rw means that this
    is a normal file that contains any type of data.
    A directory, for example, would have a 'd'
    instead of a slash mark.
  • The rw that follows means that bob can read and
    write to (modify) his own file. That's pretty
    logical. If you own it, you can do what you want
    with it.

23
File Permissions
  • -rw-r--r-- 1 bob users 1892 Jul 10 1830
    notes.txt
  • The second part of the these symbols after the
    second slash, are the permissions for the group.
    Linux can establish different types of groups for
    file access. In a one home computer environment
    anyone who uses the computer can read this file
    but cannot write to (modify) it. This is a
    completely normal situation. You, as a user, may
    want to take away the rights of others to read
    your file.
  • After the two slash marks (two here because
    there is no write permissions for the group) come
    the overall user permissions. Anyone who might
    have access to the computer from inside or
    outside (in the case of a network) can read this
    file. Once again, we can take away the
    possibility of people reading this file if we so
    choose.

24
Changing Permissions
  • 'chmod' is the program that is used to change
    file permissions on a Linux system.
  • Others cannot modify your personal user files but
    you may not want other people to even read these
    files. You can use this command to take away the
    possibility of others prying into your private
    stuff.
  • The syntax (parts separated by brackets) for
    using this command is the following
  • chmod a/o/g/u or - r/w/x

25
Chmod
  • chmod a/o/g/u or - r/w/x
  • The symbols in the first brackets refer to the
    four concepts of users that Linux has.
  • aall, all users
  • oothers, (other people)
  • ggroup, the members of your group
  • uuser, (this means you)
  • The symbol adds permissions and the symbol -
    takes them away.
  • Your actual rights to files - rread rights,
    wwrite rights and xexecutable rights

26
Chmod Examples
  • Take away read rights for everybody except you
  • chmod og-r notes.txt
  • Take away executable rights for everybody?
  • chmod a-x file.exe
  • Give read and executable rights to everyone?
  • chmod arx notes.txt
  • Take away read right for group?
  • chmod g-r notes.txt
  • Take away read and write rights from yourselves?
  • Chmod u-rw notes.txt

27
Chmod with numbers
  • You don't need to use the letter abbreviations
    with chmod. You can also use a bunch of numbers
    that will be very difficult to remember at first
  • We have three sections to permissions those of
    the owner of the file followed by those of the
    group and then the permissions of others. So if
    you use numbers with 'chmod', there will be three
    numbers following the command. One number
    corresponds to each group. Here's an example of a
    chmod command with numbers
  • chmod 644 grocery_list.txt
  • The 6 is from the owner, the 4 is for the group
    and the next 4 is for the other people.
  • So what do those numbers mean?

28
Chmod with numbers
  • The three types of permissions correspond to
    three numbers. Read permission is given a value
    of 4. Write permission is given a value of 2.
    Execute permission is given a value of 1. Here's
    what it would look like
  • User (or the owner) Group Others
  • read-write-execute read-write-execute
    read-write-execute
  • 4-2-1 4-2-1 4-2-1
  • It's really just simple arithmetic.
  • In our example of chmod 644 grocery_list.txt,
    we've added the 4 for read permission and to the
    2 for write permission for the owner to get 6.
    We've just given the group and others read
    permission, so there's nothing to add in these
    two groups. Just give it a 4 in each case. 644.
    And done.

29
Chmod examples with numbers
  • RWE for owner, RW for group, RW for others?
  • chmod 755 file.txt
  • RE for owner, RW for group, nothing for others?
  • chmod 560 file.txt
  • WE for owner, E for group, W for others?
  • chmod 312 file.txt
  • RWE for owner, nothing for everyone else?
  • chmod 700 file.txt
  • RW for owner, R for group, R for others?
  • chmod 644 file.txt

30
Chown Changing owners
  • The command 'chown' is the chmod's cousin. It is
    used for changing the ownership rights of a file.
  • It does not change the read, write and execution
    permissions however, it only changes who owns the
    file and what group it is in. The command is uses
    like this
  • chown ownergroup the_file
  • Pretend there is a file in /home/user/ called
    the_file and if you type 'ls -l' the_file you'll
    get something like this
  • -rw-r--r-- 1 root root 2428 Nov
    17 1318 the_file
  • You can see, root is the owner of the file.
    Therefore, root is the only one who has write
    permissions for the file. If you want to use the
    file, you won't be able to read at all, so let's
    change it to your username
  • chown useruser the_file

31
Chown
  • This example assumes your Linux version creates
    groups for each user. There are others that will
    create a generic group called users for everybody
    who uses the computer.
  • On a network, groups are created according to the
    needs of the organization. On your single home
    computer, just type ls -l and see what system
    corresponds to you.
  • As you can see, 'chown' is absolutely necessary
    if you're working as more than one user with the
    computer.

32
Learning more about filesystems
  • Filesystems are created on disk partitions to
    enable applications to store and organize data in
    the form of files and directories.
  • Linux, like Unix systems, uses a hierarchical
    filesystem composed of files and directories,
    which can contain either files or other
    directories.
  • The files and directories in a Linux filesystem
    are made available to users by mounting them
    using the Linux "mount" command, which is
    generally done as part of a Linux system's
    startup process.
  • The list of filesystems that are available for
    use is stored in the file /etc/fstab (which
    stands for filesystem table),
  • While the list of filesystems that are currently
    mounted is maintained by Linux in the file
    /etc/mtab (which stands for mount table).

33
More filesystems
  • As each filesystem is mounted during the boot
    process, a bit in the filesystem header
    (popularly known as the "clean bit") is cleared,
    which indicates that the filesystem is in use and
    that the data structures used to manage
    allocation and file and directory organization in
    that filesystem may actively be changing.
  • When a Linux system crashes or is simply turned
    off without going through the standard shutdown
    procedure, the clean bit in filesystem headers is
    not set. The next time the system boots, the
    mount process detects filesystems that are are
    not marked as being clean, and manually verifies
    their consistency using the Linux/Unix 'fsck'
    (filesystem check) utility.

34
Journaling
  • In order to reduce filesystem inconsistencies and
    minimize system restart time, journaling
    filesystems keep track of the changes that they
    will be making to the filesystem before they
    actually make them to the filesystem.
  • These records are stored in a separate part of
    the filesystem, typically known as the "journal"
    or "log".
  • Once these journal records (also commonly known
    as "log" records) are safely written, a
    journaling filesystem applies those changes to
    the filesystem and then purges those entries from
    the log.
  • Journal records are organized into sets of
    related filesystem changes, much like changes
    made to a database are organized into
    transactions.

35
Journaling filesystems
  • There are a number of journaling filesystems
    available for Linux.
  • The best known of these are XFS, a journaling
    filesystem originally developed by Silicon
    Graphics
  • The ReiserFS, a journaling filesystem developed
    especially for Linux,
  • JFS, a journaling filesystem originally developed
    by IBM
  • And now, the ext3 filesystem

36
Ext3 Filesystem
  • RedHat 8.0 and above now use the ext3 filesystem
    (you can see it the /etc/fstab file)
  • The ext3 filesystem is a journaling version of
    the Linux ext2 filesystem.
  • The ext3 filesystem has one significant advantage
    that no other journaling filesystem has - it is
    totally compatible with the ext2 filesystem. It
    can therefore make use of all of the existing
    applications that have already been developed to
    manipulate and fine-tune the ext2 filesystem.
  • Reiserfs is another, well developed, journaling
    file system. Slackware lets you choose this type

37
Conclusion
  • The layout of the filesystem in Linux is one of
    the most important things you can know about.
  • Knowing where to find things and where to put
    things is a big key in keeping your system up to
    date and working well
  • Knowing about the filesystem that underlies your
    system will give you a better understanding about
    what is happening to your Linux computer.
Write a Comment
User Comments (0)
About PowerShow.com