Skip to content

Instantly share code, notes, and snippets.

@jinliming2
Last active February 3, 2023 17:05
Show Gist options
  • Save jinliming2/3996caabe113717038f7147ee204b754 to your computer and use it in GitHub Desktop.
Save jinliming2/3996caabe113717038f7147ee204b754 to your computer and use it in GitHub Desktop.
Steam in Chroot

You may follow Gentoo Wiki (or other guides) to install steam in chroot first. But you may failed to launch games like Dota2, because steam is using something called soldier and bwrap.

The steam.sh below can make soldier and bwrap work by mount chroot_dir twice. this works fine for me.

Save steam.sh file to /usr/local/bin/steam, so you can run steam command in terminal to launch steam, or add steam deeplink like steam steam://install/xxx.

To start steam without ask sudo password, add this to your sudoers file:

%wheel ALL=(ALL) NOPASSWD: /usr/local/bin/steam
#!/bin/bash
# Enable log
# exec 1>/dev/shm/steam.log 2>&1
# Check Root permission
if [[ $EUID -ne 0 ]]; then
sudo $0 $@
exit $?
fi
# steam chroot bits
chroot_arch="linux64"
# steam chroot directory, you may change this
chroot_dir="/opt/steam"
# user home directory path outside chroot, you may need to change this
user_home="/home/liming"
if mountpoint -q "${chroot_dir}"; then
# steam folder already mounted, maybe steam is already running
"${chroot_arch}" chroot "${chroot_dir}" su -c "steam -no-cef-sandbox ${@}" steam
exit 0
fi
# umount the chroot directories when steam exits
cleanup() {
for mnt in /home/steam/.config/pulse /var/lib/dbus /tmp /run /dev /sys /proc; do
umount -vl "${chroot_dir}${mnt}"
done
# umount twice
umount -vl "${chroot_dir}"
umount -vl "${chroot_dir}"
}
trap cleanup EXIT
# mount the chroot directories, first three lines are the magic to make `soldier` and `bwrap` work in chroot
mount -v --bind "${chroot_dir}" "${chroot_dir}"
mount -v --make-private "${chroot_dir}"
mount -v --bind "${chroot_dir}" "${chroot_dir}"
mount -v --types proc /proc "${chroot_dir}/proc"
for mnt in /sys /dev /run /tmp /var/lib/dbus; do
mount -v --rbind "${mnt}" "${chroot_dir}${mnt}"
mount -v --make-rslave "${chroot_dir}${mnt}"
done
mount -v --rbind "${user_home}/.config/pulse" "${chroot_dir}/home/steam/.config/pulse"
mount -v --make-rslave "${chroot_dir}/home/steam/.config/pulse"
# Use cookie for X auth
cp --preserve "${user_home}/.Xauthority" "${chroot_dir}/home/liming/.Xauthority"
# chroot, substitute user, and start steam
#"${chroot_arch}" chroot "${chroot_dir}" su -c '/bin/bash -l' steam
#"${chroot_arch}" chroot "${chroot_dir}" su -c '/bin/bash -l' root
"${chroot_arch}" chroot "${chroot_dir}" su -c "steam -no-cef-sandbox ${@}" steam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment