Total Pageviews

Friday 25 June 2021

ish, Linux shell for iOS


https://ish.app/

https://apps.apple.com/us/app/ish-shell/id1436902243 (ios上的 安装地址)

A project to get a Linux shell running on iOS, using usermode x86 emulation and syscall translation.

For the current status of the project, check the issues tab, and the commit logs.

Hacking

This project has a git submodule, make sure to clone with --recurse-submodules or run git submodule update --init after cloning.

You'll need these things to build the project:

  • Python 3
    • Meson (pip3 install meson)
  • Ninja
  • Clang and LLD (on mac, brew install llvm, on linux, sudo apt install clang lld or sudo pacman -S clang lld or whatever)
  • sqlite3 (this is so common it may already be installed on linux and is definitely already installed on mac. if not, do something like sudo apt install libsqlite3-dev)
  • libarchive (brew install libarchivesudo port install libarchivesudo apt install libarchive-dev) TODO: bundle this dependency

Build for iOS

Open the project in Xcode, open iSH.xcconfig, and change ROOT_BUNDLE_IDENTIFIER to something unique. Then click Run. There are scripts that should do everything else automatically. If you run into any problems, open an issue and I'll try to help.

Build command line tool for testing

To set up your environment, cd to the project and run meson build to create a build directory in build. Then cd to the build directory and run ninja.

To set up a self-contained Alpine linux filesystem, download the Alpine minirootfs tarball for i386 from the Alpine website and run ./tools/fakefsify, with the minirootfs tarball as the first argument and the name of the output directory as the second argument. Then you can run things inside the Alpine filesystem with ./ish -f alpine /bin/login -f root, assuming the output directory is called alpine. If tools/fakefsify doesn't exist for you in your build directory, that might be because it couldn't find libarchive on your system (see above for ways to install it.)

You can replace ish with tools/ptraceomatic to run the program in a real process and single step and compare the registers at each step. I use it for debugging. Requires 64-bit Linux 4.11 or later.

Logging

iSH has several logging channels which can be enabled at build time. By default, all of them are disabled. To enable them:

  • In Xcode: Set the ISH_LOG setting in iSH.xcconfig to a space-separated list of log channels.
  • With Meson (command line tool for testing): Run meson configure -Dlog="<space-separated list of log channels>.

Available channels:

  • strace: The most useful channel, logs the parameters and return value of almost every system call.
  • instr: Logs every instruction executed by the emulator. This slows things down a lot.
  • verbose: Debug logs that don't fit into another category.
  • Grep for DEFAULT_CHANNEL to see if more log channels have been added since this list was updated.

A note on the JIT

Possibly the most interesting thing I wrote as part of iSH is the JIT. It's not actually a JIT since it doesn't target machine code. Instead it generates an array of pointers to functions called gadgets, and each gadget ends with a tailcall to the next function; like the threaded code technique used by some Forth interpreters. The result is a speedup of roughly 3-5x compared to pure emulation.

Unfortunately, I made the decision to write nearly all of the gadgets in assembly language. This was probably a good decision with regards to performance (though I'll never know for sure), but a horrible decision with regards to readability, maintainability, and my sanity. The amount of bullshit I've had to put up with from the compiler/assembler/linker is insane. It's like there's a demon in there that makes sure my code is sufficiently deformed, and if not, makes up stupid reasons why it shouldn't compile. In order to stay sane while writing this code, I've had to ignore best practices in code structure and naming. You'll find macros and variables with such descriptive names as ss and s and a. Assembler macros nested beyond belief. And to top it off, there are almost no comments.

So a warning: Long-term exposure to this code may cause loss of sanity, nightmares about GAS macros and linker errors, or any number of other debilitating side effects. This code is known to the State of California to cause cancer, birth defects, and reproductive harm.


from https://github.com/ish-app/ish

------------------------------------------

如何在iOS上运行Linux系统

iSH是一个活跃的项目,用于在iOS上运行Linux Shell。它提供了一个Alpine Linux环境,并带有apk软件包管理器。该应用程序依赖于用户模式x86仿真。伯衡君下载试用后,发现其功能真的很强大,好像是同时拥有了Linux电脑和iOS双系统,不错不错。您可以从App Store下载iSH。新安装的默认情况下包括功能齐全的apk。现有的应用程序用户可能需要按照文档中的步骤手动安装apk。

内容详情

首先从App Store安装iSH。启动应用程序,您将直接进入Alpine Linux终端环境。


 

您可以开始运行熟悉的Linux命令!您可以使用BusyBox提供的所有Unix实用程序,包括cat,grep,ls,sed和wget等。

iSH提供了自己的键盘图标条,以简化触摸屏终端的使用。该条左侧的四个按钮分别是Tab键,Control键,Escape键和箭头键。在您希望光标导航的方向上滑动箭头键按钮。

设置功能

设置菜单可让您自定义一些选项。 “外观”页面允许您设置字体并在浅色和深色主题之间切换。在“应用程序图标”页面上,可以从多个应用程序图标中进行选择。通过此选择,您可以将iSH与iOS主屏幕上其他应用程序的视觉风格进行匹配。

外部键盘使您可以控制iSH处理通过蓝牙或USB适配器连接的物理键盘的方式。除了iOS的内置重新映射选项之外,您还可以将选项和反引号键重新映射到iSH元和转义键。您可以通过启用“使用外部键盘隐藏”设置来隐藏iSH的图标栏(使用外部键盘时)。

文件系统

iSH支持使用多个文件系统。前往设置菜单中的“文件系统”页面进行管理。首先,您将看到一个包含内置Alpine安装的“默认”文件系统。

按“浏览文件”以在iOS的“文件”应用中打开文件系统。这可以帮助您快速将文件从iSH复制到iOS设备上的其他位置。


 

您可以使用“导出”选项导出整个文件系统。可以使用“文件系统”主页面上的“导入”按钮将文件系统导入iSH。
文件系统的实际用例是允许您运行多个独立的安装。

您可以尝试使用Alpine的“迷你根文件系统” –下载该文件,然后将其导入,然后按“从此文件系统启动”以使用该文件系统重新启动iSH。通过选择菜单项并再次选择“从此文件系统启动”,切换回默认文件系统。

添加包

您可以使用常规apk命令在iSH环境中管理软件包。

apk update
# Upgrade existing installed packages
apk upgrade
# Install SSH
apk add openssh
# Remove SSH
apk del openssh
 

请注意,iSH默认使用其自己的程序包存储库。通过确保应用完全独立,该应用可以通过应用商店审查。

如果愿意,可以切换到正式的Alpine Linux存储库。这使您可以访问Alpine软件的完整列表。许多软件包将在Alpine主存储库中提供比iSH存储库中提供的软件包更高的版本。

grep -v "file:///ish/apk/" /etc/apk/repositories | dd of=/etc/apk/repositories bs=4194304
echo https://dl-cdn.alpinelinux.org/alpine/v3.12/main >> /etc/apk/repositories
echo https://dl-cdn.alpinelinux.org/alpine/v3.12/community >> /etc/apk/repositories
 

运行以上命令,用Alpine Linux提供的存储库替换iSH的/ ish / apk伪文件系统的内容。然后,您需要运行apk更新以获取新的软件包列表。

使用ssh

您可以使用apk add openssh安装OpenSSH,客户端将立即工作,可以尝试ssh me @ myserver。
要将iOS设备用作SSH服务器,请运行以下命令:

 ssh-keygen -A

passwd
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
sshd
 

这将生成SSH主机密钥,并提示您为root用户设置密码。调用sshd可执行文件以启动SSH服务器。现在,您可以以root用户身份连接到设备。

默认情况下,iSH不支持自动启动服务。您可以通过将/etc/inittab的第三行编辑为:: sysinit:/ sbin / openrc来进行设置。下次运行rc-update add sshd,以使SSH服务器在启动iSH会话时自动启动。

运行Web服务器

如SSH示例所示,iSH使用您设备的网络堆栈。您可以托管一个网络服务器,您可以在其他设备上进行浏览。

运行apk install apache2以添加Apache。使用httpd启动Apache进程。接下来,在网络浏览器中访问iOS设备的IP地址-您应该看到Apache的默认“It works!”文本。

iSH目前不支持在后台运行。这意味着您在使用iPhone时无法切换到Safari并浏览网页。在iPad上,可以以拆分视图打开浏览器– iSH在屏幕的一侧保持活动状态。

可以按照常规方式配置Apache。您可以在/etc/apache2/httpd.conf中找到其配置文件。默认的文档根目录-/var/www/localhost/htdocs是从中提供网页的。

您现在在iOS设备上运行Alpine Linux环境。添加对您的工作有意义的软件包。可以使用的软件列表越来越多,其中包括Unix staples和完整的编程语言。 Node.js,Python,PHP,Ruby和Git均可运行。

并非所有软件包都可以。进行尚未翻译的系统调用的软件将崩溃。由于iSH是仿真器,因此性能有时可能也未达到标准。

如果要使用图形应用程序,则可以运行VNC服务器。 iSH Wiki中提供了详细步骤。通过图形工作负载,性能限制将变得很清楚,但是在技术上是可行的。该过程涉及安装xorg-server,设置无头配置,然后添加.xinitrc文件以定义要使用的窗口管理器。使用轻量级的窗口管理器(例如i3),您将获得最佳效果。

总结

iSH似乎已成为开发人员和系统管理员必备的iOS应用。已经有像a-Shell这样的高质量应用程序,它们提供基本的Unix工具,以及像Termius这样的SSH客户端,它们使您可以连接到远程Linux机器。 iSH是迄今为止最完整的解决方案,它提供了一个Linux环境,该环境支持越来越多的流行软件。

在iPhone或iPad上使用iSH,无论您身在何处,都可以使用熟悉的x86 Linux软件。将其与外部键盘配对后,您便拥有了可以真正取代笔记本电脑的便携式生产力设备。

 

 

 

 

 

 

 

 

 

 

No comments:

Post a Comment