Skip to content

Instantly share code, notes, and snippets.

@bahamat
Last active March 19, 2020 00:07
Show Gist options
  • Save bahamat/33349eb5cd230ae479b2e8f02e987c4c to your computer and use it in GitHub Desktop.
Save bahamat/33349eb5cd230ae479b2e8f02e987c4c to your computer and use it in GitHub Desktop.
chroot in lx brand zone
#!/bin/bash
# MIT License.
# This isn't meant to be run as a script exactly, but github has better syntax hilighting if I pretend.
chr=${PWD}/testroot
mkdir -p $chr/{bin,lib,lib64,native,var}
cd $chr
cp -v /bin/{bash,touch,ls,rm} $chr/bin
list=(
$(ldd /bin/bash | egrep -o '/lib.*\.[0-9]')
$(ldd /bin/touch | egrep -o '/lib.*\.[0-9]')
$(ldd /bin/ls | egrep -o '/lib.*\.[0-9]')
$(ldd /bin/rm | egrep -o '/lib.*\.[0-9]')
)
list=( $(tr ' ' '\n' <<< "${list[@]}" | sort -u | tr '\n' ' ') )
for i in ${list[@]} ; do cp -v --parents "$i" "${chr}"; done
/native/usr/sbin/mount -O -F lofs /native ${chr}/native/
cp -v --parents /var/ld/64/ld.config $chr
# You're ready, now run it.
chroot $chr bin/bash
@bahamat
Copy link
Author

bahamat commented Feb 6, 2020

To prune the chroot, make sure to unmount /native first.

umount ${chr:?}/native
rm -rf ${chr:?}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment