# 1. Introduction Starting from VS Code release 1.99, some servers (such as white, black and red who fail the requirements, including glibc >= 2.28 and libstdc++ >= 3.4.25) can not be accessed through VS Code remotely. The official provides a temporary patch to fix this, though an annoying banner is still present. To make it short, software `crosstool-ng` can generate a directory `sysroot` containing library file needed. Then `patchelf` can help VS Code server consume the required files during the installation process. Finally a script `sysroot.sh` can tell VS Code and patchelf where to find all those file. First, I will show users how to set up. Next, I will show what I have done for those who are interested. # 2. Usage For users, what they need to do is just adding those lines to their .bashrc or .cshrc file. ``` # Patchelf / VS Code source /home/usr/share/sysroot/sysroot.sh ``` or ``` # Patchelf / VS Code source /home/usr/share/sysroot/sysroot.csh ``` That's all if you are a user. For developers, the next chapter may be helpful. # 3. Configuration - The main instruction: [修复 远程主机不满足运行VS Code服务器的先决条件](https://remrin.xlog.app/vscode-remote-fix) - The repo used: [GitHub - ursetto/vscode-sysroot](https://github.com/ursetto/vscode-sysroot) - Official version: [Remote Development FAQ](https://code.visualstudio.com/docs/remote/faq#_can-i-run-vs-code-server-on-older-linux-distributions) ## 3.1. Install crosstool-ng [crosstool-NG](https://crosstool-ng.github.io/docs/) is a tool to generate required library files `sysroot` ``` sudo apt-get update sudo apt-get install -y gcc g++ gperf bison flex texinfo help2man make libncurses5-dev python3-dev autoconf automake libtool libtool-bin gawk wget bzip2 xz-utils unzip patch rsync meson ninja-build wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.26.0.tar.bz2 tar -xjf crosstool-ng-1.26.0.tar.bz2 cd crosstool-ng-1.26.0 ./configure --prefix=/home/usr/share/crosstool-ng make make install ``` ## 3.2. Generate sysroot `sysroot` is a directory containing required library files. ``` sysroot/ ├── etc ├── lib ├── lib64 -> lib ├── sbin ├── sysroot.sh ├── usr └── var ``` Maybe you shall remove some experiment variables first, such as `LD_LIBRARY_PATH`, otherwise some unexpected errors. ``` mkdir toolchain-dir cd toolchain-dir # download the config file from https://github.com/ursetto/vscode-sysroot/blob/main/x86_64-gcc-8.5.0-glibc-2.28.config cp x86_64-gcc-8.5.0-glibc-2.28.config .config ct-ng build ``` The directory `x86_64-linux-gnu/x86_64-linux-gnu/sysroot` is what we needed. For the file `.config`, what's different from the official version are two variables `CT_LINUX_VERSION` and `CT_GLIBC_MIN_KERNEL`. Microsoft set them to `4.19.287`, while they shall be `3.10` for Centos 7. For Ubuntu 18.04 with kernel version `4.15.0`, `3.10` works. ## 3.3. Download patchelf [patchelf](https://github.com/NixOS/patchelf) is a software to help VS Code server to find related library files. The binary file itself works well. I put it into `sysroot`, following `ursetto`'s instruction. Some steps are necessary due to file permission problems. ``` cd x86_64-linux-gnu/x86_64-linux-gnu/sysroot/usr chmod 755 bin cd bin # download binary file from https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-x86_64.tar.gz tar -xvf patchelf-0.18.0-x86_64.tar.gz cp patchelf-0.18.0/bin/patchelf ./ cd .. chmod -R 555 bin ``` ## 3.4. Add a source file This is a script for use's convenience. It defines three variables to help VS Code to find the files. I put the script in `sysroot` `sysroot.sh` ```sh # Path to the dynamic linker in the sysroot (used for --set-interpreter option with patchelf) export VSCODE_SERVER_CUSTOM_GLIBC_LINKER=/home/usr/share/sysroot/lib/ld-linux-x86-64.so.2 # Path to the library locations in the sysroot (used as --set-rpath option with patchelf) export VSCODE_SERVER_CUSTOM_GLIBC_PATH=/home/usr/share/sysroot/usr/lib:/home/usr/share/sysroot/lib # Path to the patchelf binary on the remote host export VSCODE_SERVER_PATCHELF_PATH=/home/usr/share/sysroot/usr/bin/patchelf ``` `sysroot.csh` ```csh # Path to the dynamic linker in the sysroot (used for --set-interpreter option with patchelf) setenv VSCODE_SERVER_CUSTOM_GLIBC_LINKER /home/usr/share/sysroot/lib/ld-linux-x86-64.so.2 # Path to the library locations in the sysroot (used as --set-rpath option with patchelf) setenv VSCODE_SERVER_CUSTOM_GLIBC_PATH /home/usr/share/sysroot/usr/lib:/home/usr/share/sysroot/lib # Path to the patchelf binary on the remote host setenv VSCODE_SERVER_PATCHELF_PATH /home/usr/share/sysroot/usr/bin/patchelf ``` ``` cd ../.. chmod 755 sysroot vi sysroot/sysroot.sh vi sysroot/sysroot.csh chmod 555 sysroot ``` ## 3.5. Something special Finally, I move `sysroot` to a public directory. ``` rsync -avz toolchain-dir/x86_64-linux-gnu/x86_64-linux-gnu/sysroot/ /home/usr/share/sysroot chown -R xuelab:xue /home/usr/share/sysroot ``` For users, they need to add those lines to their .bashrc or .cshrc file. ``` source /home/usr/share/sysroot/sysroot.sh source /home/usr/share/sysroot/sysroot.csh ```