busybox的基本使用记录壹

内核如何启动init进程
init/main.c

static int __ref kernel_init(void *unused)
{
	int ret;

	kernel_init_freeable();
	/* need to finish all async __init code before freeing the memory */
	async_synchronize_full();
	ftrace_free_init_mem();
	jump_label_invalidate_initmem();
	free_initmem();
	mark_readonly();

	/*
	 * Kernel mappings are now finalized - update the userspace page-table
	 * to finalize PTI.
	 */
	pti_finalize();

	system_state = SYSTEM_RUNNING;
	numa_default_policy();

	rcu_end_inkernel_boot();

	if (ramdisk_execute_command) {
		ret = run_init_process(ramdisk_execute_command);
		if (!ret)
			return 0;
		pr_err("Failed to execute %s (error %d)\n",
		       ramdisk_execute_command, ret);
	}

	/*
	 * We try each of these until one succeeds.
	 *
	 * The Bourne shell can be used instead of init if we are
	 * trying to recover a really broken machine.
	 */
	if (execute_command) {
		ret = run_init_process(execute_command);
		if (!ret)
			return 0;
		panic("Requested init %s failed (error %d).",
		      execute_command, ret);
	}
	if (!try_to_run_init_process("/sbin/init") ||
	    !try_to_run_init_process("/etc/init") ||
	    !try_to_run_init_process("/bin/init") ||
	    !try_to_run_init_process("/bin/sh"))
		return 0;

	panic("No working init found.  Try passing init= option to kernel. "
	      "See Linux Documentation/admin-guide/init.rst for guidance.");
}

static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };

static int run_init_process(const char *init_filename)
{
	argv_init[0] = init_filename;
	pr_info("Run %s as init process\n", init_filename);
	return do_execve(getname_kernel(init_filename),
		(const char __user *const __user *)argv_init,
		(const char __user *const __user *)envp_init);
}

依次尝试执行/sbin/init  /etc/init /bin/init  /bin/sh 
ls -l /sbin/init
lrwxrwxrwx    1 test     test            14 Aug  3  2022 /sbin/init -> ../bin/busybox

简介: linux内核启动的第一个init进程,并且集成了大量的linux命令和工具的软件和系统初始化运行的配置,比如ls,mv,ifconfig等命令,是一个大的工具箱,
使用就是配置相关的选项,选择自己想要的功能,然后编译即可.
(1)官网和源码包下载
	https://busybox.net/
(2)解压
   mkdir rootfs
   tar -vxjf busybox-1.29.0.tar.bz2 
(3)配置busybox,裁剪和选择需要的功能
   cp  ../config_xxx   ./.config
   make ARCH=arm64  CROSS_COMPILE=aarch64-linux-gnu- menuconfig
(4)编译busybox 
	make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 20  
(5)install 生成所需要的busybox
	make install 
	make CONFIG_PREFIX=../busybox_output/  install 
	cp -af ./_install/*   ../busybox_output/
(6)查看成品
ls -lh
total 12K
drwxr-xr-x 2 root root 4.0K Jun 21 14:50 bin
lrwxrwxrwx 1 root root   11 Jun 21 14:50 linuxrc -> bin/busybox
drwxr-xr-x 2 root root 4.0K Jun 21 14:50 sbin
drwxr-xr-x 4 root root 4.0K Jun 21 14:50 usr

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今天6点半起床10点半睡觉和今天早晚运动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值