📜 ⬆️ ⬇️

Boot into Vim or Vim with PID 1

Boot to Vim (boot window)

This is the answer to a great article from Pascal Bourguignon, in which he talks about how to run Emacs with PID 1 .

As we all know, nobody uses Emacs.
')
The proposal above seems to hint that this is the beginning of the next holy war. Please start. If you want to tell me something, all my contacts are in my blog.

In fact, joking aside. I think this is a great article, and after reading it, I wanted to see if I could do something similar with Vim. Not in Linux user mode, but in reality creating an ISO to boot. You can say, “boot into Vim”, if you so wish.

It is, indeed, quite simple. Compile Vim statically, set init= to boot, and you're done.

We will use a small (9Mb) distribution of the Tiny Core, Core edition and configure it so that the download goes straight to our statically assembled Vim.

We collect Vim


Please follow my other manual on how to build a statically linked Vim . As a result, you will receive an executable file that we will use later in this guide.

Training


You will need several tools to build the ISO, namely cpio , tar , gzip , advdef and mkisofs . They can most likely be installed using your package manager, if they are not already installed. Please do it for a start.

First, create a directory to build:

 mkdir vim-as-pid-1 cd vim-as-pid-1 


Also create a couple of directories to build an ISO:

 mkdir /tmp/isomount mkdir extract 


Download the latest version of Tiny Core, Core edition (without GUI):

 wget http://distro.ibiblio.org/tinycorelinux/5.x/x86/release/Core-current.iso 


Copy the files from the downloaded ISO:

 mount Core-current.iso /tmp/isomount/ -o loop,ro cp -a /tmp/isomount/boot /tmp/ 


These commands will create the /tmp/boot with the bootloader and the core.gz file. Do not forget to unmount it:

 umount /tmp/isomount 


We will use the /tmp/boot further when we put everything together in an ISO file.

Change ISO file



Go to the directory where core.gz will be extracted - the root directory of the file system:

 cd extract 


Use zcat and cpio to extract the file system root from core.gz :

 zcat /tmp/boot/core.gz | cpio -i -H newc -d 


We now have the extracted filesystem root directory:

 # ls bin dev etc home init lib linuxrc mnt opt proc root run sbin sys tmp usr var 


Place the Vim executable compiled in the previous step in the bin/ directory

 cp ~/vim bin/ 


You can also make different settings, for example, edit the message of the loader. It is located in a file named boot.msg in the /tmp/boot/isolinux/ directory:

 # vim /tmp/boot/isolinux/boot.msg ^L _ ( - Boot to Vim //\ Vim as Pid 1, because Awesome! v_/_ https://raymii.org/ Press <Enter> to begin or F2, F3, or F4 to view boot options. 


Change inittab



To load directly into Vim, we need to change the initialization configuration. Edit the following file:

 vim etc/inittab 


Change these lines:

 ::sysinit:/etc/init.d/rcS tty1::respawn:/sbin/getty 38400 tty1 


on:

 ::sysinit:/bin/vim tty1::respawn:/bin/vim 


We collect new ISO


Make sure that we are still in the directory named extract . Next, we’ll use the following command to build a new tinycore.gz file, which our ISO will use as initramfs :

 find | cpio -o -H newc | gzip -2 > ../tinycore.gz 


Copy it to a file called core.gz to the /tmp/boot , which we copied earlier:

 cp ../tinycore.gz /tmp/boot/core.gz 


Create a new directory for the files that will be in the new ISO:

 mkdir /tmp/newiso 


Copy the /tmp/boot directory into it:

 cp -a /tmp/boot /tmp/newiso/ 


We assemble ISO using mkisofs :

 cd /tmp/ mkisofs -l -J -R -V Boot_To_Vim -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -o Boot_to_Vim.iso newiso 


You now have a file in /tmp called Boot_to_Vim.iso :

 ls -la /tmp/Boot_to_Vim.iso -rw-r--r-- 1 root root 11044864 Sep 17 08:05 /tmp/Boot_to_Vim.iso 


You can use it to boot in a virtual machine or to burn to disk. If you exit Vim, it will start again.

Boot to vim

You can call the real shell by typing :!sh in command mode. To turn off use the command :!halt .

More information on Tiny Core remastering can be found here .

Source: https://habr.com/ru/post/237213/


All Articles