diff --git a/Task_4-6/Linux-Cl-Praktikum_04_en.html b/Task_4-6/Linux-Cl-Praktikum_04_en.html new file mode 100644 index 0000000..8155d79 --- /dev/null +++ b/Task_4-6/Linux-Cl-Praktikum_04_en.html @@ -0,0 +1,1259 @@ + + + + + + + +Linux Praktikumstermin 2025_04: User Handling / Processes + + + + + + + +
+
+General Notes with respect to this Lab Exercise +
+
+FAQ concerning Lab Work of Lehrgebiet Informationstechnische Systeme (ITS) +
+

As the technical setup (using VirtualBox Virtual Machines) is similar +in several of Prof. Classen’s lectures / labs, we provide shared FAQ answers +in a separate, shared Ilias course at +Support für die WF Praktika Prof. Claßen. +Feel free to become a member of that Ilias course.

+
+
+

A +Wiki +there provides FAQ answers +related to the technical setup of the Prof. Classen labs. +New FAQ answers will be added on demand. +If you have problems creating and starting the VM, +first check the information in our FAQ. +In particular, the points on the topic of activating hardware virtualization on Windows systems.

+
+
+

Specific questions specifically related +to one module' lab only will however not be answered there, but in the Ilias of the specific module +instead. Only questions that are valid for multiple / all of the labs will be handled +via the shared Support Wiki.

+
+ +
+
+On your own computer: VirtualBox Installation +
+

VirtualBox Version 7.x is installed on the terminal computers.

+
+
+

If you are working on your own computer, +so you should also install and use the latest version of Virtualbox 7.x.

+
+ +
+
+Operating the VirtualBox VM +
+

With VirtualBox, the mouse and keyboard may be "caught" in the VM, +as soon as you click in the console window. +You can then "release" it by pressing the right Ctrl key.

+
+ +
+
+Persistence of data and changes +
+

The changes in the virtual machine are persistent +even if you have to shut down or reboot the virtual machine during the lab exercises.

+
+ +
+
+Interrupting the Lab Work: Shut down the VM, do not pause it +
+

If you need to interrupt your lab work, +please do not pause the VM, +instead, shut down the VM. +Otherwise, when paused, the VM will not have a +working network connection when you continue your work.

+
+ +
+
+Superuser Permissions +
+

Many of the commands and file content changes in the following exercises +require superuser (root) permissions, because they impact general system settings. In many cases, this is explicitly mentioned in the explanation of the respective exercise. +We do however expect you to understand the concept, +so therefore there might be cases where you are expected to recognize and handle this yourself. +As a general hint: should you get error messages like command not found or Permission denied +when issueing a command, this might be an indication +that the respective command needs to be executed as +root superuser.

+
+ +
+
+ +
+
+ Download and Setup of the Virtual Machine (VM) Users_Processes_VM +
+
+On the FH Aachen PCs: +
+
+

Start VirtualBox.

+
+
+

Importing the appliance for the ITS-VM ("ITS" == "Lehrgebiet Informationstechnische Systeme, Prof. Claßen"):

+
+
+

Open the windows command shell cmd.exe by clicking on the menu in the bottom left corner, then "blindly" type in cmd, followed +by a left click onto cmd.exe. +Enter the following command into the shell:

+
+
+
+
1
net use S: \\ad.fh-aachen.de\files\FB05\StudiShare
+
+
+
+
+

You should now see a new drive S: in the explorer.

+
+
+

=== Importing the appliance for the VM) Users_Processes_VM

+
+
+

In VirtualBox menu file : +import appliance, select ITS_Client_debian12_AMD64_V02.ova in +S:\Classen\VM_OVAs\ , +click Next, +change name setting to Users_Processes_VM.

+
+
+

On FH terminal room computers: +change virtual disk image to +D:\VMs\Users_Processes_VM.vmdk.

+
+
+ + + + + +
+ + +
Assign a new MAC address
+Important (on all computers): +Make sure to set the checkbox +Assign new MAC addresses for all network cards, +alternatively go to MAC Address Policy +and set Include all network adapter MAC addresses. +
+
+
+

Finally click on Import.

+
+
+
+
+On your private computer: +
+
+

Download ITS_Client_debian12_AMD64_V02.ova from +https://fh-aachen.sciebo.de/s/voHfcjRsXAfYbfJ

+
+
+

In VirtualBox menu file : +import appliance, select ITS_Client_debian12_AMD64_V02.ova +from your local download folder, +click Next, +change name setting to Users_Processes_VM.

+
+
+ + + + + +
+ + +
Assign a new MAC address
+Important (on all computers): +Make sure to set the checkbox +Assign new MAC addresses for all network cards, +alternatively go to MAC Address Policy +and set Include all network adapter MAC addresses. +
+
+
+

Finally click on Import.

+
+
+
+
+Starting the VM +
+

Start the VM.

+
+
+

Should you get an error message when starting the VM regarding +VirtualBox Host-Only Ethernet Adapter is not a Host-Only Network +(or similar), the name of the host-only network in your VirtualBox installation differs from +the name expected by the VM definition. +For the VM refusing to start, click on Configure (upper-left of the +VirtualBox window) and a settings window will open for that VM. +Click on OK without changing any VM settings. +This will nevertheless update the VM settings and correct the problem. +Start the VM again.

+
+ +
+
+Account Data for the VM +
+

The user accounts of the VM are:

+
+
+
    +
  • +

    User: itsadmin, Password: itsadmin

    +
  • +
  • +

    Administrator-User: root, Password: itsadmin

    +
  • +
+
+ +
+
+ +
+
+Result logging +
+
+

To show that you have successfully finished this lab, please upload a log file to ILIAS. The log file +will contain all commands that you typed in during your session and all system outputs.

+
+
+

It is not a problem if there are commands in the logfile that did not work on first try or were typed in wrong, +we just want to see that at some point all the required commands were used correctly.

+
+
+

Open a terminal in the virtual +machine and start the logging by using the script command +(option -a means: append to file in case the file is non-empty +when the logging to file is started):

+
+
+
+
1
script -a Linux-praktikum-04.log
+
+
+
+
+

The following output should appear:

+
+
+
+
1
Script started, file is Linux-praktikum-04.log
+
+
+
+
+

From now on, please only use the console in which the logger is running, so that everything gets logged correctly!

+
+
+

If you want to interrupt the lab and shut down the virtual machine, e.g. to take a break, or if you get interrupted somehow, +you have to restart the logging when you continue. +Choose a new / different file name. +Finally, use a text editor to merge the resulting log files into a single file in the correct order.

+
+
+

After completing the lab, upload the complete result files to the Ilias course.

+
+
+ +
+
+User Management under Linux +
+
+

Log into the VM:

+
+
+

User: itsadmin, password: itsadmin

+
+
+

Open a terminal window with a command line session, e.g. via the menu at the bottom left, menu item Terminal.

+
+
+user identity +
+

Enter the command whoami to determine the user identity under which you are currently working.

+
+
+

Enter the command id in order to determine the user identity under which you are currently working in another way.

+
+
+

Compare the output of the two commands. Note that the id command also provides you with the numeric user ID of the user.

+
+
+

You do not need to record the results of actions such as "…​ compare …​" or "…​ analyze …​" in any form, i.e. you do not have to "provide written evidence" that you also carried out these analyzes …​

+
+
+

Change to the identity of the root user by entering

+
+
+
+
1
su - root
+
+
+
+
+

Enter the password itsadmin of the` root` user.

+
+
+

Use the whoami command to determine whether / that the change of user identity was successful.

+
+
+

Enter the exit command to end the session as user` root`. +You return to the session as the original user. Check this out.

+
+ +
+
+user switch is via command line session +
+

Open a second terminal window with a second command line session, e.g. via the File menu,` New Tab` entry.

+
+
+

Give the command there

+
+
+
+
1
su - root
+
+
+
+
+

and authenticate as root. Then enter id to check your user identity as` root` there.

+
+
+

By selecting the previous tab, switch to the first command line session that is still running and enter the id command there. Observe that the user change did not take place in the first session. This means that you are currently working under different user identities in the two command line sessions.

+
+
+

Use the second tab to switch back to the second command line session and enter the command exit there. This will switch you back to the identity of the itsadmin in this session; check this out. You are now working under the same user identity again in both sessions.

+
+
+

End the second session by entering the command exit there.

+
+ +
+
+sudo +
+

In the now only command line session, check under which user identity you are currently working and make sure that it is not the identity of the root user.

+
+
+

As a non-root user, try to update the list of installable software packages using the following command:

+
+
+
+
1
apt-get update
+
+
+
+
+

Notice that you get permission denied error messages. The reason for this is that the package lists are classified as system configuration files and can therefore only be updated by the root user (as administrator user).

+
+
+

The sudo software is already installed on the lab VM. It is also configured in such a way that the itsadmin user can use` sudo` to execute any command under any user identity (i.e. also under the identity of the root user) without having to authenticate by entering a password.

+
+
+

Enter the whoami command again and then use the` sudo --user = root …​ command to execute the above command to update the package lists under the root` identity.

+
+
+

Then enter whoami again to determine that you are back in the original user identity after executing the` sudo` command, i.e. that the user change with sudo only takes place for the specified command.

+
+
+

If the sudo command does not specify a target user identity via` --user = …​ , root` is assumed as the target user. So enter the command again, but this time without specifying the target user:

+
+
+
+
1
sudo apt-get update
+
+
+
+
+

Question (please answer this question yourself; answer does not have to be submitted): +Why do the following two commands produce different outputs?

+
+
+
+
1
+2
whoami
+sudo whoami
+
+
+
+ +
+
+useradd +
+

Create a new user dummy1 using the following command:

+
+
+
+
1
sudo useradd --create-home dummy1
+
+
+
+
+

Since creating a new user in the system is a system administration task, it can only be done by the root user. Therefore the useradd command must be executed under the identity of the` root` user, or the sudo command is used to execute exactly this command under the identity of the` root` user.

+
+ +
+
+Set password +
+

Set the password dummy1pw for the new user` dummy1` using the command …​

+
+
+
+
1
sudo passwd dummy1
+
+
+
+
+

... and by entering the new password twice.

+
+
+

The new user is now “ready to use”. Change to his user identity using the command …​

+
+
+
+
1
su  dummy1
+
+
+
+
+

... and entering his newly set password. +Check that you are in fact now working under the new user’s identity.

+
+
+

Use the id command to find out the user ID of the new user. Make a note of this user ID.

+
+
+

Then create a new text file file1.txt with any content in the home directory` / home / dummy1` of this new user (you are probably located there anyway). +Let yourself be …​

+
+
+
+
1
ls -l /home/dummy1
+
+
+
+
+

... output the directory contents and make sure that the files there belong to user dummy1.

+
+
+
+
1
+2
+3
+4
su  root
+# ... dann das Passwort “itsadmin” des root Benutzers eingeben
+sed -i "s/dummy1/willi/g" /etc/passwd
+exit  # ... wechselt zurück zum Benutzer dummy1 / willi
+
+
+
+ +
+
+Renaming the new user +
+

Use the following commands to change the user name in the central file / etc / passwd, in which the user IDs and user names are stored:

+
+
+

Let yourself be again by means of …​

+
+
+
+
1
ls -l /home/dummy1
+
+
+
+
+

... output the directory contents and make sure that the files there now belong to the user willi. +Only the user ID of the file owner was saved and this has not changed.

+
+
+

Also check under which user identity you are now working.

+
+
+

Note that the directory name of the home directory /home/dummy1 has not changed as a result of the renaming.

+
+
+

Undo the renaming (is important, otherwise deleting the user will not work properly because of the inconsistencies):

+
+
+
+
1
+2
+3
+4
su  root
+# ... dann das Passwort “itsadmin” des `root` Benutzers eingeben
+sed -i "s/willi/dummy1/ g" /etc/passwd
+exit  # ... wechselt zurück zum Benutzer dummy1 / willi
+
+
+
+
+

Exit the new command line after these commands with exit. The new tab closes with it.

+
+
+

Check that you are working under the original user identity dummy1 in the first tab.

+
+
+

Leave the command line session under the new user identity using the exit command.

+
+
+

Check that you are working under the original user identity itsadmin again.

+
+ +
+
+Delete the new user +
+

Delete the new user by entering the command …​

+
+
+
+
1
sudo deluser --remove-home --quiet dummy1
+
+
+
+ +
+
+ +
+
+Processes and Signaling +
+
+

Use ps to display the processes of the current user that are connected to a terminal (input / output, i.e. keyboard and screen).

+
+
+

In a Bash command line, the variable $$ stores the process ID of this command line. +So use echo $$ to output the value of this variable and compare the process ID: s.

+
+
+

The pgrep command searches for all processes with a certain name and outputs their process ID: s. +So use pgrep bash to search for the process ID: s of all running command lines.

+
+
+

Open a second tab in the terminal and use pgrep bash to display the process ID: s of all Bash command lines. +Close the second tab with exit and enter the command` pgrep bash` one last time.

+
+
+

Display the list of all processes using ps aux. +Notice that there are now many more processes from this user listed. +Analyze under which user identities processes were started in the system.

+
+
+

Processes are arranged hierarchically in Bash: every process except for the init process has a parent process. +Use pstree to display the hierarchical structure of all processes.

+
+
+ + + + + +
+ + +If pstree is not installed: sudo apt install psmisc +
+
+
+

Start an interactive Python interpreter with the command python3. +Open a second tab in the terminal and determine the process ID of this Python process there. +Send a signal to the process to terminate it (check that the process is terminated). +Then close the second tab again using exit.

+
+
+Signal Processing, a bash script +
+

Write a bash script which first outputs the current date and time in an endless loop (command date without parameters) and then always sleeps for 60 seconds (` sleep`).

+
+
+

Whenever Ctrl-C is pressed, the program should display` Thanks for pressing Ctrl-C` and exit. +Other signals should not be intercepted by the program.

+
+ +
+
+signal processing, several bash scripts +
+

Create two bash scripts child_one.sh and` child_two.sh`, which both execute a sleep 5 in an endless loop, +i.e. "sleep" again and again for 5 seconds at a time. +Furthermore, these scripts should have a signal handler that handles the TERM signal and then terminates the process with` exit`. Make both scripts executable.

+
+
+

Create another bash script parent.sh, which also executes a` sleep 5` in an endless loop and starts the two child scripts in the background before the loop is executed. +The parent script should also have a signal handler that handles the TERM signal and terminates the process with` exit`. Make this script executable too.

+
+
+

Start the parent script and check (in another command line) that all three scripts are running. Send the TERM signal to the parent script. It should end.

+
+
+

Check whether the child scripts are still running or not. If so, terminate the child scripts by sending the TERM signal to each of the child scripts as well.

+
+
+

Edit the parent script: The child scripts should no longer be started in the background, but in the foreground. Start the parent script and check (in another command line) which of the scripts are running.

+
+
+

Send the TERM signal to the parent script. What is happening? (please answer this question yourself; answer does not have to be submitted)

+
+
+

Send the TERM signal to all running child scripts (how many are there? ⇒ Please answer this question yourself; answer does not have to be submitted). +What happens to the child script and the parent script?

+
+ +
+
+ +
+
+PID namespaces using unshare +
+
+

Start a Python interpreter that does nothing but execute an infinite loop:

+
+
+
+
1
python3 -c "while True: import time ; time.sleep(2)" &
+
+
+
+
+

With the following command you can (still) see the running process of the Python interpreter:

+
+
+
+
1
ps aux | grep python3
+
+
+
+
+

Start a Bash command line (shell) again in a PID namespace:

+
+
+
+
1
sudo unshare --pid --mount-proc --fork /bin/bash
+
+
+
+
+

Now look whether the python3 process is still visible in this shell:

+
+
+
+
1
ps aux
+
+
+
+
+

In this PID namespace only the bash shell, which was "encapsulated" in the PID namespace, should now be visible, plus the ps aux command that was just executed while the" process list "output was being generated. The python3 process, however, is no longer visible.

+
+
+

Also check that this shell "thinks" that it has Process-ID 1. Under Unix-based systems, this is a special process ID, namely the ID of the first process (init) on a Unix computer, which is then responsible for starting all further processes on the computer. Our shell “thinks” that it is “alone on the computer” and that it is the “first process started” in its environment.

+
+
+

Exit the command line encapsulated in the PID namespace. This also ends the PID namespace itself:

+
+
+
+
1
exit
+
+
+
+
+

Quit the running Python interpreter:

+
+
+
+
1
pkill python3
+
+
+
+
+ +
+
+Upload of console log file and completion of this lab +
+
+

When you have finalized your lab work, you need to end the logging by entering exit into your console. The following output should appear:

+
+
+
+
1
Script done, file is Linux-praktikum-04.log
+
+
+
+
+

Start a webbrowser inside the virtual machine and upload the log file to ILIAS, using this web browser.

+
+
+

Shut down the VM, remove the VM completely (delete all files) and end your session.

+
+
+ +
+
+ + + \ No newline at end of file diff --git a/Task_4-6/Linux-Cl-Praktikum_05_en.html b/Task_4-6/Linux-Cl-Praktikum_05_en.html new file mode 100644 index 0000000..4565f4b --- /dev/null +++ b/Task_4-6/Linux-Cl-Praktikum_05_en.html @@ -0,0 +1,1295 @@ + + + + + + + +Linux Praktikumstermin 2025_05: Processes / Files + + + + + + + +
+
+General Notes with respect to this Lab Exercise +
+
+FAQ concerning Lab Work of Lehrgebiet Informationstechnische Systeme (ITS) +
+

As the technical setup (using VirtualBox Virtual Machines) is similar +in several of Prof. Classen’s lectures / labs, we provide shared FAQ answers +in a separate, shared Ilias course at +Support für die WF Praktika Prof. Claßen. +Feel free to become a member of that Ilias course.

+
+
+

A +Wiki +there provides FAQ answers +related to the technical setup of the Prof. Classen labs. +New FAQ answers will be added on demand. +If you have problems creating and starting the VM, +first check the information in our FAQ. +In particular, the points on the topic of activating hardware virtualization on Windows systems.

+
+
+

Specific questions specifically related +to one module' lab only will however not be answered there, but in the Ilias of the specific module +instead. Only questions that are valid for multiple / all of the labs will be handled +via the shared Support Wiki.

+
+ +
+
+On your own computer: VirtualBox Installation +
+

VirtualBox Version 7.x is installed on the terminal computers.

+
+
+

If you are working on your own computer, +so you should also install and use the latest version of Virtualbox 7.x.

+
+ +
+
+Operating the VirtualBox VM +
+

With VirtualBox, the mouse and keyboard may be "caught" in the VM, +as soon as you click in the console window. +You can then "release" it by pressing the right Ctrl key.

+
+ +
+
+Persistence of data and changes +
+

The changes in the virtual machine are persistent +even if you have to shut down or reboot the virtual machine during the lab exercises.

+
+ +
+
+Interrupting the Lab Work: Shut down the VM, do not pause it +
+

If you need to interrupt your lab work, +please do not pause the VM, +instead, shut down the VM. +Otherwise, when paused, the VM will not have a +working network connection when you continue your work.

+
+ +
+
+Superuser Permissions +
+

Many of the commands and file content changes in the following exercises +require superuser (root) permissions, because they impact general system settings. In many cases, this is explicitly mentioned in the explanation of the respective exercise. +We do however expect you to understand the concept, +so therefore there might be cases where you are expected to recognize and handle this yourself. +As a general hint: should you get error messages like command not found or Permission denied +when issueing a command, this might be an indication +that the respective command needs to be executed as +root superuser.

+
+ +
+
+ +
+
+ Download and Setup of the Virtual Machine (VM) Processes_Files_VM +
+
+On the FH Aachen PCs: +
+
+

Start VirtualBox.

+
+
+

Importing the appliance for the ITS-VM ("ITS" == "Lehrgebiet Informationstechnische Systeme, Prof. Claßen"):

+
+
+

Open the windows command shell cmd.exe by clicking on the menu in the bottom left corner, then "blindly" type in cmd, followed +by a left click onto cmd.exe. +Enter the following command into the shell:

+
+
+
+
1
net use S: \\ad.fh-aachen.de\files\FB05\StudiShare
+
+
+
+
+

You should now see a new drive S: in the explorer.

+
+
+

=== Importing the appliance for the VM) Processes_Files_VM

+
+
+

In VirtualBox menu file : +import appliance, select ITS_Client_debian12_AMD64_V02.ova in +S:\Classen\VM_OVAs\ , +click Next, +change name setting to Processes_Files_VM.

+
+
+

On FH terminal room computers: +change virtual disk image to +D:\VMs\Processes_Files_VM.vmdk.

+
+
+ + + + + +
+ + +
Assign a new MAC address
+Important (on all computers): +Make sure to set the checkbox +Assign new MAC addresses for all network cards, +alternatively go to MAC Address Policy +and set Include all network adapter MAC addresses. +
+
+
+

Finally click on Import.

+
+
+
+
+On your private computer: +
+
+

Download ITS_Client_debian12_AMD64_V02.ova from +https://fh-aachen.sciebo.de/s/voHfcjRsXAfYbfJ

+
+
+

In VirtualBox menu file : +import appliance, select ITS_Client_debian12_AMD64_V02.ova +from your local download folder, +click Next, +change name setting to Processes_Files_VM.

+
+
+ + + + + +
+ + +
Assign a new MAC address
+Important (on all computers): +Make sure to set the checkbox +Assign new MAC addresses for all network cards, +alternatively go to MAC Address Policy +and set Include all network adapter MAC addresses. +
+
+
+

Finally click on Import.

+
+
+
+
+Starting the VM +
+

Start the VM.

+
+
+

Should you get an error message when starting the VM regarding +VirtualBox Host-Only Ethernet Adapter is not a Host-Only Network +(or similar), the name of the host-only network in your VirtualBox installation differs from +the name expected by the VM definition. +For the VM refusing to start, click on Configure (upper-left of the +VirtualBox window) and a settings window will open for that VM. +Click on OK without changing any VM settings. +This will nevertheless update the VM settings and correct the problem. +Start the VM again.

+
+ +
+
+Account Data for the VM +
+

The user accounts of the VM are:

+
+
+
    +
  • +

    User: itsadmin, Password: itsadmin

    +
  • +
  • +

    Administrator-User: root, Password: itsadmin

    +
  • +
+
+ +
+
+ +
+
+Result logging +
+
+

To show that you have successfully finished this lab, please upload a log file to ILIAS. The log file +will contain all commands that you typed in during your session and all system outputs.

+
+
+

It is not a problem if there are commands in the logfile that did not work on first try or were typed in wrong, +we just want to see that at some point all the required commands were used correctly.

+
+
+

Open a terminal in the virtual +machine and start the logging by using the script command +(option -a means: append to file in case the file is non-empty +when the logging to file is started):

+
+
+
+
1
script -a Linux-praktikum-05.log
+
+
+
+
+

The following output should appear:

+
+
+
+
1
Script started, file is Linux-praktikum-05.log
+
+
+
+
+

From now on, please only use the console in which the logger is running, so that everything gets logged correctly!

+
+
+

If you want to interrupt the lab and shut down the virtual machine, e.g. to take a break, or if you get interrupted somehow, +you have to restart the logging when you continue. +Choose a new / different file name. +Finally, use a text editor to merge the resulting log files into a single file in the correct order.

+
+
+

After completing the lab, upload the complete result files to the Ilias course.

+
+
+ +
+
+Pseudo files for Processes +
+
+

Start a Python Interpreter in the background. The interpreter shall solely execute a continuous loop:

+
+
+
+
1
python -c "while True: pass" &
+
+
+
+
+

Find out via the /proc subdirectory related to the Python process which working directory the Python process was started with. +That means if the Python process tries to read a file from his "current directory", which directory would be searched forthe file? +(Such questions should only be answered for yourself, you do not have to answer "submit" …​)

+
+
+

Find out via the /proc subdirectory related to the Python process which command this process was started with. +You should see the full command, but all parts of the command are "glued together". Why? +Because the driver for the /proc filesystem separates the individual parts (parameters) of the command with \0 (NULL), +which means it is a list of C-strings. The following command at least shows that there are still "separators" between the parts of the command:

+
+
+
+
1
+2
PYTHON_PID=$(pgrep --newest python)
+cat --show-all /proc/$PYTHON_PID/cmdline
+
+
+
+
+

And by means of the following command, all \0 characters are replaced by a line break:

+
+
+
+
1
cat /proc/$PYTHON_PID/cmdline | tr '\0' '\n'
+
+
+
+
+

Let the system output the environment (i.e., the list of environment variables with their values) of the python process.

+
+
+

Kill the running Python Interpreter:

+
+
+
+
1
pkill python
+
+
+
+
+ +
+
+File system 'Jails': chroot +
+
+

Download the tar archive (= "packed" archive file) of a basic Linux filesystem:

+
+
+
+
1
+2
cd /home/itsadmin
+wget https://github.com/ericchiang/containers-from-scratch/releases/download/v0.1.0/rootfs.tar.gz
+
+
+
+
+

Unzip the archive as user itsadmin:

+
+
+
+
1
sudo tar zxf rootfs.tar.gz
+
+
+
+
+

Take a look at the archive contents:

+
+
+
+
1
+2
ls rootfs
+ls -al rootfs/bin/
+
+
+
+
+

Create a blank file in-rootfs.txt as follows. +This serves as a "marking" to recognize the directory /home/itsadmin/rootfs based on the existence of this file:

+
+
+
+
1
+2
sudo touch rootfs/in-rootfs.txt
+ls rootfs
+
+
+
+
+

Check that you are currently working as user itsadmin:

+
+
+
+
1
id
+
+
+
+
+

Now execute the chroot command with administrator rights. +The command should start a bash shell (= command prompt, console session) +with the directory /home/itsadmin/rootfs as a root directory:

+
+
+
+
1
sudo chroot ./rootfs /bin/bash
+
+
+
+
+

Check that this shell really has the directory above as its root directory by looking for the file in-rootfs.txt:

+
+
+
+
1
ls /
+
+
+
+
+

Check that due to the chroot you are now working as administrator user root:

+
+
+
+
1
id
+
+
+
+
+

Now check that even the Administrator user root can not leave the "restricted root directory":

+
+
+
+
1
+2
+3
+4
cd /
+ls
+cd ..
+ls
+
+
+
+
+

But by leaving the shell by means of exit you get out of the chroot "filesystem jail". +chroot was only applicable for the bash shell program that was started by it …​

+
+
+
+
1
exit
+
+
+
+
+

Also applications can run in a chroot. +We will try this via a Python interpreter that will run a mini web server. +First, we check that Python interpreter executable exists within the filesystem under rootfs:

+
+
+
+
1
ls rootfs/usr/bin/python
+
+
+
+
+

For Python to work, the following workaround is necessary (otherwise /dev/urandom will b emissing, which is needed by Python):

+
+
+
+
1
sudo mount --bind /dev/ rootfs/dev
+
+
+
+
+

Now we can start Python in the chroot "jail":

+
+
+
+
1
sudo chroot rootfs python -m http.server
+
+
+
+
+

Via a new, other console, call a web page served by this web server:

+
+
+
+
1
curl localhost:8000
+
+
+
+
+

Note: The file in-rootfs.txt is also part of the listing on this web page!

+
+
+

Switch to the console in which the Python program is running. +Exit the program via Ctrl-C.

+
+
+

Leave the chroot "filesystem jail":

+
+
+
+
1
exit
+
+
+
+
+

End the above workaround:

+
+
+
+
1
sudo umount rootfs/dev
+
+
+
+
+

"::h1 Simple Container"

+
+
+

Now combine PID namespaces and chroot using the following command:

+
+
+
+
1
sudo unshare --pid --fork chroot ./rootfs /bin/bash
+
+
+
+
+

Take a look at the root filesystem as well as the current user of the "container".

+
+
+

To view the processes in the "container", a command must be executed that instructs the procfs driver to +make the needed pseudo files available within the /proc directory of the "container".

+
+
+
+
1
mount –t proc procfs /proc
+
+
+
+
+

Now the processes visible in the "container" can be viewed via the ps command.

+
+
+

End the container via exit.

+
+
+ +
+
+Using Files as Disks +
+
+

Use the dd command to create a file /tmp/disk1.img. +The file shall have a size of 512 MB and shall be filled with zeros:

+
+
+
+
1
dd if=/dev/zero of=/tmp/disk1.img bs=1M count=512
+
+
+
+
+

Within the file, create a File system of ext3 type.

+
+
+

Create a directory /mnt/disk1.

+
+
+

Mount the file into the just created directory (mount).

+
+
+

Create a new file in the directory. +You may have to do so as root, because standard users do not have write permissions in the directory. +Alternatively, you can also grant write permissions to the directory to all users and then create the file as the default user.

+
+
+

Check that the file is created successfully.

+
+
+

Check as well that a subdirectory lost+found also exists in that directory. +This automatically created directory is a good indicator that the directory is the root directory of a filesystem of a separate disk: +it is a kind of "wastebasket of the filesystem", where the filesystem possibly stores +orphaned files when filesystem operations should run into errors.

+
+
+

Unmount the "disk implemented via a file" at the location /mnt/disk1 again.

+
+
+

Delete the directory /mnt/disk1 as well as the data file /tmp/disk1.img.

+
+
+ +
+
+Simple Containers using Overlay Filesystem +
+
+

Download the following file into the directory /home/itsadmin using wget:

+
+
+
+
1
https://github.com/ericchiang/containers-from-scratch/releases/download/v0.1.0/rootfs.tar.gz
+
+
+
+
+

Unzip with administrator rights (important) the downloaded file:

+
+
+
+
1
sudo tar -zxf rootfs.tar.gz
+
+
+
+
+

Switch to the rootfs subdirectory just created and as root user create four subdirectories there: +container1_subdir_1, container1_subdir_2, container2_subdir_1, container2_subdir_2

+
+
+

Let the system output the contents of directory /home/`datei1.txt, datei2.txt. /rootfs` and check that the four directories are present.

+
+
+

As root user, create two files in each of the four directories: +datei1.txt, datei2.txt. +The content of the files does not matter and can also be empty.

+
+
+

Back as user itsadmin, in the /home/itsadmin directory, create the following subdirectories: +upper1, upper2, work1, work2, overlay1, overlay2.

+
+
+

Now create two overlay filesystem structures:

+
+
+
+
1
+2
sudo mount -t overlay -o lowerdir=rootfs,upperdir=upper1,workdir=work1 none overlay1
+sudo mount -t overlay -o lowerdir=rootfs,upperdir=upper2,workdir=work2 none overlay2
+
+
+
+
+

Let the system list the directory contents of the directories /home/itsadmin/overlay1 and /home/itsadmin/overlay2. +You should both times see the files from rootfs.

+
+
+

Enter the command mount and watch the last two lines of the output of the command. +There you should find the mounted overlay structures.

+
+
+

Open a new command line or a new command line tab and start a "simple container" there:

+
+
+
+
1
sudo unshare --pid  --mount --fork chroot overlay1 /bin/bash
+
+
+
+
+

Check your user identity in the container and have the system output the contents of the root directory of the container using the command ls /. +You should see the files from rootfs there.

+
+
+

In this first container, delete the directory /srv and all of its content. +Check that the directory is indeed deleted.

+
+
+

In the root directory of the container, create a file container1_added.txt. +The file contents do not matter and can also be empty. +Insert a directory /container1_added_subdir_1 and in this directory a file /container1_added_subdir_1/container1_added.txt.

+
+
+

In the container, recursively delete the directory /container1_subdir_1 with all its contents. +Create a new file /container1_subdir_2/container1_added.txt and delete the file /container1_subdir_2/file1.txt.

+
+
+

After all these steps in the container, check that the required changes have all been executed correctly.

+
+
+

Now open another new command line or a new command line tab and start a second "simple container" there:

+
+
+
+
1
sudo unshare --pid  --mount --fork chroot overlay2 /bin/bash
+
+
+
+
+

Check your user identity in the container and have the system output the contents of the root directory of the container using the command ls /. +You should see the files from rootfs there.

+
+
+

In this second container, delete the directory /media including all its contents. +Check that the directory is indeed deleted. +Also, check that the /srv directory still exists, i.e. the deletion of this directory in container1 obviously has had no effect on container2.

+
+
+

In the root directory of the container, create a file container2_added.txt. +The file contents do not matter and can also be empty.

+
+
+

Create a directory /container2_added_subdir_1 and in this directory a file /container2_added_subdir_1/container2_added.txt.

+
+
+

In the container, recursively delete the directory /container2_subdir_1 with all its contents.

+
+
+

Create a new file /container2_subdir_2/container2_added.txt and delete the file /container2_subdir_2/file1.txt.

+
+
+

Switch to each of the command lines of Container1 and Container2 and check that the changes made in each container did not have an impact on each other container.

+
+
+

Switch to the command line of Container2. +Use the command ps aux to view the list of processes in the container and +terminate this command line and thus the container via exit.

+
+
+

Also leave the command line or the command line tab that was opened for the container by means of exit.

+
+
+

Switch to the command line of Container1. +Use ps aux to get the list of processes in the container and +terminate this command line and thus the container via exit.

+
+
+

Also leave the command line or the command line tab that was opened for this container by means of exit.

+
+
+

Stop the mounting and end the existence of the two overlay filesystem structures:

+
+
+
+
1
+2
sudo umount /home/itsadmin/overlay2
+sudo umount /home/itsadmin/overlay1
+
+
+
+
+

Now look at the contents of the directories upper1 and upper2 (including their subdirectories) +and analyze the results for yourself.

+
+
+

Take a look at the content of the rootfs directory and observe that all these activities have no changed the original directory contents. +The container…​ subdirectories should also be completely present; +these were created before the containers were started and thus belong to the "initial state". +Also observe that in rootfs, the directories srv and media are still available with their contents.

+
+
+

With administrator permissions, recursively delete the directories +upper1, upper2, work1, work2, overlay1, overlay2 und rootfs +with all their contents.

+
+
+ +
+
+Upload of console log file and completion of this lab +
+
+

When you have finalized your lab work, you need to end the logging by entering exit into your console. The following output should appear:

+
+
+
+
1
Script done, file is Linux-praktikum-05.log
+
+
+
+
+

Start a webbrowser inside the virtual machine and upload the log file to ILIAS, using this web browser.

+
+
+

Shut down the VM, remove the VM completely (delete all files) and end your session.

+
+
+ +
+
+ + + \ No newline at end of file diff --git a/Task_4-6/Linux-Cl-Praktikum_06_en.html b/Task_4-6/Linux-Cl-Praktikum_06_en.html new file mode 100644 index 0000000..11a53c8 --- /dev/null +++ b/Task_4-6/Linux-Cl-Praktikum_06_en.html @@ -0,0 +1,1229 @@ + + + + + + + +Linux Praktikumstermin 2025_06: Simple Container & btrfs + + + + + + + +
+
+General Notes with respect to this Lab Exercise +
+
+FAQ concerning Lab Work of Lehrgebiet Informationstechnische Systeme (ITS) +
+

As the technical setup (using VirtualBox Virtual Machines) is similar +in several of Prof. Classen’s lectures / labs, we provide shared FAQ answers +in a separate, shared Ilias course at +Support für die WF Praktika Prof. Claßen. +Feel free to become a member of that Ilias course.

+
+
+

A +Wiki +there provides FAQ answers +related to the technical setup of the Prof. Classen labs. +New FAQ answers will be added on demand. +If you have problems creating and starting the VM, +first check the information in our FAQ. +In particular, the points on the topic of activating hardware virtualization on Windows systems.

+
+
+

Specific questions specifically related +to one module' lab only will however not be answered there, but in the Ilias of the specific module +instead. Only questions that are valid for multiple / all of the labs will be handled +via the shared Support Wiki.

+
+ +
+
+On your own computer: VirtualBox Installation +
+

VirtualBox Version 7.x is installed on the terminal computers.

+
+
+

If you are working on your own computer, +so you should also install and use the latest version of Virtualbox 7.x.

+
+ +
+
+Operating the VirtualBox VM +
+

With VirtualBox, the mouse and keyboard may be "caught" in the VM, +as soon as you click in the console window. +You can then "release" it by pressing the right Ctrl key.

+
+ +
+
+Persistence of data and changes +
+

The changes in the virtual machine are persistent +even if you have to shut down or reboot the virtual machine during the lab exercises.

+
+ +
+
+Interrupting the Lab Work: Shut down the VM, do not pause it +
+

If you need to interrupt your lab work, +please do not pause the VM, +instead, shut down the VM. +Otherwise, when paused, the VM will not have a +working network connection when you continue your work.

+
+ +
+
+Superuser Permissions +
+

Many of the commands and file content changes in the following exercises +require superuser (root) permissions, because they impact general system settings. In many cases, this is explicitly mentioned in the explanation of the respective exercise. +We do however expect you to understand the concept, +so therefore there might be cases where you are expected to recognize and handle this yourself. +As a general hint: should you get error messages like command not found or Permission denied +when issueing a command, this might be an indication +that the respective command needs to be executed as +root superuser.

+
+ +
+
+ +
+
+ Download and Setup of the Virtual Machine (VM) Container_btrfs_VM +
+
+On the FH Aachen PCs: +
+
+

Start VirtualBox.

+
+
+

Importing the appliance for the ITS-VM ("ITS" == "Lehrgebiet Informationstechnische Systeme, Prof. Claßen"):

+
+
+

Open the windows command shell cmd.exe by clicking on the menu in the bottom left corner, then "blindly" type in cmd, followed +by a left click onto cmd.exe. +Enter the following command into the shell:

+
+
+
+
1net use S: \\ad.fh-aachen.de\files\FB05\StudiShare
+
+
+
+

You should now see a new drive S: in the explorer.

+
+
+

=== Importing the appliance for the VM) Container_btrfs_VM

+
+
+

In VirtualBox menu file : +import appliance, select ITS_Client_Debian12_AMD64_V02.ova in +S:\Classen\VM_OVAs\ , +click Next, +change name setting to Container_btrfs_VM.

+
+
+

On FH terminal room computers: +change virtual disk image to +D:\VMs\Container_btrfs_VM.vmdk.

+
+
+ + + + + +
+ + +
Assign a new MAC address
+Important (on all computers): +Make sure to set the checkbox +Assign new MAC addresses for all network cards, +alternatively go to MAC Address Policy +and set Include all network adapter MAC addresses. +
+
+
+

Finally click on Import.

+
+
+
+
+On your private computer: +
+
+

Download ITS_Client_Debian12_AMD64_V02.ova from +https://fh-aachen.sciebo.de/s/voHfcjRsXAfYbfJ

+
+
+

In VirtualBox menu file : +import appliance, select ITS_Client_Debian12_AMD64_V02.ova +from your local download folder, +click Next, +change name setting to Container_btrfs_VM.

+
+
+ + + + + +
+ + +
Assign a new MAC address
+Important (on all computers): +Make sure to set the checkbox +Assign new MAC addresses for all network cards, +alternatively go to MAC Address Policy +and set Include all network adapter MAC addresses. +
+
+
+

Finally click on Import.

+
+
+
+
+Adding additional Virtual Hard Disks +
+

Change the configuration for this VM under storage:

+
+
+

Click on +Controller: SATA (or` Controller: SATA Controller`).

+
+
+

Then click on the right icon with a plus sign that appears to the right (Add hard disk).

+
+
+

There Create new disk, File type: VDI, Next, Type of storage:` dynamically allocated`, Next.

+
+
+

You can freely choose the file name and leave the suggested size of 10 GB +(because of dynamic storage, the size of 10 GB is actually not really allocated, +so this will not take up that much hard disk space on your physical computer), +Create.

+
+
+ + + + + +
+ + +
Add 3 virtual hard disks
+Repeat this procedure until you have added in total +3 +such additional virtual disks +(that makes a total of 3+1 hard disks: +The operating system is installed on the first hard disk, +all other disks are used as data disks). +
+
+ +
+
+Starting the VM +
+

Start the VM.

+
+
+

Should you get an error message when starting the VM regarding +VirtualBox Host-Only Ethernet Adapter is not a Host-Only Network +(or similar), the name of the host-only network in your VirtualBox installation differs from +the name expected by the VM definition. +For the VM refusing to start, click on Configure (upper-left of the +VirtualBox window) and a settings window will open for that VM. +Click on OK without changing any VM settings. +This will nevertheless update the VM settings and correct the problem. +Start the VM again.

+
+ +
+
+Account Data for the VM +
+

The user accounts of the VM are:

+
+
+
    +
  • +

    User: itsadmin, Password: itsadmin

    +
  • +
  • +

    Administrator-User: root, Password: itsadmin

    +
  • +
+
+ +
+
+ +
+
+Result logging +
+
+

To show that you have successfully finished this lab, please upload a log file to ILIAS. The log file +will contain all commands that you typed in during your session and all system outputs.

+
+
+

It is not a problem if there are commands in the logfile that did not work on first try or were typed in wrong, +we just want to see that at some point all the required commands were used correctly.

+
+
+

Open a terminal in the virtual +machine and start the logging by using the script command +(option -a means: append to file in case the file is non-empty +when the logging to file is started):

+
+
+
+
1script -a Linux-praktikum-06.log
+
+
+
+

The following output should appear:

+
+
+
+
1Script started, file is Linux-praktikum-06.log
+
+
+
+

From now on, please only use the console in which the logger is running, so that everything gets logged correctly!

+
+
+

If you want to interrupt the lab and shut down the virtual machine, e.g. to take a break, or if you get interrupted somehow, +you have to restart the logging when you continue. +Choose a new / different file name. +Finally, use a text editor to merge the resulting log files into a single file in the correct order.

+
+
+

After completing the lab, upload the complete result files to the Ilias course.

+
+
+ +
+
+btrfs +
+
+

Install the btrfs file system driver and the tools required for btrfs using the software package btrfs-progs:

+
+
+
+
1sudo apt-get update
+2sudo apt-get install -y btrfs-progs
+
+
+
+

Create a btrfs file system using the two hard drives sdb and sdc as devices:

+
+
+
+
1sudo mkfs.btrfs /dev/sdb /dev/sdc
+
+
+
+

Have the system output information about the file system. +Each of the two devices can be used as "reference" to the overall file system spanning the two devices:

+
+
+
+
1sudo btrfs filesystem show /dev/sdb
+2sudo btrfs filesystem show /dev/sdc
+
+
+
+

Create a directory /mnt/prakt and mount the btrfs file system with administrator rights at this mount point. +Again, each of the two devices can be used as reference to the file system.

+
+
+
+
1sudo mkdir /mnt/prakt
+2sudo mount -t btrfs /dev/sdc /mnt/prakt
+3mount | grep btrfs
+
+
+
+

Make the mounted file system writable for all users and copy some "dummy files" there:

+
+
+
+
1sudo chmod a+w /mnt/prakt
+2cp -r /usr/share/doc /mnt/prakt/
+
+
+
+

Now that the file system is mounted, the mount point can also in many cases be used as a reference to the file system. +E.g. the following command displays information about the file system "level of fill up" analogous to the "classic" df command:

+
+
+
+
1btrfs filesystem df /mnt/prakt
+
+
+
+

Add another device:

+
+
+
+
1sudo btrfs device add /dev/sdd /mnt/prakt
+2sudo btrfs filesystem balance start --full-balance /mnt/prakt
+3sudo btrfs filesystem show /mnt/prakt
+4btrfs filesystem df /mnt/prakt
+
+
+
+

Now we remove one of the original devices:

+
+
+
+
1sudo btrfs device remove /dev/sdc /mnt/prakt
+2sudo btrfs filesystem balance start --full-balance /mnt/prakt
+3sudo btrfs filesystem show /mnt/prakt
+
+
+
+

Create a new subvolume SV1, in the /mnt/prakt directory, i.e. at the top level within the btrfs file system:

+
+
+
+
1sudo btrfs subvolume create /mnt/prakt/SV1
+2sudo btrfs subvolume list /mnt/prakt
+
+
+
+

Together with the subvolume the associated directory is also created. The directory is still empty, of course:

+
+
+
+
1ls /mnt/prakt/SV1
+
+
+
+

Make the directory writable for all users and create two files there (file content does not matter, can also be empty):

+
+
+
+
1sudo chmod a+w /mnt/prakt/SV1
+2# Create two files file1.txt and file2.txt in that directory
+3ls /mnt/prakt/SV1
+
+
+
+

Place a second, nested subvolume:

+
+
+
+
1sudo btrfs subvolume create /mnt/prakt/SV1/SV11
+2sudo btrfs subvolume list /mnt/prakt
+3ls /mnt/prakt/SV1/SV11
+4sudo chmod a+w /mnt/prakt/SV1/SV11
+
+
+
+

Create two files file11.txt and file12.txt in this subvolume.

+
+
+
+
1ls /mnt/prakt/SV1/SV11
+
+
+
+

Place two mount points for the two subvolumes:

+
+
+
+
1sudo mkdir -p /mnt/SV1 /mnt/SV11
+
+
+
+

Mount the outer / upper subvolume SV1. Again, one of the involved Devices must be specified as a reference to the file system containing the subvolume. Observe that when mounting the outer subvolume, the inner / nested subvolume SV11 is also automatically available:

+
+
+
+
1sudo mount -o subvol=SV1 /dev/sdb /mnt/SV1
+2ls -R /mnt/SV1
+3ls /mnt/SV1/SV11
+
+
+
+

Now mount the inner subvolume SV11 separately. This shows that each subvolume can also be mounted separately. And it is not a problem that SV11 is now available via "multiple paths" in the file system:

+
+
+
+
1sudo mount -o subvol=SV1/SV11 /dev/sdb /mnt/SV11
+2ls /mnt/SV11/
+3ls /mnt/SV1/SV11
+
+
+
+

Create a snapshot of the current state of the subvolume SV11. The snapshot is also made available as a subvolume. We need to specify where this new subvolume should be placed in the btrfs file system:

+
+
+
+
1sudo btrfs subvolume snapshot /mnt/prakt/SV1/SV11 /mnt/prakt/sv11-snapshot
+2sudo btrfs subvolume list /mnt/prakt
+3
+4ls /mnt/prakt
+
+
+
+

Create a mount point for the new subvolume and mount it there:

+
+
+
+
1sudo mkdir -p /mnt/SV11-Snapshot
+2sudo mount -o subvol=sv11-snapshot /dev/sdb /mnt/SV11-Snapshot
+3ls /mnt/SV11-Snapshot
+
+
+
+

The snapshot is writable: delete the file file11.txt from the snapshot. Check that this file is really deleted in the snapshot, but is still available in the source subvolume SV11.

+
+
+

Then delete the file file12.txt in the source subvolume SV11 and check that this file is still available in the snapshot.

+
+
+

Now a backup of the snapshot could now be made, even if it takes a long time, and the original subvolume SV11 could still continue to be in use and could be changed without jeopardizing the consistency of the backup’s data.

+
+
+

Unmount the snapshot:

+
+
+
+
1sudo umount /mnt/SV11-Snapshot
+
+
+
+

Now delete the snapshot itself:

+
+
+
+
1sudo btrfs subvolume delete --commit-after /mnt/prakt/sv11-snapshot
+
+
+
+

Check that the snapshot is no longer available:

+
+
+
+
1ls /mnt/prakt
+2sudo btrfs subvolume list /mnt/prakt
+
+
+
+

Now delete the mount point that is no longer needed:

+
+
+
+
1sudo rmdir /mnt/SV11-Snapshot
+
+
+
+

Now also unmount the other mount:

+
+
+
+
1sudo umount /mnt/SV1
+2sudo rmdir /mnt/SV1
+
+
+
+ +
+
+Simple container with file system +
+
+

Download the following file into the directory /home/itsadmin using wget:

+
+ +
+

Copy the file /home/itsadmin/rootfs.tar.gz to the /mnt/prakt directory, i.e. to the btrfs file system.

+
+
+

Unzip the downloaded file with administrator rights (important):

+
+
+
+
1cd /mnt/prakt
+2sudo tar -zxf rootfs.tar.gz
+
+
+
+

Create a new subvolume root_subvolume:

+
+
+
+
1sudo btrfs subvolume create root_subvolume
+
+
+
+

Move all contents of the rootfs/ directory into the new subvolume root_subvolume and delete the emptied source directory:

+
+
+
+
1sudo mv rootfs/* root_subvolume/
+2ls rootfs
+3rmdir rootfs
+
+
+
+

Take a look at and remember how much space for data is occupied in the btrfs file system. The rootfs.tar.gz file is about 260 MB in size, the resulting files occupy about 705 MB, altogether under 1 GB:

+
+
+
+
1sudo btrfs filesystem df /mnt/prakt
+
+
+
+

Now we create two writable snapshots. These are then used as file systems for two containers. Because of the Copy-on-Write principle, the containers do not get real copies of the files, so little space is consumed per container. The original subvolume and its contents are not changed by the containers:

+
+
+
+
1sudo btrfs subvolume snapshot root_subvolume root_container1
+2ls root_container1/
+3
+4sudo btrfs subvolume snapshot root_subvolume root_container2
+5ls root_container2/
+
+
+
+

Take a look at and compare with the previous value, how much space for data is occupied in the btrfs file system:

+
+
+
+
1sudo btrfs filesystem df /mnt/prakt
+
+
+
+

In case of real copying of all files, the occupied disk space would have increased by 2x 705 MB …​

+
+
+

Open a new command line or a new command line tab and start a "simple container" there:

+
+
+
+
1sudo unshare --pid  --mount --fork chroot /mnt/prakt/root_container1 /bin/bash
+
+
+
+

Use ls / to list the contents of the root directory of the container. You should see the files from rootfs there.

+
+
+

In this first container, recursively delete the directory /srv and all of its content.

+
+
+

In the root directory of the container, create a file container1_added.txt. The file content does not matter and the file can also be empty. Create a directory /container1_added_subdir_1 and in this directory create a file /container1_added_subdir_1/container1_added.txt.

+
+
+

Now open another new command line or a new command line tab and start a second "simple container" there:

+
+
+
+
1sudo unshare --pid  --mount --fork chroot /mnt/prakt/root_container2 /bin/bash
+
+
+
+

Also in this container, use ls / to list the contents of the root directory of the container. You should see the files from rootfs there.

+
+
+

In this second container, recursively delete the directory /media including all of its content. Check that the directory is indeed deleted. Also check that the /srv directory still exists, i.e. its deletion in container1 obviously had no effect on container2.

+
+
+

In the root directory of the container, create a file container2_added.txt. The file content does not matter and can also be empty. Create a directory /container2_added_subdir_1 and in this directory a file /container2_added_subdir_1/container2_added.txt.

+
+
+

Change to the command lines of container1 and container2 and check that the changes made in each container did not have an impact on the other container.

+
+
+

Switch to the command line of container2. End this command line and thus the container via exit.

+
+
+

Also end the command line or command line tab that was opened before starting the container container2 by means of exit.

+
+
+

Switch to the command line of container1. Via command ps aux take a look at the list of processes in the container and end this command line and thus the container via exit.

+
+
+

Also end the command line or command line tab that was opened for starting the container by means of exit.

+
+
+

Starting from /mnt/prakt, take a look at the top level content of directory root_subvolume. The changes made in the containers should have had no impact on the contents of this subvolume.

+
+
+

Analyze the top level contents of the directories root_container1 and root_container2. The changes made in the containers should be visible here.

+
+
+

Check the amount of occupied space in the file system:

+
+
+
+
1sudo btrfs filesystem df /mnt/prakt
+
+
+
+

The amount of occupied space should not have changed significantly.

+
+
+ +
+
+Upload of console log file and completion of this lab +
+
+

When you have finalized your lab work, you need to end the logging by entering exit into your console. The following output should appear:

+
+
+
+
1Script done, file is Linux-praktikum-06.log
+
+
+
+

Start a webbrowser inside the virtual machine and upload the log file to ILIAS, using this web browser.

+
+
+

Shut down the VM, remove the VM completely (delete all files) and end your session.

+
+
+ +
+
+ + + \ No newline at end of file