<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<HTML>
<HEAD>
  <TITLE>Emacs standing alone on a Linux Kernel</TITLE>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
  <META NAME="author" CONTENT="Pascal J. Bourguignon">
  <META HTTP-EQUIV="Reply-to" NAME="Reply-to" CONTENT="pjb@informatimago.com">
  <META HTTP-EQUIV="Description" NAME="description" CONTENT=
  "Nano How-To explaining how to setup a root file system with only emacs.">
  <META NAME="keywords" CONTENT="User Mode Linux,Linux,Emacs">
<link rel="stylesheet" type="text/css" href="../default.css"></HEAD>

<BODY>
  <!--TOP-BEGIN-->
<!-- This section is automatically generated by html-update, -->
<!-- from data in 'node.el'.    Please, do not edit it here. -->
<DIV CLASS="TOP"></DIV>
<!--TOP-END-->
<!--MENU-BEGIN-->
<!-- This section is automatically generated by html-update, -->
<!-- from data in 'node.el'.    Please, do not edit it here. -->
<DIV CLASS="MENU"><HR><P>|
 <A CLASS="button" HREF="../toc.html">Contents</a> |
 <A CLASS="button" HREF="../index.html">Home</a> |
 <A CLASS="button" HREF="chrooted-ssh-cvs.html">Previous</a> |
 <A CLASS="button" HREF="../develop/sms/index.html">Up</a> |
 <A CLASS="button" HREF="../develop/abalone/index.html">Next</a> |
</P><HR></DIV>
<!--MENU-END-->

<p><a href="#shell">Jump to Emacs as shell</a>

<h1>Emacs standing alone on a Linux Kernel</h1>

<p>The purpose of this experiment is to see how emacs can work alone
   over a linux kernel.

<p>The only external tool needed is <code>mount</code>.

<p>This "root_fs_emacs" could be used as a normal partition or on live CD,
   but for this experiment, we'll run it with
   <a href="http://user-mode-linux.sourceforge.net">User Mode Linux</a>.

<h2>1- Initialize a root_fs with at least 150 MB</h2>
<pre>
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 &gt;etc/fstab &lt;&lt;EOF
/dev/ubd0 / ext2 defaults  0 1
EOF
</pre>

<h2>2- Compile an emacs without X and statically</h2>
<pre>
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
</pre>

<h2>3- Install emacs as /sbin/init</h2>
<pre>
cd /emacs
ln bin/emacs sbin/init
cat &gt;.emacs &lt;&lt;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
</pre>

<h2>4- Compile mount statically</h2>
<pre>
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/
</pre>

<h2>5- Boot linux</h2>
<pre>
cd ~/uml
umount /emacs
linux ubd0=root_fs_emacs
</pre>

<p>Now, you can launch an emacs shell with <pre> M-x eshell RET
ls -l RET
</pre>
<p>and get: <pre>
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---------------------
</pre>

<p>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.

<p>Another, more realistic, alternative would be to use a Common-Lisp
implementation with a FFI  and portable Hemlock.



<h1><a name="shell"></a>Emacs as shell</h1>

<p>Emacs can easily be used as shell:
<pre>
     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!
</pre>


  <!--MENU-BEGIN-->
<!-- This section is automatically generated by html-update, -->
<!-- from data in 'node.el'.    Please, do not edit it here. -->
<DIV CLASS="MENU"><HR><P>|
 <A CLASS="button" HREF="../toc.html">Contents</a> |
 <A CLASS="button" HREF="../index.html">Home</a> |
 <A CLASS="button" HREF="chrooted-ssh-cvs.html">Previous</a> |
 <A CLASS="button" HREF="../develop/sms/index.html">Up</a> |
 <A CLASS="button" HREF="../develop/abalone/index.html">Next</a> |
</P><HR></DIV>
<!--MENU-END-->
  <!--BOTTOM-BEGIN-->
<!-- This section is automatically generated by html-update, -->
<!-- from data in 'node.el'.    Please, do not edit it here. -->
<DIV CLASS="BOTTOM">
<hr><code><small>
 | <a href="http://www.informatimago.com//linux/emacs-on-user-mode-linux.html">Mirror on informatimago.com</a>
 | <a href="http://informatimago.free.fr/i//linux/emacs-on-user-mode-linux.html">Mirror on free.fr</a>
 | </small></code>

<BR><SMALL>
      <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-html401"
          alt="Valid HTML 4.01!" height="31" width="88"></a>
   </SMALL>
</DIV>
<!--BOTTOM-END-->
</BODY>
</HTML>
<!-- emacs-on-user-mode-linux.html    ==                     ==          -->
ViewGit