-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestsetup
More file actions
executable file
·29 lines (22 loc) · 762 Bytes
/
Copy pathtestsetup
File metadata and controls
executable file
·29 lines (22 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
#
# This script creates an image file, formats it with btrfs and mounts it as
# loopback device.
set -eu
dir=local
img="$dir/img"
mnt="$dir/mnt"
sudo umount "$mnt" || echo "Unable to unmount, image was probably not mounted"
sudo losetup -d /dev/loop0 || echo "Unable to detach loopback device, it was probably not setup"
mkdir -p "$mnt"
truncate -s 100m "$img"
mkfs.btrfs "$img"
sudo losetup /dev/loop0 "$img"
sudo mount /dev/loop0 "$mnt"
sudo chmod 777 "$mnt"
dd if=/dev/urandom of="$mnt/a1" bs=1M count=2
cp --reflink "$mnt/a1" "$mnt/a1a"
# seems like btrfs is sometimes (or nowadays) smart enough to detect its the same, so using dd again
#cp "$mnt/a1" "$mnt/a2"
dd if="$mnt/a1" of="$mnt/a2" bs=1M count=2
cp --reflink "$mnt/a2" "$mnt/a2a"