Linux - Unit 5
Linux - Unit 5
Standard
Create Partitions and Filesystems
The options that are available for use with fstab file:
atime / noatime / relatime The Unix stat structure records when files are last accessed
(atime), modified (mtime), and created (ctime). One result is that atime is written every time a
file is read, which has been heavily criticized for causing performance degradation and
increased wear. However, atime is used by some applications and desired by some users, and
thus is configurable as atime (update on access), noatime (do not update), or (in Linux) relatime
(update atime if older than mtime). Through Linux 2.6.29, atime was the default; as of 2.6.30 (9
June 2009), relatime is the default,
auto / noauto - With the auto option, the device will be mounted automatically at bootup
or when the mount -a command is issued. auto is the default option. If you don't want the device
to be mounted automatically, use the noauto option in /etc/fstab. With noauto, the device can be
only mounted explicitly.
dev / nodev - Interpret/do not interpret block special devices on the filesystem.
exec / noexec - exec lets you execute binaries that are on that partition, whereas noexec
doesn't let you do that. noexec might be useful for a partition that contains no binaries, like /var,
or contains binaries you don't want to execute on your system, or that can't even be executed
on your system. Last might be the case of a Windows partition.
ro - Mount read-only.
rw - Mount the filesystem read-write. Again, using this option might alleviate confusion
on the part of new Linux users who are frustrated because they can't write to their floppies,
Windows partitions, or other media,
sync / async -How the input and output to the filesystem should be done. sync means it's
done synchronously. If you look at the example fstab, you'll notice that this is the option used
with the floppy. In plain English, this means that when you, for example, copy a file to the floppy,
the changes are physically written to the floppy at the same time you issue the copy command.
suid / nosuid - Permit/Block the operation of suid, and sgid bits.
user / users / nouser - user permits any user to mount the filesystem. This automatically
implies noexec, nosuid, nodev unless overridden. If nouser is specified, only root can mount the
filesystem. If users is specified, every user in group users will be able to unmount the volume.
owner - Permit the owner of device to mount,
defaults - Use default settings. Default settings are defined per file system at the file
system level. For ext3 file systems these can be set with the tune2fs command. The normal
default for Ext3 file systems is equivalent to rw,suid,dev,exec,auto,nouser,async(no acl
support). Modern Red Hat based systems set acl support as default on the root file system but
not on user created Ext3 file systems. Some file systems such as XFS enable acls by default.
Default file system mount attributes can be over ridden in /etc/fstab.
Mount maintains the list of mounted filesystems in /etc/mtab. Typing mount with no
options will show all filesystems currently mounted. The output is similar to /etc/mtab.
The kernel also keeps track of mounted filesystems in /proc/mounts.
User Mountable Configurable Systems
On a running system the /etc/fstab file also acts as a shortcut for assigning a resource
to a specific directory. For example:
The mount utility reads fstab and deduces where to mount the resource. Notice that
some of the devices are accessed using a label. Labels are assigned to devices with
the tune2fs tool:
Mount can take most of the fstab options that have been listed above. This allows a
user to mount a filesystem read-only or with noexec for example. Beside mounting
filesystems that have been defined in the /etc/fstab file, mount can also be used to
mount new devices not defined in fstab. If an external SATA drive is plugged into the
machine for example, and given the device node of /dev/sdc, its first partition can be
mounted as
This will make the 1st partition of the device available under /mnt directory
or
Conventionally, mount points under /media are used for removable devices such as
CDs or USB storage devices.
Quota Setup
Disk quotas allow system administrators to allocate the maximum amount of disk space
a user or group's files and data may take up on a machine. This functionality can be
crucial on a Linux machine that is used as a file server to prevent the hard disks from
filling up and causing system instability.
The quota tools allow administrators to set up quotas without having to reboot. Here are
the steps.
Edit /etc/fstab and add usrquota to the options
Remount the partition:
Here a soft/hard limit must be set for both the number of blocks and inodes available for
each user.
The system will allow the user to exceed the soft limit during a certain grace period.
After the grace period has expired the soft limit will be enforced as a hard limit.
Start enforcing quotas:
Uses can query the quota status with quota. The system administrator can generate
reports with repquota or quotastats.
The extract above is from running the ls -l command on the /etc directory. When a file is
created it is owned by the user who created the file and assigned to the default group of
the owner.
Permissions apply to the user, the group and to others. An item has a set of 3 grouped
permissions for each of these categories.
How to read a 755 or -rwxr-x-r-x permission
On systems where users belong to separate groups, the umask can have a value of
002. For systems which place all users in the users group, the umask is likely to be 022
so that files do not have group write access by default.
NOTE:
A useful option for chmod, chown and chgrp is -R which recursively changes ownership
and permissions through all files and directories indicated.
Special Permissions
SUID Permissions
An executable can be assigned a special permission which will always make it run as
the owner of this file. This permission is called SUID meaning 'set user ID'. It has a
symbolic value s or a numerical value 4000.
Administrative tools may have the SUID bit set in order to allow non-root users to
change system files. For example the passwd command can be run by any user and will
interactively change his or her current password. This password will be saved
to /etc/shadow. However this file belongs to user root with typical permissions of 600.
This problem has been solved by setting the SUID bit on passwd hence forcing it to run
as user root with the correct permissions to modify /etc/shadow.
The SUID on passwd
NOTE:
The SUID bit is shown in symbolic form in the command above. It is possible to get
more information about a file using stat as well as seeing the octal representation of the
permissions as follows:
The next examples are dangerous. Why?
SGID permissions
The SGID is a permission similar to SUID that is set for group members. The symbolic
value is s and the octal value of 2000.
Setting SGID on a directory changes the group ownership used for files subsequently
created in that directory to the directory's group ownership. No need to use newgrp to
change the effective
group of the process prior to file creation.
Examples:
The sticky bit
The sticky bit permission with value 1000 has the following effect:
Applied to a directory it prevents users from deleting files unless they are the owner
(ideal for directories shared by a group, or for /tmp
Applied to a file this used to cause the file or executable to be loaded into memory and
caused later access or execution to be faster. The symbolic value for an executable file is t . It
was
supported in some versions of Unix but is not used in Linux.
Examples:
Symbolic links
A soft link to a file or a directory is a special file type that simply contains the name of
the file that it "points to".
Soft links can be created across filesystems. By running ls -l we can identify whether a
directory entry is a soft link or just an ordinary file from the output. A symbolic link is
shown as follows when we run the ls -l command
mytext.txt -> mytext.sym. Notice that the reference count is 1 for both files.
-rw------- 1 root root 223 Sep 29 09:10 mytext.txt
lrwxrwxrwx 1 root root 9 Sep 29 09:10 mytext.sym -> mytext.txt
To find all symbolic links to a file you can use the find command for example
find / -lname mytext.txt
will find all symbolic links to the file mytext.txt.
Hard Links
A hard link is an additional name for the same inode and as such the reference count of
the file increases by one for every new hard link.
In the listing notice that the reference count is 2 and that both files have the same size.
In fact they are identical.
-rw------- 2 mark mark 223 Sep 26 09:06 mytextfile.txt
-rw------- 2 mark mark 223 Sep 26 09:06 mytextfile.link
Hard links can only be created within the same filesystem. Using ls, a hard link can be
identified by the reference count shown in the output, as in the above example. Another
way of finding files with hard links is to obtain the file's inode number and then run the
find command with the inode number as a parameter. To find the inode of a file run the
command:
This will output the inode number of the file, next run the find command as follows:
Used terms, files and utilities
ln