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

Initramfs starts linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. Rootfs production:

The root file system is the first file system used when Linux starts up, just like the file directory on the PC

1. Create the directory of the root file system (the directory name is random)

Mkdir rootfs

Cd rootfs

Mkdir bin dev etc lib home proc sbin sys usr mnt tmp var

Mkdir usr/bin usr/lib usr/sbin lib/modules

two。 Create a device file

Cd dev/

Mknod-m 666 console c 5 1

Mknod-m 666 null c 1 3

2. Configure busybox

Extract busybox and enter the busybox root directory

Make menuconfig

Select the tools you need to use

Go to busybox settings- > build option- >

Check "build busybox as a static binary", static link

Change Cross Compiler prefix to (arm-linux-)

3. Compile and install busybox

Copy the relevant commands / files to the file system being created

1. Under the busybox root directory

Modify Makefile

ARCH=arm

CROSS_COMPILE=arm-linux-

Make

Make install

Cp-rf _ install/* rootfs

Since / root/rootfs/linuxrc and / root/rootfs/sbin/init are the same program, linuxrc can be deleted to save space, ln-s/sbin/init init

[root@RSM-2 rootfs] # ls

Bin dev etc home lib init mnt root proc sbin sys tmp usr var

two。 Create a directory file under etc

Cd etc

Cp-a / root/busybox-1.20.2/examples/bootfloppy/etc/*.

[root@RSM-2 etc] # ls

Fstab init.d inittab profile

3. Modify these files

Modify inittab

Original file:

:: sysinit:/etc/init.d/rcS

:: respawn:-/bin/sh

Tty2::askfirst:/bin/sh

:: ctrlaltdel:/bin/umount-a-r

After modification: boot login-free and directly open shell (the previous number represents the line number)

:: sysinit:/etc/init.d/rcS

Console::askfirst:-/bin/sh

:: ctrlaltdel:/bin/umount-a-r

Modified: login is required for startup (the previous number represents the line number)

:: sysinit:/etc/init.d/rcS

:: respawn:-/bin/login

:: ctrlaltdel:/bin/umount-a-r

Modify fstab

Proc / proc proc defaults 0 0

None / var ramfs defaults 0 0

None / sys sysfs default 0 0

None / dev/pts devpts default 0 0

Modify profile

# / etc/profile: system-wide .profile file for the Bourne shells

PATH=/bin:/sbin:/usr/bin:/usr/sbin

Export LD_LIBRARY_PATH=/lib:/usr/lib

/ bin/hostname test

USER= "`id-un`"

LOGNAME=$USER

HOSTNAME='/bin/hostname'

PS1=' [\ u@\ h\ W] #'

Echo "All done!" Echo

4. Modify / etc/init.d/rcS

Echo "Starting rcS..."

Echo "+ + Mounting filesystem..."

Mount-t tmpfs mdev / dev

Mkdir / dev/pts

Mount-t devpts devpts / dev/pts

Mount-t sysfs sysfs / sys

Echo "+ + Setting up mdev..."

Echo / bin/mdev > / proc/sys/kernel/hotplug

Mdev-s

Mount-a

Echo "+ + Starting telnet daemon..."

Telnetd-l / bin/sh

Echo "+ + Set network..."

/ sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0

/ sbin/ifconfig eth9 192.168.3.1

/ sbin/ifconfig eth9 netmask 255.255.255.0

Echo "rcS Complete"

5. Copy passwd, shadow, group files locally.

[root@vm-dev etc] # cp / etc/passwd.

[root@vm-dev etc] # cp / etc/shadow.

[root@vm-dev etc] # cp / etc/group.

[root@vm-dev etc] # cp / etc/localtime.

Echo "root::0:0:root:/root:/bin/sh" > / etc/passwd

Echo "root:x:0:root" > / etc/group

Echo "root:$1 $3jZ93Mwqroomoaeef6lWIuThavs8wD0Wh2VOV 0M999997LV:" > / etc/shadow "

The user name is root and the password is 123456.

6. Copy the * * / lib/***.so library (according to your own system needs) in the cross compiler to the / lib directory

[root@vm-dev lib] # cp * * / lib/***.so. -a

To finish the production of this file system.

4. Making initramfs

Delete .config

Cp linux-2.6.26/arch/mips/configs/xxxxx_config linux-2.6.26/.config

Modify Makefile

ARCH=mips

CROSS_COMPILE=mipsel-linux-

Step 1.make menuconfig to open the configuration menu

General setup-- > Select Initial RAM filesystem and RAM disk. [*] Compress ramdisk by lzma instead of gzip, the reason is simple: we use initramfs instead of ramdisk, so there is no need to configure the driver support item Device Drivers-- > Block devices-- > RAM block device support of ramdisk, and the relevant default configuration options such as (4096) Default RAM disk size kbytes will not appear again.

In addition, another important difference between initramfs technology and ramdisk technology is that initramfs does not simulate a disk in memory, so it no longer needs the ext2 driver support needed in ramdisk. Therefore, the ext2 file system under the File systems menu supports

< >

The Second extended fs support option can be canceled.

Another important difference at this step is that you need to General setup-- > Initial RAM filesystem and RAM disk. Fill in the root file system directory that you want to make into initramfs format in the related item (/ root/rootfs) Initramfs source file (s). Here, the root file system directory I'm going to do is / root/rootfs.

Step 2. Make initramfs root file system

The steps for making the minimum system root file system are basically the same as the previous steps for making the ramdisk root file system. Here is just how the last step is different.

In addition, we use the genext2fs tool when we create the ramdisk root file system image, here we do not need additional steps to create the initramfs root file system image, but automatically generate it when you compile the Linux kernel. The automatically generated initramfs root file system is mirrored in the usr directory of the Linux source tree. The name is initramfs_data.cpio.gz, and it is a compressed file in gz format

There is a problem with this: when compiling a kernel that can be booted with initramfs, its configuration option has a related item, which is to fill in the root file system directory you want to make into initramfs format in (/ root/rootfs) Initramfs source file (s). This requires us to do the root file system first when compiling the kernel. It is worth noting that the kernel image we created in this way is actually much larger than the original one, because when we do this, we actually merge the initramfs root file system directly into the kernel image. In this way, the merged image no longer needs to burn the root file system image separately, and accordingly, the parameters when booting the kernel do not need to add initrd=. To specify the location of the initramfs.

Step 3. Compile and install the kernel

Cd Linux 2.6.26

Make modules_install INSTALL_MOD_PATH=/***/rootfs / / generate rootfs/lib/modules/2.6.26

Step 4. Modify makefile compilation

Introduction to objcopy tool parameters

# use-O binary (or-- out-target=binary) to export to the original binary file

# use the-R. note (or-- remove-section) output file without the .note section to reduce the file size

# use-S (or-- strip-all) to output files without relocating information and symbol information, reducing the file size

Due to the use of u-boot startup, so the kernel to make uImage,uImage is a U-boot-specific image file, it is before the zImage with a length of 0x40 "header", indicating the type of image file, loading location, generation time, size and other information, vmlinux is the most original uncompressed kernel file.

COMP=lzma (compression method) p_w_picpath: mkp_w_picpath

$(CROSS_COMPILE) objcopy-O binary-R .note-R .comment-S $(ROOTDIR) / $(LINUXDIR) / vmlinux $(KERNELZ)

Cd $(IMAGEDIR); rm-f $(KERNELZ). *; $(COMP)-9-f-S. $(COMP) $(KERNELZ)

Cd $(IMAGEDIR); $(CUR_DIR) / mkp_w_picpath-A mips-O linux-T kernel-C $(COMP)-a 80000000-e $(shell readelf-h $(ROOTDIR) / $(LINUXDIR) / vmlinux | grep "Entry" | awk'{print $4}')-n "Linux Kernel Image"-d $(KERNELZ). $(COMP) $(IMAGE)

The uImage generated after make is the file system started by initramfs.

5. File systems supported by embedded Linux:

Jffs2,yaffs,cramfs,ramdisk,ramfs

Jffs2: used on NorFlash, readable and writable, supporting data compression

Yaffs2: used on NandFlash, does not support data compression, can read and write

Cramfs: can be used on both NorFlash and NandFlash, read-only, supporting data compression

Ramdisk: use a portion of fixed memory as a partition, not an actual file system, to facilitate kernel startup

NFS: the file system is shared on the PC through the network

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

Servers

Wechat

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

12
Report