From this script:
```sh
#!/bin/sh

# Exit immediately if a command exits with a non-zero status
set -e

# Define PATH to ensure all necessary commands are found
export PATH=/sbin:/bin:/usr/sbin:/usr/bin

# Variables
ALPINE_VERSION="3.20.3"
ALPINE_ARCH="aarch64"
ALPINE_URL="https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/aarch64/alpine-minirootfs-${ALPINE_VERSION}-${ALPINE_ARCH}.tar.gz"
ROOTFS_DIR="./alpine"
TARBALL="alpine-minirootfs-${ALPINE_VERSION}-${ALPINE_ARCH}.tar.gz"

# Function to download Alpine minirootfs
download_alpine() {
    if [ -f "$TARBALL" ]; then
        echo "Alpine tarball already exists. Skipping download."
    else
        echo "Downloading Alpine minirootfs..."
        # Use wget if available, otherwise try curl
        if command -v wget > /dev/null 2>&1; then
            wget "$ALPINE_URL" -O "$TARBALL"
        elif command -v curl > /dev/null 2>&1; then
            curl -L "$ALPINE_URL" -o "$TARBALL"
        else
            echo "Error: Neither wget nor curl is available to download files."
            exit 1
        fi
    fi
}

# Function to extract Alpine minirootfs
extract_alpine() {
    if [ -d "$ROOTFS_DIR" ]; then
        echo "Alpine root filesystem already exists. Skipping extraction."
    else
        echo "Extracting Alpine minirootfs..."
        mkdir -p "$ROOTFS_DIR"
        tar -xzf "$TARBALL" -C "$ROOTFS_DIR"
    fi
}

# Function to set up the root user's home directory
setup_root_home() {
    echo "Setting up /root directory..."
    # Create /root if it doesn't exist
    if [ ! -d "$ROOTFS_DIR/root" ]; then
        mkdir -p "$ROOTFS_DIR/root"
        echo "/root directory created."
    else
        echo "/root directory already exists."
    fi

    # Set ownership to root:root
    chown 0:0 "$ROOTFS_DIR/root"

    # Set permissions to 700
    chmod 700 "$ROOTFS_DIR/root"
}

# Function to verify and set root's home directory in /etc/passwd
configure_passwd() {
    echo "Configuring /etc/passwd for root user..."
    PASSWD_FILE="$ROOTFS_DIR/etc/passwd"

    if [ ! -f "$PASSWD_FILE" ]; then
        echo "Error: /etc/passwd does not exist in the root filesystem."
        exit 1
    fi

    # Check root entry's home directory
    ROOT_HOME=$(grep '^root:' "$PASSWD_FILE" | cut -d: -f6)

    if [ "$ROOT_HOME" != "/root" ]; then
        echo "Updating root's home directory to /root in /etc/passwd..."
        # This sed command updates the sixth field (home directory) for root
        sed -i 's|^root:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:/bin/ash|root:x:0:0:root:/root:/bin/ash|' "$PASSWD_FILE"
    else
        echo "Root's home directory is already set to /root."
    fi
}

# Function to mount necessary filesystems
mount_filesystems() {
    echo "Mounting /proc, /sys, and /dev..."
    mount -t proc /proc "$ROOTFS_DIR/proc"
    mount --rbind /sys "$ROOTFS_DIR/sys"
    mount --rbind /dev "$ROOTFS_DIR/dev"
}

# Function to unmount filesystems (to be called after exiting chroot)
unmount_filesystems() {
    echo "Unmounting /proc, /sys, and /dev..."
    umount -l "$ROOTFS_DIR/proc" || true
    umount -l "$ROOTFS_DIR/sys" || true
    umount -l "$ROOTFS_DIR/dev" || true
}

# Function to configure DNS inside the chroot
configure_dns() {
    echo "Configuring DNS inside the chroot environment..."
    # Create or overwrite resolv.conf with Google's DNS servers
    cat > "$ROOTFS_DIR/etc/resolv.conf" <<EOF
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
}

# Function to set environment variables for chroot
prepare_chroot_env() {
    echo "Setting up environment variables for chroot..."
    # Optional: Copy essential environment variables
    mkdir -p "$ROOTFS_DIR/etc/profile.d"
    echo "export HOME=/root" > "$ROOTFS_DIR/etc/profile.d/home.sh"
}

# Function to cleanup the rootfs tarball after extraction
cleanup_rootfs() {
    if [ -f "$TARBALL" ]; then
        echo "Removing rootfs tarball ($TARBALL)..."
        rm -f "$TARBALL"
        echo "Rootfs tarball removed."
    else
        echo "Rootfs tarball ($TARBALL) does not exist. Skipping removal."
    fi
}

# Trap to ensure filesystems are unmounted on script exit
trap unmount_filesystems EXIT INT TERM

# Main execution
download_alpine
extract_alpine
cleanup_rootfs      # Remove the tarball after extraction
setup_root_home
configure_passwd
mount_filesystems
configure_dns
prepare_chroot_env

echo "Entering Alpine chroot environment..."
# Use chroot with the HOME environment variable set to /root
chroot "$ROOTFS_DIR" /bin/ash -l

# After exiting chroot, the trap will unmount the filesystems
echo "Exited Alpine chroot environment."

exit 0
```

We should automatically cd into /root when we run the chroot