Late to answer; the project originally mentioned is almost certainly over; and no one else is likely to ever have this need again. But oh well, here goes ...
Create a chroot jail. Do the following as root:
- Create a location for the chroot:
sudo mkdir /newroot; cd /newroot
- Recreate/bindmount all of the necessary directories inside
newroot
:
mkdir usr; mount --bind /usr usr
mkdir etc; mount --bind /etc etc
mkdir root
mkdir -p /home/user; mount --bind /home/user home/user
(substitute the default username for the WSl instance).
mkdir var; mount --bind /var var
mkdir dev; mount --bind /dev dev
- And so on for any other required directories.
- Pay attention to the root directory symlinks in your distribution. For instance, at least Ubuntu would also require:
ln -s usr/lib lib
ln -s usr/lib32 lib32
- and so on ...
mount -t proc none proc
mkdir init
(The customer required init directory rather than the "real" root init file)
Now, to launch the wsl session, set up a shortcut for wsl -u root -e sh -c "cd /newroot; exec /usr/sbin/chroot /newroot/" su - username
. Substitute the default username
of course.
This will launch the user into a chroot jail with just the directory structure you have selected, which obviously does not include the init
file, but your init
directory instead.
/init
? Can you change the name of the directory at least?/init
as the initramfs main executable's path since 2005. Creating a custom directory there was already a somewhat bad choice.