Skip to content

Instantly share code, notes, and snippets.

@thearyanahmed
Created November 3, 2024 18:57
Show Gist options
  • Save thearyanahmed/b5e5a3cbee4e2de779a6d97b318e8b68 to your computer and use it in GitHub Desktop.
Save thearyanahmed/b5e5a3cbee4e2de779a6d97b318e8b68 to your computer and use it in GitHub Desktop.
sudo mkdir -p /tmp/rootfs
sudo mkdir -p /tmp/container

# Mount root filesystem in read-only mode

sudo mount --bind -o readonly /tmp/rootfs /tmp/container

# Mount the proc filesystem

sudo mount -t proc proc /tmp/rootfs/proc

# Verify that /tmp/rootfs/bin/bash exists or not

ldd /tmp/rootfs/bin/bash # Check for required libraries using ldd

# add necessary stuff for bash
sudo mkdir -p /tmp/rootfs/lib/x86_64-linux-gnu
sudo mkdir -p /tmp/rootfs/lib64
sudo cp /lib64/ld-linux-x86-64.so.2 /tmp/rootfs/lib64/
sudo cp /lib/x86_64-linux-gnu/libtinfo.so.6 /tmp/rootfs/lib/x86_64-linux-gnu/
sudo cp /lib/x86_64-linux-gnu/libc.so.6 /tmp/rootfs/lib/x86_64-linux-gnu/

# sanity check
ls -l /tmp/rootfs/lib64/ld-linux-x86-64.so.2
ls -l /tmp/rootfs/lib/x86_64-linux-gnu/libtinfo.so.6
ls -l /tmp/rootfs/lib/x86_64-linux-gnu/libc.so.6

sudo unshare -pf --mount-proc=/tmp/container/proc/ chroot /tmp/rootfs /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment