Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CNIT 17600 - Intro Computer Architectur

The Linux Filesystem - Everything is a File

About Reports

A note about lab reports - your pi now has internet access, so there is no legitimate reason to use your phone to take screenshots for evidence. You can use the command line command scrot (which you may have to install with the command sudo  apt-get  install  scrot). That command takes a screen shot and saves it to your user’s Desktop or home directory, usually. These images should have a figure caption below them in your report that briefly describes the contents of the screenshot. This part has been true all semester, but as this is one of the last reports of the semester, you should definitely be in the habit of doing this at this time.

Linux File System

A metaphor that is used to describe the filesystem in Linux/Unix is that of a tree. Each file is a leaf on the tree, and each level of the directory structure can be seen as a branch. The filesystem starts at “the root”. You should install a utility called tree using the command sudo  apt-get  install  tree at the start of this lab manual. Include a screenshot to show that the tree has been installed.

Starting from the Root(s) and growing up

Question 1:

The root of a filesystem is the point above which (or below which - depending on how you imagine the tree to be growing) there can be no additional files or folders created. It represents the starting point of all the system and user files and directories.

Question 1a (“root” is confusing):

Root is the name for both the superuser  (administrative user) in Linux, and it is the absolute start of any file’s path.  It is also the name of the home directory for the root administrative user (/root). What is the root of the filesystem on Mac OS X and on Win- dows 10?  How is the root directory represented in the Linux filesystem?  Create a table with a column labeled root directory representation” and three data rows (one for each of the operating systems). Fill in your answers in this table, give the table and appropriate name label, and include them in your report.

Question 1b (path to home):

When showing the path to a file from the root of the filesystem, Linux and OS X depict directories in one way, and Windows does so in a different way.  Write out the full path from the root (also known as the absolute path) to your Raspbian user’s home directory. Do the same for your user’s documents folder on your personal computing device.

Question 1c (absolute v relative paths):

The root of the file system is the very top level.  There are no directories above it (it is the parent of all other directories).  If you want to specify the absolute file system path from the root to the sub-directory  “usr”, to its sub-directory “bin,” to the file “xeyes”, how would you do so?

How does your answer change if your working directory (the results of the output of the pwd command) shows that you are in usr and you want to use “relative”paths (starting from where you are to where you want to go)?

When you are navigating the Linux file system, it’s valuable to know several commands. First, if you want to know your location in the file system, you can use the pwd command. It will  “print working directory” .  This is the current location in the filesystem.  Most problems with students using Linux occur because they are trying to access files from the command line using the wrong path or being on the wrong path. The common error you will get is No such file or directory” . If you see this, you are probably trying to get a file that isn’t in your path or you have typed it incorrectly.

Linux filesystem is case  sensitive.   So a directory called Home is different than one called home.

If you want to know all the contents of that directory, you can ls  -a.  This command lists all the contents of the directory you give it (if you don’t specify the path, it uses the current location in the filesystem). By saying that, it lists ALL the files, this includes hidden files (signified with a . in front of the file name like /home/user/ .bashrc).

Differentiating between files and directories, a“ .”is also the character used to specify  your current location in the file system. It basically translates to “here”. If you were to cd  . you have changed directories to the same place you were (the output of pwd would not  change after the cd command is executed). The parent directory to your current directory  is specified as“ ..”So, if the results of pwd is /etc/X11/fonts and you wanted to go back to the X11 directory, you could use the command cd  . .. The results of pwd would now be /etc/X11. If you wish to go to the parent of your parent directory, you can use cd ../..” You can do this to go up any number of levels of directories (at least until you hit the root).

Question 2a (navigating by parent paths):  Based on the above scenario where you are located in /etc/X11/fonts: If you were to cd  . ./ . ./ . .  what directory would you be lo- cated in?

Question 2b:

If your current working directory is /etc/X11/fonts/misc and you want to be in the direc- tory /etc/X11/app-defaults name the absolute path command line command to get there, as well as any variation of a relative path command (using parents or the path from your current working directory by name).

Each of the directories in the root folder in Linux was (originally) 3 letter abbreviations of the use the directory had in the Unix filesystem.

/bin  =  binary

/lib  =  library

/var  =  variable

/usr  =  user

/tmp  =  temporary

/etc  =  et  cetera

/adm  =  administrative  (now  found  in  /var/adm)

/log  =  logs  (now  found  in  /var/log)

/net  =  network

/mnt  = mount

Question 3a:

Draw a map of the file system root (by hand or with software) in Raspbian and the first level of directories that root currently contains.  The ls command can be used to list all the contents of a directory.

Question 3b:

What types of files are currently contained in the /etc directory? In addition to describing the files in general, name one example directory or file that might be helpful for your pi project in particular.

Question 3c:

Linux filesystem permissions use 3 octal (digits 0-7) nibbles (octal nibble is 3 bits) to define permissions for, respectively, the resource (file or directory)) owner, the resource group’s owner, and finally, the rest of the universe.  The first bit denotes whether the resource is a directory (d) or a file (-) (or another type of filesystem node).  The next nine bits are defined in this order:  read (r), write (w), execute (x).  A dash is used to show that the permission is set to false.

The ls command lists the contents of a directory, but some flags can give additional infor- mation besides the file and directory names. The command ls -alh will list all the contents of a directory (including hidden files and folders), will give the long form (including per- missions information and when it was last edited), and will do so in human readable form. The output of ls -l has the following values:

perms

resource link #

owner name

group owner

size

date created

Name of resource

drwxr-xr-x

2

cyberstudent

cyberstudent

4096

Aug 17 2019

Documents

Table 1: Values of ls  -l Output

Using the command ls  -alh, who owns the files in the /etc directory? What permissions does your user have on these files, in general (for a specific example, consider the file called “hostname”)? What about for subdirectories? What permissions does your user have for those?

Question 4:

In Unix and Linux, conceptually, (nearly) everything is considered to be a file, though there are exceptions to this general rule. Name 5 parts of the Linux system that are presented to the user as a file, and one part of the system that is not. It is helpful for this task to look at the permissions in a directory and to see the types of resources in the directory. Most are labeled with a d for the directory or a - for a file.  The /dev directory has a couple of different options. The command file will tell you what type of resource a file node is. You can use it on some of these unfamiliar items to help you fill out the other resources considered to be files. You will likely have to do external research to figure out what these mean, and it is important that you cite your sources.

Troubleshooting with Logs

When something goes wrong when using Linux, there are a few places we can look to find clues about what has happened.  The systemctl commands will address the starting and stopping of services (like networking) and can give output about the status of those services.   Sometimes this output will direct you to the location of a file containing log information.  The Linux system logs certain information standard and can be configured to log more or less by a system administrator as needed.

Question 5a:

In the file /etc/ssh/sshd config there is a configuration option for the LogLevel. The line above the log level shows the SyslogFacility location is AUTH. The auth logs are located at the path /var/log/auth.log

First, change the value of the LogLevel variable to  VERBOSE”.  To do this, you will need to edit the file using a command line text editor.  Many of the guides you will see for projects will suggest you use nano.  Others include vi, vim, or emacs.  If you have a different preference, you may use that instead. To edit the file, use the command:

sudo  nano  /etc/ssh/sshd_config

The commands to operate in nano are listed at the bottom of the screen.  To save your changes type ctrl+x (to exit the editor),“y”(to answer yes to save changes), and “enter”  (to keep the file name the same as it was previously). Notice that the Linux terminal gives  you prompts at the bottom of the screen when it needs input from you to move forward. To restart the SSH session, you can use either the command sudo  service  ssh  restart OR sudo  systemctl  restart  ssh .service.  Ensure it’s working by replacing the word “restart” in either of those commands with the word “status”.

Create an SSH session into your Raspberry Pi (like from the networking lab) and then cat (the command to print out the contents of a file to the terminal) the contents of the /var/log/auth.log file. What information was logged about your SSH session?

Question 5b:

Find a log file that might be useful for your project’s troubleshooting efforts. Give its full path (i.e., from root) and describe why it might be helpful.