[SOLVED] COP4600 - Ex6

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (3 votes)

 IO Device Files

 

Structure

The exercise is broken into these main parts:

 

  • Create a storage device image file.
  • Connect the file to a loopback device, format it, and mount a filesystem on the device.
  • Write data to the virtual device by creating files on it after mounting
  • Unmount the virtual device and disconnect the loopback device 5) Verify the data has been written to the image file

 

Creating the Image

Follow these steps to completed the exercise:

 

  1. Create a img file, filled with zeroes, of size one megabyte (1MiB) using dd:

 

$ dd if=<input file> of=<output file> bs=<block size> count=<how many> 

 

The dd command’s input can come from any source, a regular file or a special (device) file. A special file, /dev/zero, will have an infinite number of zeroes available for reading. The output data’s size is defined by the block-size and block-count – you could create a 1KiB file by using a size of 512 and a count of 2, for example.

 

  1. Create a loopback device connected to the image file via losetup, format the image in ext4 format using mkfs, and then mount the loopback device on /mnt/ex6 via mount. Take a screenshot of the commands you used in this step.
    1. You will need to use sudo for the losetup

 

  1. In this step you will be writing data to the virtual device by creating files on it after mounting.

In the mounted directory (/mnt/ex6), create two text files:

  1. one empty,
  2. and one containing a message.

Display the contents of each file using the cat command and take a screenshot.

 

  1. Unmount the filesystem (umount) and disconnect the loopback device (losetup).

 

  1. Lastly, you need to verify if the data has been written to the image file.

Install the hexedit program (sudo apt-get install hexedit) and use it to examine the image file – you should be able to find your filenames and text. Take a screenshot.

 

Just for fun: try the strings command and see what happens!

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.