hwdb: fix screen rotation for EXO Wings 2in1 w1125 (#36283)
[systemd.io.git] / test / units / TEST-87-AUX-UTILS-VM.mount.sh
blobc1bfbdc1a22d6c0a86ed501f3f37329b810609e5
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 set -eux
4 set -o pipefail
6 # shellcheck source=test/units/util.sh
7 . "$(dirname "$0")"/util.sh
9 at_exit() {
10 set +e
12 [[ -n "${LOOP:-}" ]] && losetup -d "$LOOP"
13 [[ -n "${WORK_DIR:-}" ]] && rm -fr "$WORK_DIR"
16 (! systemd-detect-virt -cq)
18 trap at_exit EXIT
20 WORK_DIR="$(mktemp -d)"
21 mkdir -p "$WORK_DIR/mnt"
23 systemd-mount --list
24 systemd-mount --list --full
25 systemd-mount --list --no-legend
26 systemd-mount --list --no-pager
27 systemd-mount --list --quiet
28 systemd-mount --list --json=pretty
30 # tmpfs
31 mkdir -p "$WORK_DIR/mnt/foo/bar"
32 systemd-mount --tmpfs "$WORK_DIR/mnt/foo"
33 test ! -d "$WORK_DIR/mnt/foo/bar"
34 touch "$WORK_DIR/mnt/foo/baz"
35 systemd-umount "$WORK_DIR/mnt/foo"
36 test -d "$WORK_DIR/mnt/foo/bar"
37 test ! -e "$WORK_DIR/mnt/foo/baz"
39 # overlay
40 systemd-mount --type=overlay --options="lowerdir=/etc,upperdir=$WORK_DIR/upper,workdir=$WORK_DIR/work" /etc "$WORK_DIR/overlay"
41 touch "$WORK_DIR/overlay/foo"
42 test -e "$WORK_DIR/upper/foo"
43 systemd-umount "$WORK_DIR/overlay"
45 # Set up a simple block device for further tests
46 dd if=/dev/zero of="$WORK_DIR/simple.img" bs=1M count=16
47 mkfs.ext4 -L sd-mount-test "$WORK_DIR/simple.img"
48 LOOP="$(losetup --show --find "$WORK_DIR/simple.img")"
49 udevadm wait --timeout 60 --settle "$LOOP"
50 # Also wait for the .device unit for the loop device is active. Otherwise, the .device unit activation
51 # that is triggered by the .mount unit introduced by systemd-mount below may time out.
52 timeout 60 bash -c "until systemctl is-active $LOOP; do sleep 1; done"
53 mount "$LOOP" "$WORK_DIR/mnt"
54 touch "$WORK_DIR/mnt/foo.bar"
55 umount "$LOOP"
56 (! mountpoint "$WORK_DIR/mnt")
57 # Wait for the mount unit to be unloaded. Otherwise, creation of the transient unit below may fail.
58 MOUNT_UNIT=$(systemd-escape --path --suffix=mount "$WORK_DIR/mnt")
59 timeout 60 bash -c "while [[ -n \$(systemctl list-units --all --no-legend $MOUNT_UNIT) ]]; do sleep 1; done"
61 # Mount with both source and destination set
62 systemd-mount "$LOOP" "$WORK_DIR/mnt"
63 systemctl status "$WORK_DIR/mnt"
64 systemd-mount --list --full
65 test -e "$WORK_DIR/mnt/foo.bar"
66 systemd-umount "$WORK_DIR/mnt"
67 # Same thing, but with explicitly specified filesystem and disabled filesystem check
68 systemd-mount --type=ext4 --fsck=no --collect "$LOOP" "$WORK_DIR/mnt"
69 systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").mount"
70 test -e "$WORK_DIR/mnt/foo.bar"
71 systemd-mount --umount "$LOOP"
72 # Discover additional metadata (unit description should now contain filesystem label)
73 systemd-mount --no-ask-password --discover "$LOOP" "$WORK_DIR/mnt"
74 test -e "$WORK_DIR/mnt/foo.bar"
75 systemctl show -P Description "$WORK_DIR/mnt" | grep -q sd-mount-test
76 systemd-umount "$WORK_DIR/mnt"
77 # Set a unit description
78 systemd-mount --description="Very Important Unit" "$LOOP" "$WORK_DIR/mnt"
79 test -e "$WORK_DIR/mnt/foo.bar"
80 systemctl show -P Description "$WORK_DIR/mnt" | grep -q "Very Important Unit"
81 systemd-umount "$WORK_DIR/mnt"
82 # Set a property
83 systemd-mount --property="Description=Foo Bar" "$LOOP" "$WORK_DIR/mnt"
84 test -e "$WORK_DIR/mnt/foo.bar"
85 systemctl show -P Description "$WORK_DIR/mnt" | grep -q "Foo Bar"
86 systemd-umount "$WORK_DIR/mnt"
87 # Set mount options
88 systemd-mount --options=ro,x-foo-bar "$LOOP" "$WORK_DIR/mnt"
89 test -e "$WORK_DIR/mnt/foo.bar"
90 systemctl show -P Options "$WORK_DIR/mnt" | grep -Eq "(^ro|,ro)"
91 systemctl show -P Options "$WORK_DIR/mnt" | grep -q "x-foo-bar"
92 systemd-umount "$WORK_DIR/mnt"
94 # Mount with only source set
95 systemd-mount "$LOOP"
96 systemctl status /run/media/system/sd-mount-test
97 systemd-mount --list --full
98 test -e /run/media/system/sd-mount-test/foo.bar
99 systemd-umount LABEL=sd-mount-test
101 # Automount
102 systemd-mount --automount=yes "$LOOP" "$WORK_DIR/mnt"
103 systemd-mount --list --full
104 systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount"
105 [[ "$(systemctl show -P ActiveState "$WORK_DIR/mnt")" == inactive ]]
106 test -e "$WORK_DIR/mnt/foo.bar"
107 systemctl status "$WORK_DIR/mnt"
108 systemd-umount "$WORK_DIR/mnt"
109 # Automount + automount-specific property
110 systemd-mount -A --automount-property="Description=Bar Baz" "$LOOP" "$WORK_DIR/mnt"
111 systemctl show -P Description "$(systemd-escape --path "$WORK_DIR/mnt").automount" | grep -q "Bar Baz"
112 test -e "$WORK_DIR/mnt/foo.bar"
113 # Call --umount via --machine=, first with a relative path (bad) and then with
114 # an absolute one (good)
115 (! systemd-umount --machine=.host "$(realpath --relative-to=. "$WORK_DIR/mnt")")
116 systemd-umount --machine=.host "$WORK_DIR/mnt"
118 # ext4 doesn't support uid=/gid=
119 (! systemd-mount -t ext4 --owner=testuser "$LOOP" "$WORK_DIR/mnt")
121 # Automount + --bind-device
122 systemd-mount --automount=yes --bind-device --timeout-idle-sec=1 "$LOOP" "$WORK_DIR/mnt"
123 systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount"
124 # Trigger the automount
125 test -e "$WORK_DIR/mnt/foo.bar"
126 # Wait until it's idle again
127 sleep 1.5
128 # Safety net for slower/overloaded systems
129 timeout 10s bash -c "while systemctl is-active -q $WORK_DIR/mnt; do sleep .2; done"
130 systemctl status "$(systemd-escape --path "$WORK_DIR/mnt").automount"
131 # Disassemble the underlying block device
132 losetup -d "$LOOP"
133 unset LOOP
134 # The automount unit should disappear once the underlying blockdev is gone
135 timeout 10s bash -c "while systemctl status '$(systemd-escape --path "$WORK_DIR/mnt".automount)'; do sleep .2; done"
137 # Mount a disk image
138 systemd-mount --discover "$WORK_DIR/simple.img"
139 # We can access files in the image even if the loopback block device is not initialized by udevd.
140 test -e /run/media/system/simple.img/foo.bar
141 # systemd-mount --list and systemd-umount require the loopback block device is initialized by udevd.
142 udevadm settle --timeout 30
143 assert_in "/dev/loop.* ext4 +sd-mount-test" "$(systemd-mount --list --full)"
144 LOOP_AUTO=$(systemd-mount --list --full --no-legend | awk '$7 == "sd-mount-test" { print $1 }')
145 LOOP_AUTO_DEVPATH=$(udevadm info --query property --property DEVPATH --value "$LOOP_AUTO")
146 systemd-umount "$WORK_DIR/simple.img"
147 # Wait for 'change' uevent for the device with DISK_MEDIA_CHANGE=1.
148 # After the event, the backing_file attribute should be removed.
149 timeout 60 bash -c "while [[ -e /sys/$LOOP_AUTO_DEVPATH/loop/backing_file ]]; do sleep 1; done"
151 # --owner + vfat
153 # Create a vfat image, as ext4 doesn't support uid=/gid= fixating for all
154 # files/directories
155 dd if=/dev/zero of="$WORK_DIR/owner-vfat.img" bs=1M count=16
156 mkfs.vfat -n owner-vfat "$WORK_DIR/owner-vfat.img"
157 LOOP="$(losetup --show --find "$WORK_DIR/owner-vfat.img")"
158 # If the synthesized uevent triggered by inotify event has been processed earlier than the kernel finishes to
159 # attach the backing file, then SYSTEMD_READY=0 is set for the device. As a workaround, monitor sysattr
160 # and re-trigger uevent after that.
161 LOOP_DEVPATH=$(udevadm info --query property --property DEVPATH --value "$LOOP")
162 timeout 60 bash -c "until [[ -e /sys/$LOOP_DEVPATH/loop/backing_file ]]; do sleep 1; done"
163 udevadm trigger --settle "$LOOP"
164 # Also wait for the .device unit for the loop device is active. Otherwise, the .device unit activation
165 # that is triggered by the .mount unit introduced by systemd-mount below may time out.
166 if ! timeout 60 bash -c "until systemctl is-active $LOOP; do sleep 1; done"; then
167 # For debugging issue like
168 # https://github.com/systemd/systemd/issues/32680#issuecomment-2120959238
169 # https://github.com/systemd/systemd/issues/32680#issuecomment-2122074805
170 udevadm info "$LOOP"
171 udevadm info --attribute-walk "$LOOP"
172 cat /sys/"$(udevadm info --query property --property DEVPATH --value "$LOOP")"/loop/backing_file || :
173 false
175 # Mount it and check the UID/GID
176 [[ "$(stat -c "%U:%G" "$WORK_DIR/mnt")" == "root:root" ]]
177 systemd-mount --owner=testuser "$LOOP" "$WORK_DIR/mnt"
178 systemctl status "$WORK_DIR/mnt"
179 [[ "$(stat -c "%U:%G" "$WORK_DIR/mnt")" == "testuser:testuser" ]]
180 touch "$WORK_DIR/mnt/hello"
181 [[ "$(stat -c "%U:%G" "$WORK_DIR/mnt/hello")" == "testuser:testuser" ]]
182 systemd-umount LABEL=owner-vfat
184 # Mkae sure that graceful mount options work
185 GRACEFULTEST="/tmp/graceful/$RANDOM"
186 systemd-mount --tmpfs -p GracefulOptions=idefinitelydontexist,nr_inodes=4711,idonexisteither "$GRACEFULTEST"
187 findmnt -n -o options "$GRACEFULTEST"
188 findmnt -n -o options "$GRACEFULTEST" | grep -q nr_inodes=4711
189 umount "$GRACEFULTEST"