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.