Super DIY: Create a Linux system running in memory

Source: Internet
Author: User
Article Title: Super DIY: Create a Linux system running in memory. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories. Generally, during the linux system startup process, the bootloader written on the MBR loads the kernel, then load the initial environment, that is, initrd. In initrd, there is usually a script (or ELF File) called init or linuxrc. After the process is started, read the content under the/etc/inittab first. This is an initialization table used to determine the execution of/etc/rc. d. After the RC script is executed, the file system obtains all hardware information and loads the real root partition. What we need to do now is to use initrd as the root partition. In this way, there are four main tasks to do: 1. create a Ramdisk with a large space. use busybox to generate necessary commands in the file system. The main reason for using it is that it occupies less space. add or modify files under dev and etc. consider adding some applications, such as ssh.
Operating System: SlackWare12, kernel version:
1. Create a Ramdisk with a large space
# Dd if =/dev/zero of =/tmp/ramdisk bs = 1 k count = 92160
# Losetup/dev/loop2/tmp/ramdisk
# Mkfs. ext2/dev/loop2
# Mount-t ext2/dev/loop2/mnt
You can write something to/mnt, and then
# Umount/mnt
You can use
# Gunzip ramdisk.gz // decompress initrd
# Mount-o loop ramdisk/mnt // mount
...... ...... // Modify the content
# Gzip-9 ramdisk // recompress
2. Use busybox to generate necessary commands in the file system
To download a new busybox, you must first modify the source code. Otherwise, an error occurs during compilation because uclibc is not used. Open the applets/applets. c file and comment out"
# If ENABLE_STATIC & defined (_ GLIBC __)&&! Defined (_ UCLIBC __)
# Warning Static linking against glibc produces buggy executables
# Warning (glibc does not well with ld -- gc-sections ).
# Warning See Id = 3400
# Warning Note that glibc is unsuitable for static linking anyway.
# Warning If you still want to do it, remove-Wl, -- gc-sections
# Warning from top-level Makefile and remove this warning.
# Endif "this code.
Run # make menuconfig. According to the online article, pay attention to the following two points: first, select "compile busybox into an executable file for static connection ", the second is to select "do not use the usr directory of the system", and pay attention to the selected default SHELL. Run the make command to generate some files in the _ install directory and copy them to ramdisk for use.
3. Add or modify files under dev and etc
Under ramdisk,
Mkdir dev etc root usr var tmp proc mnt
Let's talk about dev first,
You can copy all files under dev in the compiling environment to # cp-a/dev/* ramdisk/dev; or you can use mkdevs under busybox/examples/bootfloppy. sh script to generate a device file.
Let's talk about the files under etc. This is troublesome and I haven't figured it out yet, huh, huh. My current method is to copy all the files in the etc environment of the compiling environment to the previous one, and then overwrite the inittab file in ramdisk/etc with the inittab file in busybox/example. This new inittab file ignores runlevel and does not require the user's login username and password. It only requires an rcS script (in busybox/examples/bootfloppy/etc ). Modify the/etc/fstab content:
      /dev/ram0 / ext3 defaults 1 1devpts /dev/pts devpts gid=5,mode=620 0 0proc /proc proc defaults 0 0

4. Rewrite lilo
Add in lilo. conf
Image =/boot/vmlinuz
Initrd =/boot/test_kern/ramdisk.gz
Label = test
Append = "mem = 600 M ramdisk = 92160 root =/dev/ram0 rw"
Run # lilo-v-C/etc/lilo. conf-s/boot
Now, Ramdisk has been created and has a basic operating environment. After the NIC Driver is loaded, it can connect to the network, but cannot log on to it through ssh.
5. Consider adding some applications, such as ssh.
My current practice is to copy the sshd, ssh, and other commands and Related Files under etc. The missing library is checked by executing ldd and then copied to lib, dev also has the random and unrandom files to be copied, And the empty and run directories to be created under var.
At first, "privilege separation user sshd does not exist" is prompted when/etc/rc. d/rc. sshd start is executed on the system running on Ramdisk ". The cause is that the uid is unknown (all the files in the etc are copied from the original compilation environment). An error occurs when the passwd command is executed, prompting "unknown uid 0 ". The solution is to add the lib file.
Libnsl. so.1
I have added bash and other programs. In this way, the following files are available under/lib:

      -rwxr-xr-x 1 root root 131484 2008-01-25 10:15*-rwxr-xr-x 1 root root 23512 2008-01-25 10:14*-rwxr-xr-x 1 root root 12324 2008-01-25 10:15*-rwxr-xr-x 1 root root 1528742 2008-01-28 10:33*-rwxr-xr-x 1 root root 25250 2008-01-28 10:33*-rwxr-xr-x 1 root root 13506 2008-01-28 10:33*-rwxr-xr-x 1 root root 96480 2008-01-28 19:09*-rwxr-xr-x 1 root root 35494 2008-01-28 19:09*-rwxr-xr-x 1 root root 45552 2008-01-28 19:10*-rwxr-xr-x 1 root root 41045 2008-01-28 19:10*-rwxr-xr-x 1 root root 110796 2008-01-25 10:14*-rwxr-xr-x 1 root root 77439 2008-01-28 10:30*-rwxr-xr-x 1 root root 34905 2008-01-25 10:13*-rwxr-xr-x 1 root root 10280 2008-01-25 12:38*-rwxr-xr-x 1 root root 12537 2008-01-28 10:31*drwxr-xr-x 3 root root 1024 2008-01-28 10:37 modules/


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.