<p>In order to provide you with a working knowledge of the Linux filesystem, the following topics will be introduced in this section.</p><ol type="1"><li><p>The Linux Root Filesystem</p></li><li><p>Permissions</p></li><li><p>Alternative Filesystems</p></li></ol><div class="SECT2"><h2 class="SECT2"><a name="AEN2664">Overview</a></h2><p>The filesystem is made up of <i class="EMPHASIS">files</i> and <i class="EMPHASIS">folders</i> or directories. The top level folder is called the <i class="EMPHASIS">root</i> folder and contains all of the files that are pertinent to your system. Each file within this system is allotted a name and a path on the basis of where it lies in relation to the root folder. Thus a sample file -<tt class="FILENAME">alephlinux.txt</tt>- may be found at <tt class="FILENAME">/home/letters/alephlinux.txt</tt> where the forward slash <span class="QUOTE">&quot;/&quot;</span> before <i class="EMPHASIS">home</i> denotes root. </p><div class="IMPORTANT"><blockquote class="IMPORTANT"><p><b>Important: </b>The new user must also appreciate that the filesystem is case-sensitive and therefore distinguishes between <tt class="FILENAME">ALEPHLINUX.txt</tt> and <tt class="FILENAME">alephlinux.txt</tt>.</p></blockquote></div><p>Linux also provides support for long filenames although you should avoid the use of symbols like <span class="QUOTE">&quot;@&quot;</span> within filenames, as they are used for other purposes.</p></div><div class="SECT2"><h2 class="SECT2"><a name="AEN2685">The Linux Root Filesystem</a></h2><p>The following schematic provides a simple representation of the most important directories and files which make up the root filesystem whilst the subsequent sub-section provides a brief description of the filesystem's structure. For more information about the root filesystem, enter <b class="COMMAND">man hier</b> at the prompt for a full description.</p><div class="FIGURE"><a name="LINUX-ROOT-FILESYSTEM" /><p><b>Figure 9-1. Linux Root Filesystem</b></p><div class="MEDIAOBJECT"><p><div class="photo">
<a href="?q=node/284"><img src="?q=img_assist/gen/284" width="545" height="304" alt="Linux - Root filesystem" />
<div class = "caption">Linux - Root filesystem
</div></a>
</div>
</p></div></div></div><dl><p><b>Directories</b></p><dt><tt class="FILENAME">/usr</tt></dt><dd><p>Contains files and sub-directories which may be shared between machines. Important sub-directories include:</p><ul><li><p><tt class="FILENAME">/usr/lib</tt> which contains programming and language libraries</p></li><li><p><tt class="FILENAME">/usr/local</tt> which provides the location for user-specific programs and files</p></li><li><p><tt class="FILENAME">/usr/include</tt> for C #include files</p></li></ul></dd><dt><tt class="FILENAME">/etc</tt></dt><dd><p>all configuration files should be in here (often in subdirectories)</p></dd><dt><tt class="FILENAME">/home</tt></dt><dd><p>contains home directories for all users on the system. <tt class="FILENAME">/home/paul</tt> would therefore be the home directory for user <i class="EMPHASIS">paul</i>.</p></dd><dt><tt class="FILENAME">/bin</tt></dt><dd><p>contains fundamental executable files (commands or programs) used by users. Only the basic ones are here, most are in /usr/local/bin, but usually a user doesn't care where the executable is actually stored. <b class="COMMAND">which &lt;commandname&gt;</b> will tell you where an executable actually resides.</p></dd><dt><tt class="FILENAME">/sbin</tt></dt><dd><p>includes executable files which are for system administration, as opposed to programs used by users. An example of this would be the <b class="COMMAND">shutdown</b> command which closes the system down properly.</p></dd><dt><tt class="FILENAME">/mnt</tt></dt><dd><p>location for <i class="EMPHASIS">mounting</i> filesystems. For supplementary information, consult <a href="http://www.aleph1.co.uk../../../armlinux/book/x2654.html#ALTFILESYS">the section called <i>Alternative Filesystems</i></a></p></dd><dt><tt class="FILENAME">/tmp</tt></dt><dd><p>a directory which provides the temporary location for different programs. <tt class="FILENAME">/tmp</tt> files tend to be deleted when the system is re-booted.</p></dd><dt><tt class="FILENAME">/dev</tt></dt><dd><p>contains special <i class="EMPHASIS">pseudo</i> files which give access to devices like the keyboard - /dev/kbd - and the virtual terminals - /dev/console, /dev/tty0 and /dev/tty1.     </p></dd><dt><tt class="FILENAME">/var</tt></dt><dd><p>a directory which contains files which can grow through usage. Typical examples include email message files and system accounting files. </p><ul><li><p><tt class="FILENAME">/var/adm</tt> for per-process accounting records</p></li><li><p><tt class="FILENAME">/var/tmp</tt> for temporary files which are not deleted at re-boot time.</p></li><li><p><tt class="FILENAME">/var/spool</tt> for running system processes. /var/spool/mail would be a typical file in this sub-directory </p></li></ul></dd></dl></div><div class="SECT2"><h2 class="SECT2"><a name="AEN2820">Permissions</a></h2><p>Although you should now have some appreciation of the Linux filesystem it is important to realise that Linux can be used in a multi-user or networked environment. It is therefore sensible to learn about the various types of <i class="EMPHASIS">role</i> and <i class="EMPHASIS">permission</i> which can be associated with a file so that the file <i class="EMPHASIS">owner</i> can decide exactly who has access to files.</p><p>Any user may consequently fit into any one of three roles which include:</p><ol type="1"><li><p>the <i class="EMPHASIS">ownership</i> role</p></li><li><p>the <i class="EMPHASIS">group</i> role</p></li><li><p>the <i class="EMPHASIS">other</i> role</p></li></ol><p>The <i class="EMPHASIS">owner</i> of a file can change file permissions at will. Moreover, a file may be associated with a <i class="EMPHASIS">group</i> which is useful in a collaborative project context in which file access can be restricted to group members. Finally, the <i class="EMPHASIS">other</i> role applies to a user who is neither the owner of the file nor the member of the group which is associated with the file.</p><p>In a similar vein, for every Linux file, three types of permission can be applied to each of the three roles. These permission <i class="EMPHASIS">switches</i> are as follows</p><ol type="1"><li><p><span class="ABBREV">R</span> (Read): enables the user to read files, or (for a directory) to list files on the system</p></li><li><p><span class="ABBREV">W</span> (Write): allows for the alteration or deletion of files, or (for a directory) deleting, adding and renameing of files</p></li><li><p><span class="ABBREV">Execute</span> (Execute): allows for the execution of a file where it is an executable or for changing directories.</p></li></ol><p>In order to clarify matters, this information can be most effectively presented in tabular form. Note that a dash in the line of text denotes the absence of a permission whilst <span class="ABBREV">r</span>, <span class="ABBREV">w</span> or <span class="ABBREV">e</span> indicates that one of the three types of switch is activated.</p><div class="TABLE"><p><b>Table 9-3. Permissions by Role</b></p><table border="1" class="CALSTABLE"><tbody><tr><th valign="top" align="left">Owner</th><th valign="top" align="left">Group</th><th valign="top" align="left">Other</th></tr><tr><td valign="top" align="left">r w x</td><td valign="top" align="left">r w x</td><td valign="top" align="left">r - x</td></tr></tbody></table></div><p>To illustrate all of the above, consider a situation where we want to know the permissions which apply to a particular file. After invoking the <b class="COMMAND">ls -l</b> &lt;filename&gt; command, our hypothetical output might look some thing like the following:</p><p class="LITERALLAYOUT">&mdash;rw&mdash;r&mdash;&mdash;r&mdash;&mdash;&nbsp;1&nbsp;paul&nbsp;paul&nbsp;388&nbsp;June&nbsp;10&nbsp;09:30&nbsp;notes.txt</p><p>Reading across the listing from left to right, the first character position show the file's filetype which in this example is a normal file. Other possibilities include:</p><ol type="1"><li><p>d for a directory</p></li><li><p>c for a device</p></li><li><p>b for a socket</p></li><li><p>s for a pipe</p></li></ol><p>The remaining nine bits apply to the user, group and other roles respectively with three bits being alotted to each of the roles. Thus our hypothetical output shows that the user has <i class="EMPHASIS">read</i> and <i class="EMPHASIS">write</i> permissions whilst the <i class="EMPHASIS">group</i> and <i class="EMPHASIS">other</i> roles have read permission only. Note also that a dash denotes the absence of a permission.</p><p>If however, it becomes necessary to change file permissions, this can be accomplished by:</p><ol type="1"><li><p>setting file permissions with octal numbers</p></li><li><p>setting file permissions with a combination of symbols</p></li><li><p>setting the setuid, setgid and sticky bits</p></li></ol><p>To alter a file's permissions with numbers, Linux uses four numbers which determine permission types including:</p><ol type="1"><li><p>4: read permissions</p></li><li><p>2: write permissions</p></li><li><p>1: execute permissions</p></li><li><p>0: no permissions</p></li></ol><p>Therefore, to alter the permissions status of our hypothetical file so that the <i class="EMPHASIS">group</i> has <i class="EMPHASIS">read</i> and <i class="EMPHASIS">write</i> permissions, we would add 4 (read permission) and 2 (write permission) together before issuing the following command:</p><p><b class="COMMAND">chmod 664 notes.txt</b> </p><p>The following table summarises the situation thus far:</p><div class="TABLE"><p><b>Table 9-4. Permissions by Numbers</b></p><table border="1" class="CALSTABLE"><tbody><tr><th valign="top" align="left">Role</th><th valign="top" align="left">Permission</th><th valign="top" align="left">Calculation</th></tr><tr><td valign="top" align="left">Owner</td><td valign="top" align="left">6</td><td valign="top" align="left">4+2+0 (r+w+e)</td></tr><tr><td valign="top" align="left">Group</td><td valign="top" align="left">6</td><td valign="top" align="left">4+2+0 (r+w)</td></tr><tr><td valign="top" align="left">Other</td><td valign="top" align="left">4</td><td valign="top" align="left">4+0+0 (r)</td></tr></tbody></table></div><p>In a situation where it is necessary to set permissions one role and one permission at a time, the <i class="EMPHASIS">symbolic permission</i> notation can be used. In order to make use of this facility, the user need only remember that permissions may be granted or denied by using the following three symbols in conjunction with the read, write and execute switches that we have already encountered:</p><ol type="1"><li><p>u signifies the user/owner role</p></li><li><p>g represents the group role</p></li><li><p>o signifies the other role</p></li></ol><p>Therefore, in order to allocate a group read and write permissions for the file <tt class="FILENAME">notes.txt</tt> using symbolic notation, the user could enter the following command:</p><p><b class="COMMAND">chmod g+rw notes.txt</b> </p><p>Because many permutations are possible when using this method, the table below gives some indication of how permissions may be alterred. Note that <span class="QUOTE">&quot;+&quot;</span> means that <i class="EMPHASIS">permission is granted</i> whilst <span class="QUOTE">&quot;-&quot;</span> shows that <i class="EMPHASIS">permission is denied</i>.</p><div class="TABLE"><p><b>Table 9-5. Permissions by Symbols</b></p><table border="1" class="CALSTABLE"><tbody><tr><th width="33%" valign="top" align="left">Granted/Denied</th><th width="33%" valign="top" align="left">Permissions</th><th width="33%" valign="top" align="left">String</th></tr><tr><td width="33%" valign="top" align="left">user, group, other</td><td width="33%" valign="top" align="left">read, write, execute</td><td width="33%" valign="top" align="left">ugo+rwx</td></tr><tr><td width="33%" valign="top" align="left">user, group, other</td><td width="33%" valign="top" align="left">read, write, execute</td><td width="33%" valign="top" align="left">ugo-rwx</td></tr><tr><td width="33%" valign="top" align="left">user, group</td><td width="33%" valign="top" align="left">read, write</td><td width="33%" valign="top" align="left">ug+rw</td></tr><tr><td width="33%" valign="top" align="left">user, group</td><td width="33%" valign="top" align="left">read, write</td><td width="33%" valign="top" align="left">ug-rw</td></tr><tr><td width="33%" valign="top" align="left">user</td><td width="33%" valign="top" align="left">read</td><td width="33%" valign="top" align="left">u+r</td></tr><tr><td width="33%" valign="top" align="left">user</td><td width="33%" valign="top" align="left">read</td><td width="33%" valign="top" align="left">u-r</td></tr></tbody></table></div><p>Of course, there is much more that could be said about permissions but for further details on the specifics of topics like sticky bits, shadow passwords and filesystem maintenance, consult the relevant <b class="COMMAND">man</b> page. Refer to <a href="http://www.aleph1.co.uk../../../armlinux/book/hlp.html">the section called <i>Help!</i></a> for advice on using <b class="COMMAND">man</b>.</p><p>The important thing to remember is that if you are having a problem with <i class="EMPHASIS">missing files</i> or some other mysterious error, it is very often due to incorrect permissions somewhere in the system. Always remember to check.</p></div><div class="SECT2"><h2 class="SECT2"><a name="ALTFILESYS">Alternative Filesystems</a></h2><p>ARMLinux can similarly make use of a range of filesystems in addition to its own Second Extended filesystem (ext2fs). </p><p>   Under Linux the user will however have to <i class="EMPHASIS">mount a device</i> before it can be accessed and used. This is done with the <b class="COMMAND">mount</b> command but you will initially have to edit the <tt class="FILENAME">/etc/fstab</tt> file as the root user in order to avail of this facility. This file is also used to specify which filesystems should be mounted automatically at boot time. To edit this file - which is just a text file - use <span class="APPLICATION">Vim</span> to open the file with the following command:</p><p><b class="COMMAND">vim /etc/fstab</b></p><p> If your file doesn't include a line like the following: </p><p class="LITERALLAYOUT">/dev/hda1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/adfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noauto,user&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;0</p><p>then you should add one in order to be able to read your RISC OS drive from ARMLinux. Note that if your RISC OS drive is RISC OS 4 with long filenames then this is not supported at the time of writing so you can skip this section. The format of this file is explained in <b class="COMMAND">man fstab</b>.Save and quit by depressing the <b class="KEYCAP">ESC</b> key, waiting for a beep and then typing <b class="COMMAND">:wq /etc/fstab</b>. Where this line is missing, type it in from scratch noting that there should be no spaces between <i class="EMPHASIS">noauto</i> any punctuation and <i class="EMPHASIS">user</i>. if you want this drive to be automatically mounted on boot then change the final 0 to a 1. You will then need to make a mount directory.</p><p><b class="COMMAND">mkdir /adfs</b> </p><p>Congratulations, you are now in a position to mount your RISC OS filesystem with the following command:</p><p><b class="COMMAND">mount /adfs</b> </p><p> You can now access your files from the <tt class="FILENAME">/adfs</tt> directory.</p></div><div class="SECT2"><h2 class="SECT2"><a name="PACKAGES">Debian Package Management</a></h2><p>In order to take full advantage of Debian, you need to learn a little about the package management system which underpins it. Debian packages everything in .DEB files. These packages are controlled by a program called <span class="ACRONYM">dpkg</span>, or from a friendlier front-end such as <span class="APPLICATION">dselect</span> or <span class="APPLICATION">apt</span>. The system is extremely powerful; every file on your system is known about by the system and it takes care of a great deal of complexity when installing, removing or upgrading software. It knows about the interdependencies between pieces of software and if you ask to install something it will also get the other things it needs. It knows which files are configuration files and will not overwrite them when upgrading a package. It can also upgrade a running system without breaking things and lets you find out what is on your system. To a large extent the package management system is what makes Debian special and once you understand it you will find it a marvellous facility.</p><p><span class="APPLICATION">dselect</span> is the interface that you will first use. It was designed when Debian had 500 rather than 5000 packages and suffers a bit because of this, but it is quite straightforward to use and a good introduction to the package system. Later you will just use <span class="APPLICATION">apt</span> to install new software. Once <span class="APPLICATION">apt</span> has been taught where to get software (usually off the CD and off the net) you can say things like <b class="COMMAND">apt-get install &lt;software&gt;</b> and it will go away and get it for you, then install it, install anything else necessary and configure them all, often without asking you any further questions apart from telling you which CD to insert or if the download size is OK.</p><p>It is important to understand however that if you want to install software that is not in the Debian archive then everything is not taken care of for you and you will have to understand what is going on and do some work yourself. For example, if obtaining a package from a distribution which is meant for x86-based <span class="ACRONYM">PC</span>s, you will have to compile it from source as the binary versions supplied will not work on an ARM-based machine. Such a procedure is outside this manual's scope but - assuming that you want to use a package which is on the ARMLinux <span class="ACRONYM">CD</span> or in the huge Debian archive - read on!</p><p><span class="ACRONYM">dpkg</span> can for example be used to install a package by using the <tt class="OPTION">i</tt> (or --install) switch.</p><p><b class="COMMAND">dpkg -i /cdrom/debian/dists/potato/main/binary-arm/utils/mc&lt;TAB&gt;</b> </p><p>Note that the &lt;TAB&gt; above means press the TAB key, not type in those letters. This uses the shell's <i class="EMPHASIS">filename expansion</i> facility to fill in the end of the filename. It's a marvellous facility. If it beeps then there is more than one possible answer - press &lt;TAB&gt; again to see the list. It even works on commands.</p><p>However, it is standard practice to use <span class="APPLICATION">apt</span> instead to save typing long pathnames, like this:</p><p><b class="COMMAND">apt-get install mc</b> </p><p>Here <span class="APPLICATION">apt</span> knows where to look for packages, finds <span class="APPLICATION">mc</span> and then uses <span class="APPLICATION">dpkg</span> to actually do the installation, but saves you worrying about the actual location of the package.</p><p> What you have just done is to use <span class="ACRONYM">dpkg</span> to install <span class="APPLICATION">Midnight Commander</span> (<span class="ACRONYM">mc</span>) - a visual shell which does not need X Windows - on your system. Conversely, you may choose to delete or uninstall a package which can be accomplished by using the <tt class="OPTION">-r</tt> (or --remove) switch. The following command consequently removes <span class="ACRONYM">mc</span>.</p><p><b class="COMMAND">dpkg -r mc</b> </p><p>Don't be too hasty however. <span class="ACRONYM">MC</span> is an excellent way of navigating the filesystem when used in conjunction with the shell. So why not learn a bit about it before using <span class="ACRONYM">dpkg</span>'s <tt class="OPTION">-r</tt> switch?</p><p>Congratulations, you've managed to mount your filesystem and have a look at some files. Before removing your <span class="ACRONYM">CD-ROM</span>, you will need to use the <b class="COMMAND">umount</b> command which can either be used to unmount the current filesystem or a specific directory. But please be careful with your typing and key in <tt class="USERINPUT"><b>umount</b></tt> rather than <tt class="USERINPUT"><b>unmount</b></tt>. If it tells you that the <tt class="COMPUTEROUTPUT">filesystem is busy</tt> then your current directory is probably in the mounted filesystem. You need to change directory elsewhere before you can <b class="COMMAND">umount</b>.</p><p><b class="COMMAND">umount /dev/cdrom</b> </p><p>or</p><p><b class="COMMAND">umount /cdrom</b></p><p>In order to find out about other filesystem types and the specifics of the <b class="COMMAND">mount</b> and <b class="COMMAND">umount</b> commands, you can take advantage of the range of commands and applications which are briefly described in <a href="http://www.aleph1.co.uk../../../armlinux/book/hlp.html">the section called <i>Help!</i></a>.</p></div>