chroot demo

chroot demo

# Create a minimal environment
mkdir /tmp/jail
mkdir /tmp/jail/{bin,lib,lib64}

# Copy essential binaries
cp /bin/bash /tmp/jail/bin/
cp /bin/ls /tmp/jail/bin/
cp /bin/ps /tmp/jail/bin/

# Copy required libraries
ldd /bin/bash | grep -o '/lib[^ ]*' | xargs -I {} cp {} /tmp/jail/lib/

# Enter the chroot
sudo chroot /tmp/jail /bin/bash

# Inside chroot, try:
ps aux  # You'll see all processes (not isolated!)

A longer example of that that grep & xargs pipe operation is doing

ldd /bin/bash

# this will list the dependencies, copy all the thingies that have paths

cp /lib/aarch64-linux-gnu/libtinfo.so.6 /lib/aarch64-linux-gnu/libc.so.6 /lib/ld-linux-aarch64.so.1 /my-new-root/lib

References