-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmount.sh
More file actions
executable file
·81 lines (65 loc) · 2.31 KB
/
mount.sh
File metadata and controls
executable file
·81 lines (65 loc) · 2.31 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# mount.sh - Mount a disk image with btrfs subvolumes (CI mode compatible)
# Usage: ./mount.sh <image_file> [mount_point]
set -e
if [ "$EUID" -ne 0 ]; then
echo "Error: This script must be run as root"
exit 1
fi
if [ -z "$1" ]; then
echo "Usage: $0 <image_file> [mount_point]"
echo "Example: $0 img.img /mnt"
exit 1
fi
IMAGE_FILE="$1"
MOUNT_POINT="${2:-/mnt/img}"
if [ ! -f "$IMAGE_FILE" ]; then
echo "Error: Image file '$IMAGE_FILE' not found"
exit 1
fi
echo "==> Attaching image to loop device..."
LOOP_DEV=$(losetup -f)
losetup -P "$LOOP_DEV" "$IMAGE_FILE"
echo " Loop device: $LOOP_DEV"
echo "==> Creating device mapper symlink (CI mode)..."
MAPPER_DEV="/dev/mapper/$(basename $LOOP_DEV)"
ln -sf "$LOOP_DEV" "$MAPPER_DEV"
echo "==> Creating partition mappings with kpartx..."
kpartx -avf "$LOOP_DEV"
sleep 1 # Give udev time to create devices
# In CI mode, partitions are available as /dev/mapper/loopXpY
ROOT_PART="${MAPPER_DEV}p3"
if [ ! -b "$ROOT_PART" ]; then
echo "Error: Root partition $ROOT_PART not found"
echo "Available devices:"
ls -la /dev/mapper/
kpartx -d "$LOOP_DEV"
losetup -d "$LOOP_DEV"
unlink "$MAPPER_DEV" 2>/dev/null || true
exit 1
fi
echo "==> Creating mount point: $MOUNT_POINT"
mkdir -p "$MOUNT_POINT"
echo "==> Mounting root subvolume (@) from $ROOT_PART..."
mount -t btrfs -o compress=zstd,subvol=/@ "$ROOT_PART" "$MOUNT_POINT"
echo "==> Creating subdirectories..."
mkdir -p "$MOUNT_POINT/home"
mkdir -p "$MOUNT_POINT/var/log"
mkdir -p "$MOUNT_POINT/var/cache/pacman/pkg"
mkdir -p "$MOUNT_POINT/.snapshots"
echo "==> Mounting btrfs subvolumes..."
mount -t btrfs -o compress=zstd,subvol=/@home "$ROOT_PART" "$MOUNT_POINT/home"
mount -t btrfs -o compress=zstd,subvol=/@log "$ROOT_PART" "$MOUNT_POINT/var/log"
mount -t btrfs -o compress=zstd,subvol=/@pkg "$ROOT_PART" "$MOUNT_POINT/var/cache/pacman/pkg"
mount -t btrfs -o compress=zstd,subvol=/@.snapshots "$ROOT_PART" "$MOUNT_POINT/.snapshots"
echo ""
echo "==> Successfully mounted image!"
echo " Image: $IMAGE_FILE"
echo " Loop device: $LOOP_DEV"
echo " Root part: $ROOT_PART"
echo " Mount point: $MOUNT_POINT"
echo ""
echo "Mount layout:"
lsblk "$LOOP_DEV"
echo ""
echo "To unmount, run: umount -R $MOUNT_POINT && kpartx -d $LOOP_DEV && losetup -d $LOOP_DEV && unlink $MAPPER_DEV"