Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build subdirectory Boot and mixed 32-bit and 64-bit rootfs system on tinycolinux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to build a subdirectory boot and mixed 32-bit 64-bit rootfs system on tinycolinux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build a subdirectory boot and mixed 32-bit 64-bit rootfs system on tinycolinux.

Building a 32-bit 64-bit hybrid file system on tinycolinux

In the article "installing 64-bit toolchain on tinycolinux32", we mentioned that the resulting 64-bit program could not run, and even ldd could not analyze its reference, only prompted wrong elf64class, and direct execution also prompted not found, this is because it could not find 64-bit shared library, because ldd could not be used, we analyzed by other means and found that the ultimate reason is actually the default 64-bit GCC generated by glibc, the program generated by GCC to loader That is, the reference to ld-linux-x86-64.so is placed in / lib64 (as for other basic libraries libc-2.12.1.so,libcrypt-2.12.1.so,libm-2.12.1.so,libpthread-2.12.1.so, you can make the corresponding soft chain and put it in / lib64, but you don't have to do it. Because they are referenced in / usr/local/gcc443/x86_64-pc-linux-gnu/lib, which is specified by hardcoded when compiling the tool chain, and libstdc++.so.6.13,libgcc_s.so.1 also wants to put / usr/local/gcc443/x86_64-pc-linux-gnu/lib). So we just need to:

First copy this file and the real file ld-2.12.1.so it references to / lib64, and add execution permissions to ld-2.12.1.so (this is critical, otherwise you will be prompted access corrupt shared libraries), and then copy the above files to their respective directories. Execute the 64-bit test program and find that it can run successfully!

In this way, tinycolinux has two sets of programs that GCC supports to develop and run, one under / lib and the other under / lib64. Both 32-bit and 64-bit are supported.

Set up a high definition file system separated from system and usr extend on tinycolinux

Remember when we first mentioned that the minimalist rootfs is busybox+ some init scripts. We keep mentioning that busybox is a foundation and center for generating rootfs, the manager, which contains everything we need to build this test environment, and we use it to build this minimalist rootfs sample:

We tested it in an environment where tinycolinux has its own GCC481. In order to facilitate testing using a CVM, use snapshots to be ready for backup and recovery at any time. The tinycolinux used has its own rootfs. There is a busybox under an init,/bin in the root directory. After noticing these details, let's build our own busybox:

First download busybox source code http://mirrors.163.com/tinycorelinux/3.x/release/src/ download busybox-1.19.0.tar.bz2,busybox-1.19.0-config and 9 patch and apply to the unpacked source files, press "hard disk installation on tinycolinux" to prepare sudo make menuconfig and use config, for our separate folder system, busybox is statically linked in advance Static links can eliminate the dependence on the lib directory, and when compiling the menuconfig configuration, / system/usr/bin,/system/usr/sbin is set to merge into / system/bin,system/sbin,-because lib we want to do it in the usr folder, side by side with system,boot. After sudo make install is compiled, copy _ install to the / system in the root directory, and don't delete that / system/linuxrc.

Then we follow the grub boot / boot kernel in the article "install tinycolinux on the hard disk". The specific kernel startup parameters we used in our test are: linux / boot/bzImage ro root=/dev/vda1 swapfile=vda1 local=vda3 home=vda3 opt=vda3 tce=vda3 init=/system/init, complete grub menu text please refer to that article to see. Notice init=/system/linuxrc, which is a new parameter. It defines that after the system finds root=/dev/vda1 when booting the system, the PID0,root that the system will give execution power to PID0 to initialize the file system can only be the device, corresponding to the / in the file system, while init pid0 can be an executable program under any path, a script. This parameter actually transfers kernel to the connector to rootfs init (you can actually use init/main.c in patch kernel to load your own init).

There are many complicated init in the industry, such as systemvinit, tinycolinux also defines its scripting init, in tinycolinux, init is the root init is a script, but for simple init, you can link it directly to init in busybox, which is how it works in our test environment: linuxrc links to system/bin/init,busybox init can only be used as init because it actually contains a series of default actions Just like traditional init can do: it will first look for etc/inittab, this file can not be, if not, busybox init will execute / etc/init.d/rcS, here it has to perform some necessary work, so we also need to prepare some scripts to use busybox as init and do some preliminary work: a) create four empty dev,etc,proc,sys directories under / system B) prepare two device files mknod console c 5 1 and mknod null c 1 3 under dev, and then: C) provide fstab,inittab,init.d/rcS under etc, in which inittab,rcS adds execution permissions, which are as follows:

Fstab:

Proc / system/proc proc defaults 0 0sysfs / system/sys sysfs defauts 0 0

Inittab:

:: sysinit:/system/etc/init.d/rcSconsole::respawn:-/system/bin/sh::ctrlaltdel:/system/sbin/reboot::shutdown:/system/bin/umount-a-r

Init.d/rcS:

#! / system/bin/sh/system/bin/mount-a

All right, that's it. (you can OK without / system, package the above rootfs into initrd.gz and test it in a normal way to prove that the file system is perfect, and the end result is to enter the command line correctly.) . Let's try to run based on the rootfs with / system appended, rename the original tinycolinux / bin/busybox directly, let the new busybox take effect, and continue the following tests. If you fail for one of the following reasons, the CVM may continue to recover between the following failures and the solution cycle and try again:

1) failure may:

Prompt kernel panic, saying that the provided init is not executable, and the system attempts to execute the default init under tinycolinux /

Warning:cant start default console

Sbin/gettty not found or something.

You can see sh, but ls, which not found

Visible light is a script file that is insufficient to affect the behavior of busybox, so since we are trying to classify things like etc under / system/etc, we need to customize the hard-coded part of the path in busybox to continue testing:

2) solution:

Change the source code:

Include/libbb.h

1690: define bb_default_path (bb_PATH_root_path + sizeof ("PATH=/system/bin:/system/sbin:/sbin:/usr/sbin")) 1717: # define LIBBB_DEFAULT_LOGIN_SHELL "- / system/bin/sh" 1725: # define CURRENT_TTY "/ system/dev/tty" 1726: # define DEV_CONSOLE "/ system/dev/console"

Init/init.c

137: # define INIT_SCRIPT "/ system/etc/init.d/rcS" / / to customize the behavior of busybox init, this sentence must be used with the following sentence inittab: parser_t * parser = config_open2 ("/ system/etc/inittab", fopen_for_read); 684: tty = concat_path_file ("/ system/dev/", skip_dev_pfx (tty)); 996: putenv ((char *) "SHELL=/system/bin/sh") 1018: new_init_action (SYSINIT, "mount-t proc proc / system/proc", ")

Continue compiling.

Cd / tce/busybox sudo make clean sudo make install sudo cp _ install/system/bin/busybox / system/bin

Keep testing, and finally succeed. The system boot process is correct, and finally a normal command line appears. Of course, there is a lot of room that needs to be changed to make this rootfs more perfect.

In order to maintain this clean and powerful filesystem design, users should be careful to generate it under / usr when compiling the program, and never use. / configure without prefix by default.

You can integrate the existing init logic of tinycolinux and transform the root file system of tinyclinux into a high-definition file system, in the way that changes are made step by step within tinycolinux as above.

At this point, I believe you have a deeper understanding of "how to build a subdirectory boot and mixed 32-bit 64-bit rootfs system on tinycolinux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report