|
| 1 | +--- |
| 2 | +title: how to connect the vscode ssh remote to a deprecated os |
| 3 | +date: 2025-08-25 |
| 4 | +categories: [Environment] |
| 5 | +tags: [vim] # TAG names should always be lowercase |
| 6 | +published: true |
| 7 | +--- |
| 8 | + |
| 9 | +Problem: I want to use vsocde (1.103) remote pack to connect my remote host server (x86_64, 18.04, glibc 2.27), but that is not supported by VS Code (OSes that don't have glibc >= 2.28 and libstdc++ >= 3.4.25) via the Remote - SSH extension. |
| 10 | + |
| 11 | +References: |
| 12 | +- [stack overflow1](https://stackoverflow.com/questions/79561735/using-custom-sysroot-for-vscode-remote-ssh-server-does-not-work-in-version-1-99) |
| 13 | +- [sysroot build](https://github.com/ursetto/vscode-sysroot) |
| 14 | + |
| 15 | +# Process |
| 16 | + |
| 17 | +Over view of the whole idea |
| 18 | +``` |
| 19 | +Your System: VS Code Sysroot: |
| 20 | +/lib/libc.so.6 ~/.vscode-server/sysroot/lib/libc.so.6 |
| 21 | +(glibc 2.27) (glibc 2.28) |
| 22 | + ↑ ↑ |
| 23 | +Used by system apps Used only by VS Code |
| 24 | +``` |
| 25 | +## build toolchain for the sysroot |
| 26 | +- clone the repo and better to have a docker env to execute them. |
| 27 | +```shell |
| 28 | +# Clone the repository |
| 29 | +git clone https://github.com/ursetto/vscode-sysroot.git |
| 30 | +cd vscode-sysroot |
| 31 | +# Build the sysroot (this takes 15-30 minutes) |
| 32 | +make |
| 33 | +# we'll get a toolchain/vscode-sysroot-x86_64-linux-gnu.tgz under toolchain directory |
| 34 | +``` |
| 35 | +- unzip it and copy it to the vscode-server directory |
| 36 | + |
| 37 | +```shell |
| 38 | +# Create the directory |
| 39 | +mkdir -p ~/.vscode-server |
| 40 | +# Extract the sysroot |
| 41 | +tar zxf vscode-sysroot-x86_64-linux-gnu.tgz -C ~/.vscode-server |
| 42 | +# Copy the environment script |
| 43 | +cp sysroot.sh ~/.vscode-server/ |
| 44 | +# better to clear all the files under the directory before *.log, code*, ... |
| 45 | +``` |
| 46 | +- VS Code server uses patchelf during the installation process to consume the required libraries from the sysroot, so download it simply. |
| 47 | + |
| 48 | +```shell |
| 49 | +wget https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-x86_64.tar.gz |
| 50 | +# tar it and there is an executable bin in `bin/` |
| 51 | +# chmod it |
| 52 | +# put it to the system level `/usr` dir |
| 53 | +sudo cp bin/patchelf /usr/local/bin/ |
| 54 | +sudo chmod +x /usr/local/bin/patchelf |
| 55 | +``` |
| 56 | + |
| 57 | +## Put environmetal global vars related to vscode installation |
| 58 | +Create the following 3 environment variables: |
| 59 | +``` |
| 60 | +VSCODE_SERVER_CUSTOM_GLIBC_LINKER path to the dynamic linker in the sysroot (used for --set-interpreter option with patchelf) |
| 61 | +VSCODE_SERVER_CUSTOM_GLIBC_PATH path to the library locations in the sysroot (used as --set-rpath option with patchelf) |
| 62 | +VSCODE_SERVER_PATCHELF_PATH path to the patchelf binary on the remote host |
| 63 | +``` |
| 64 | +- we need put them in the system level config, rather than the current user's `bashrc` --> tried but failed. |
| 65 | +```shell |
| 66 | +# Create the environment file |
| 67 | +sudo tee /etc/profile.d/vscode-sysroot.sh << 'EOF' |
| 68 | +VSCODE_SERVER_PATCHELF_PATH=/usr/local/bin/patchelf |
| 69 | +VSCODE_SERVER_CUSTOM_GLIBC_LINKER=/home/qingchen/.vscode-server/sysroot/lib/ld-linux-x86-64.so.2 |
| 70 | +VSCODE_SERVER_CUSTOM_GLIBC_PATH=/home/qingchen/.vscode-server/sysroot/lib:/home/qingchen/.vscode-server/sysroot/usr/lib |
| 71 | +
|
| 72 | +export VSCODE_SERVER_PATCHELF_PATH |
| 73 | +export VSCODE_SERVER_CUSTOM_GLIBC_LINKER |
| 74 | +export VSCODE_SERVER_CUSTOM_GLIBC_PATH |
| 75 | +EOF |
| 76 | +``` |
| 77 | + |
| 78 | +## reconnect with remote ssh |
| 79 | + |
| 80 | +Got a warning popup (and notice bar) that the target OS was not supported, but then everything worked. |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
0 commit comments