forked from dia8x1/container-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpine_rootfs.sh
More file actions
83 lines (70 loc) · 2.32 KB
/
alpine_rootfs.sh
File metadata and controls
83 lines (70 loc) · 2.32 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
82
83
#!/bin/bash
set -e
# Alpine Linux version
ALPINE_VERSION="3.19"
ALPINE_MINOR="3.19.1"
ARCH="x86_64"
# rootfs directory
ROOTFS_DIR="/var/lib/container-runtime/rootfs/alpine"
echo "=========================================="
echo "Alpine Linux rootfs Installation Script"
echo "=========================================="
echo "Version: Alpine Linux ${ALPINE_MINOR}"
echo "Target Directory: ${ROOTFS_DIR}"
echo "=========================================="
echo "[1/5] Creating rootfs directory..."
sudo mkdir -p "${ROOTFS_DIR}"
echo "[2/5] Downloading Alpine minirootfs..."
DOWNLOAD_URL="https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VERSION}/releases/${ARCH}/alpine-minirootfs-${ALPINE_MINOR}-${ARCH}.tar.gz"
TARBALL="/tmp/alpine-minirootfs-${ALPINE_MINOR}-${ARCH}.tar.gz"
if [ -f "${TARBALL}" ]; then
echo "Tarball already exists: ${TARBALL}"
read -p "Download again? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo rm "${TARBALL}"
sudo wget -O "${TARBALL}" "${DOWNLOAD_URL}"
fi
else
sudo wget -O "${TARBALL}" "${DOWNLOAD_URL}"
fi
echo "[3/5] Extracting rootfs..."
sudo tar -xzf "${TARBALL}" -C "${ROOTFS_DIR}"
echo "[4/5] Creating required directories..."
for dir in proc sys dev tmp run; do
sudo mkdir -p "${ROOTFS_DIR}/${dir}"
done
echo "[5/5] Setting permissions..."
sudo chmod 755 "${ROOTFS_DIR}"
sudo chmod 1777 "${ROOTFS_DIR}/tmp"
echo "=========================================="
echo "Installation Complete!"
echo "=========================================="
echo "rootfs path: ${ROOTFS_DIR}"
echo ""
echo "Installed contents:"
sudo ls -la "${ROOTFS_DIR}"
echo ""
echo "=========================================="
echo "Usage:"
echo "=========================================="
echo ""
echo "1. Run in interactive mode:"
echo " sudo ./container-runtime run --rootfs ${ROOTFS_DIR} --command /bin/sh"
echo ""
echo "2. Run in detach mode:"
echo " sudo ./container-runtime run -d --rootfs ${ROOTFS_DIR} --command /bin/sleep 3600"
echo ""
echo "3. Verify Alpine inside container:"
echo " cat /etc/os-release"
echo " apk --version"
echo ""
echo "=========================================="
read -p "Delete downloaded tarball? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo rm "${TARBALL}"
echo "Tarball deleted: ${TARBALL}"
fi
echo ""
echo "Installation script finished"