This project assignment is designed to give you experience in
creating, formatting, mounting, and unmounting Linux
filesystems.
1
You will create a disk image file and
mount it.
The commands you will use (and which you should lookup in the
man pages) are dd, df, fsck,
losetup (LOopback SETUP),
mkfs, mount, umount,
tune2fs, fuser, lsof, and
the file /etc/fstab (also documented in the man pages).
Disk image files can be used to create bootable floppies and RAM disks. 2 An image of an entire CD (or of many CDs) can be stored on a hard disk. (This is how CD duplicators or juke-boxes work.)
Make sure you keep an accurate system journal of any and all changes you make to your system! You will need to turn this in, along with the answers to the questions asked below.
Answer the following questions and perform the following tasks:
myfs.img.
Image files are regular files that hold filesystems.
They must be carefully created and formatted.
To create a 10 MB filesystem you must start by
creating a 10 MB image file.
(Verify you have 10 MB of free disk space before
starting this!
If not use a smaller count of say 1000.)
Use the dd command for this:/dev/loop0 (or another loopback device)
which will be associated with the image file:/dev/loop0 as an
unformatted disk.
Use the mkfs command to format it (and thus the image file)
as an ext4 filesystem.
(The type for a CD would be iso for Linux and
HSFS for Solaris.
Such image files can also be created and mounted, usually read-only
though.)
This command is actually a common front-end for a family of related
commands, one for each filesystem type.
What is the actual command ultimately
invoked to create an ext4 filesystem?
(Use the man pages to determine this.)
mkfs -t ext4 /dev/loop0 10000
mkdir /mnt/myfs
mount -t ext4 /dev/loop0 /mnt/myfs
df command.
How much free space shows for your
filesystem?
Why is this less than 10 MB?cd /mnt/myfs.
Run the command ls.
What files and/or directories were created
automatically?
What is their purpose? vi (or some other method):
cd /mnt/myfs
vi foo # add a few lines to the file
Now run the df command again.
Is the output any different?
If so why?
Finally, run the command
.
What is the inode number of your new
file (ls -li
)?
foo
umount /dev/loop0
What happened?
You cannot unmount a filesystem if it is in use.
If the current working directory of any process (such as your
shell) is any directory in that filesystem, or if any process
has any file open from that filesystem (such as vi)
then the device will be considered busy.
Use the commands fuser and lsof to
see what files are in use and what processes are using them.
(See the man pages for details on these commands.)
Run the commands
and fuser -cuv /mnt/myfs
.
What was the output?
What is the meaning of the options used?
lsof -Rw +D /mnt/myfs
cd
umount /dev/loop0
What happened this time?
fsck command on your filesystem.
The fsck command is actually a common front-end
for a family of related
commands, one for each type of file system.
What is the actual command that is run?
(Use the man pages to determine this.)
fsck -CVfp /dev/loop0
What is the purpose (or meaning) of each
of these options used with fsck?fsck.
There are many ways to corrupt the image, such as using a tool
such as hexedit on the image file.
But it is hard to know exactly where to corrupt the image, in
a way that matters and that can be repaired.
Instead you will use a tool
that
can be used to examine and exit image files.
You will change the link count field of your new file from
debugfs1
to 2
.
You will need to know your file's inode number in order to
run this command.
In the command line below, the inode number for the file
foo was 13
.
If you inode number is different, use that instead.
Once you have unmounted the filesystem (the previous step),
run this command (including the quotes and the angle-brackets):
debugfs -wR 'sif <13> links_count 2' /dev/loop0
(This command is part of the
package.)
Now re-run the same e2fsprogsfsck command as before.
What was the output this time?
tune2fs command is used to examine and
optionally modify the superblock of ext[234]
filesystems.
Use the man page to determine how to use this command to list
the default values used in your filesystem.
What are the default values for
ext4 filesystems for:
fsck
check is forced)fsck check is forced)
losetup -d /dev/loop0
/etc/fstab file.
Each line of this file contains what to mount,
the mount point (where to mount it),
the mount options to use, and other information.
To automatically mount your filesystem at boot time
add this entry to the /etc/fstab file:
/tmp/myfs.img /mnt/myfs ext4 owner,loop 0 0
What is the meaning of the fields and
options used?
(Read the man page for fstab to find out.)
What is the name of the similar file
for Solaris?
Are the fields the same in the Solaris file as for the Linux
fstab file?
If not what are the differences?fstab
and verify they work:
mount /mnt/myfs
Note that even without the /etc/fstab line,
the command
mount -t ext4 -o loop /tmp/myfs.img /mnt/myfs
will work.
In this case mount will automatically associate
/tmp/myfs.img with an unused loop device, and
umount will automatically break the connection.
(Earlier we merely took advantage of the fact that /dev/loop0
was already associated with /tmp/myfs.img, so different
mount options were used.)/tmp will eventually be automatically deleted,
either during a reboot or from a cron job.
What will eventually happen if you don't
remove the line from /etc/fstab?
file command can be helpful to determine
the type of these image files, so you can use the right tools
to examine them.)
The answers and journal entries from the above list describing the steps you have taken to create and use a filesystem.
You can submit your project as email to . Please see your syllabus for more information about submitting projects.
ramfs,
ext4 tools, and loop devices) are different
or not available on most Unix systems.
For Solaris, see the lofiadm command to work with
the loop devices, /dev/lofi/num,
where num is 1, 2,
3, ...
Back
man initrd).
This is because the virtual memory system is so efficient.
To create a real ram disk is easy provided you kernel is
configured to include the ramfs filesystem.
Then:
mkdir /mnt/ramdisk
mount -t ramfs none /mnt/ramdisk
That's it!
You can now create files there.
All files will be lost when the ram disk is unmounted.
Back