Lab 7a Managing fielsystesm Mounting Unmounting

Aims

1. To explore the filesystems of existing machines

2. To understand the purpose of the setgid bit, and how to share files among groups in UNIX

3. To add a new filesystem to /etc/fstab, and to mount and unmount it

4. To mount and unmount removable media

Task 1: Gathering information on the host OS and your virtual machine

On the host operating system of a Linux workstation in the Faculty labs, determine and document the structure of the filesystem. Include all of the currently mounted filesystems. How many hard disks are in the machine? Do they appear to be IDE or SCSI disks? How many partitions are there on the disk(s)? Identify which partitions are primary, extended and logical partitions. Which are logical volumes? Where are home directories stored? Where is the /tmp directory stored?

Hints: Look at both /proc/partitions and the fstab file. You can also look in /dev/disk/by-uuid or use the /sbin/blkid command to figure out the mapping of UUIDs to partitions (blkid may require root privileges).

Repeat this process for your virtual machine OS. How many (virtual) hard disks? Can you tell from the device file names whether the disks are SATA, IDE or SCSI? How many partitions? This time use the fdisk –l command to print the partition table as well as looking at /proc/partitions and the fstab file. Which partitions are primary, extended and logical? Where are home directories stored? Where is the /tmp directory stored? This time you can also refer to the previous lab on disk partitioning for other ways to view disk partitions (as opposed to mounted filesystems). Because this requires root privileges, you couldn’t do it on the host OS.

Task 1 - Steps

Check or list all the partitions of the Linux system

# cat /proc/partitions

To print the partition table use the following command

#fdisk -l


Task 2: Using file permissions to support file sharing among users

In an earlier lab exercise, you should have created four users named Peter, Stewie, Brian and Lois, and assigned two of those users, Stewie and Brian, to a group called family. This task builds on that earlier work. Let us assume that Stewie and Brian have the groups stewie and brian as their primary groups respectively (the default case under CentOS, Fedora and Red Hat Linux), but both are also members of the family group. That is, the family group is a secondary group for Stewie and Brian. If this is not the case, you might like to adjust group memberships to comply with the above. This makes the task more difficult, but more interesting.

Now assume that members of the family group need to share files with each other. Make a directory called /share/family. Make it so that Stewie and Brian (members of the family group) can read and create files in this directory, but Peter (who is not a member of the family group) cannot. Make sure that in this directory, files created by Stewie can be read and edited by Brian and vice versa (but they should not be world readable).

To solve this problem, you will need to use three things:

• UNIX file permissions on the /share/family directory, including the SetGID bit (chmod command)

• Group ownership of the /share/family directory (chgrp command)

• The umask settings of Stewie and Brian, so that files are created group writable by default (umask command, e.g. in

their .bashrc file)


Task 2 - Steps

Let’s create a directory

# mkdri -p /share/family

//-p becused we do not have share permission//

# ll -d /share/family

Change the group owner of the family

#chgrp family /share/family/

//chgrp change to group command we are changing family dir to family existing group //

Next doble check the property for family directory

# ll -d /share/family/


Next block other users using the directory or changing access permission

# chmod 2770 /share/family/

//2 means we keep the group ID as we don’t want to change the group

//7 is read write and execute permission//

Task 3: Making /tmp a separate filesystem, and testing mounting and unmounting

In your virtual machine, change the /tmp directory from being part of the root filesystem to using a tmpfs filesystem. First, create an empty file in the /tmp directory (e.g. "touch /tmp/mytest"). Then make the necessary change to the

/etc/fstab file so that /tmp uses tmpfs, as follows:

tmpfs /tmp tmpfs defaults 0 0

Then mount the filesystem with ‘mount /tmp’. Use the mount command again (with no arguments) to show currently

mounted filesystems and verify that /tmp is now using tmpfs. Also verify that the file you created earlier

(/tmp/mytest) is not there any more in the tmpfs filesystem (where is it?).

After doing this, you might want to change /tmp back to the way it was before, so as not to degrade the performance of your virtual machine by using tmpfs (since your VM does not use very much memory in total).

Task 3 - Steps

Use the top command to see partitions

#top


Create a new file temp

# touch /tmp/test


Change the /etc/fstab file

#vim /etc/fstab

Add

tmfs /tmp tmpfs defaults 0 0

:wq

To test we can use reboot or mount command

# mount /tmp

Then mount again to check properties

# mount