Emacs standing alone on a Linux Kernel
source link: http://informatimago.free.fr/i/linux/emacs-on-user-mode-linux.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Emacs standing alone on a Linux Kernel
Emacs standing alone on a Linux Kernel
The purpose of this experiment is to see how emacs can work alone over a linux kernel.
The only external tool needed is mount
.
This "root_fs_emacs" could be used as a normal partition or on live CD, but for this experiment, we'll run it with User Mode Linux.
1- Initialize a root_fs with at least 150 MB
cd ~/uml dd if=/dev/zero of=root_fs_emacs bs=1k count=200k yes y|mke2fs root_fs_emacs mkdir /emacs mount -o loop root_fs_emacs /emacs cd /emacs ln -s . emacs # we create this link to simplify config --prefix of emacs cp -a /dev dev # we boldly copy the whole /dev mkdir etc sbin tmp # some other directories not installed by emacs cat >etc/fstab <<EOF /dev/ubd0 / ext2 defaults 0 1 EOF
2- Compile an emacs without X and statically
cd ~/src tar jxvf emacs-21.3.tar.bz2 cd emacs-21.3 CFLAGS=-static LDFLAGS=-static ./configure --without-x --prefix=/emacs make && make install
3- Install emacs as /sbin/init
cd /emacs ln bin/emacs sbin/init cat >.emacs <<EOF (message "init starting") (setq auto-save-interval 0) (defun shutdown () (interactive) (when (yes-or-no-p "Really shut down the system? ") ;; actually, kill-emacs signals emacs ie. init, which makes linux panic. (kill-emacs))) (global-set-key "\C-x\C-c" 'shutdown) (global-set-key "^\" 'keyboard-quit) ;; strangely, C-g does not work. (call-process "/bin/mount" nil "*log*" t "-n" "-o" "rw,remount" "/") (if (file-exists-p "/etc/mtab") (delete-file "/etc/mtab")) (call-process "/bin/mount" nil "*log*" t "-f" "/dev/ubd0" "/") (message "init done") EOF
4- Compile mount statically
cd ~/src tar jxvf util-linux-2.12a.tar.bz2 cd util-linux-2.12a CFLAGS=-static LDFLAGS=-static ./configure make && install -m 755 mount/umount mount/mount /emacs/bin/
5- Boot linux
cd ~/uml umount /emacs linux ubd0=root_fs_emacs
Now, you can launch an emacs shell with
M-x eshell RET ls -l RET
and get:
File Edit Options Buffers Tools Help Welcome to the Emacs shell / # ls -l total 21 drwxr-xr-x 2 0 0 1024 Jul 26 08:42 bin drwxr-xr-x 1 0 0 0 Jan 1 1970 dev lrwxrwxrwx 1 0 0 1 Jul 26 08:11 emacs -> . drwxr-xr-x 2 0 0 1024 Jul 26 09:20 etc drwxr-xr-x 2 0 0 2048 Jul 26 08:11 info drwxr-xr-x 3 0 0 1024 Jul 26 08:11 libexec drwx------ 2 0 0 12288 Jul 26 08:10 lost+found drwxr-xr-x 3 0 0 1024 Jul 26 08:10 man drwxr-xr-x 2 0 0 1024 Jul 26 08:11 sbin drwxr-xr-x 3 0 0 1024 Jul 26 08:10 share drwxr-xr-x 2 0 0 1024 Jul 26 09:15 tmp / # --1-:---F1 *eshell* (EShell)--L20--All---------------------
Of course, quite a number of syscalls are missing from emacs (not available as elisp primitives), so as it is, it would be hard enough to do EVERYTHING with emacs, but this is a starting point.
Another, more realistic, alternative would be to use a Common-Lisp implementation with a FFI and portable Hemlock.
Emacs as shell
Emacs can easily be used as shell:
echo /usr/bin/emacs >> /etc/shells chsh -s /usr/bin/emacs GOODUSER echo '(setenv "SHELL" "/bin/bash")' >> ~GOODUSER/.emacs # in case the user wants to use M-x shell # [ I use rather: (setenv "SHELL" "/usr/bin/clisp") ] echo '(eshell)' >> ~GOODUSER/.emacs # to launch eshell automatically. # One could use: (dired default-directory) instead... su - GOODUSER # Hosanna!
Recommend
-
104
gijit is a just-in-time trace-compiled golang REPL. Standing on the shoulders of giants (GopherJS and LuaJIT).
-
59
Last month, I sat down and decided to at the very least attempt to fix our XHCI (USB 3 host controller) bus driver. Issues with it have been the most significant problem users have been facing, as most hardware made post-2012...
-
42
README.md bosh-bootloader Also known as bbl (pronounced: "bubble"), bosh-bootloader is a command line utility for stand...
-
22
attack2jira The MITRE ATT&CK Framework is a great tool security teams can leverage to, among many other things, measure the security posture of an organization against tactics and techniques used in the wild...
-
15
Located in the heart of Latin America’s largest city, the Uber Sao Paulo Tech Center was founded in late 2018 as a compa...
-
8
Apple responds to Facebook: it’s about standing up for users
-
7
‘Cope Cages’ on Busted Tanks Are a Symbol of Russia’s Military FailuresThe Russian military used improvised slat armor on its tanks in an attempt to protect them from getting blown up. It’s not going well.
-
7
1、httpd简介? http是Apache超文本传输协议服务器的主程序。它是一个独立的后台进程,能够处理请求的子进程和线程。 http常用用的两个版本是httpd-2.2和httpd-2.4 CentO...
-
3
Linux 用户和组 1、用户和组的概念 用户的作用: Authentication:认证 Authorization:授权 Accouting:审计 用户存在的最终目的: 为了实现资...
-
8
Have you ever hit an annoying Firefox bug and want to fix it? You’re rig...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK