构建根文件系统-initrd

本文详细介绍了如何使用initrd构建根文件系统的过程,包括配置Busybox、创建必要的目录和文件、制作rootfs映像、修改bootloader及kernel命令行,并最终烧录到设备中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 用initrd方式构建根文件系统
操作步骤:
0) set enveniment
a) $ export PATH=$PATH:/usr/local/arm/arm-2009q3/bin

1) make busybox.
a) $ cd busybox-1.20.2
b) $ make menuconfig
Busybox Settings
--> Build Options
 [*] select build busybox as a static binary
 (arm-none-linux-gnueabi-) Cross Compiler Prefix
c) $ make
d) $ make install
e) $ cd ..


2) create necessary directory and files
a) $ mkdir initrd && cd initrd
b) $ mkdir -p etc/init.d proc sys dev
c) $ sudo cp -a /dev/{null,zero,console} dev/
d) $ cp -rf ../busybox-1.20.2/_install/* ./
e) $ rm -f linuxrc && ln -s bin/busybox init
f) edit etc/fstab, add followings:
proc    /proc   proc    defaults    0   0
sysfs   /sys    sysfs   defaults    0   0
g) edit etc/inittab
::sysinit:/etc/init.d/rcS
console::respawn:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
h) edit etc/init.d/rcS
#!/bin/sh
mount -a
i) $ chmod +x etc/init.d/rcS
j) $ cd ..


3) create rootfs image.
a) $ dd if=/dev/zero of=initrd.img bs=1k count=8192
b) $ sudo mke2fs -F -v -m0 initrd.img
c) $ sudo mount -o loop initrd.img /mnt/tmp/
mount: mount point /mnt/tmp/ does not exist 解决办法:sudo mount -o loop initrd.img /mnt/
d) $ sudo cp initrd/* /mnt/tmp/ -rf 替换为 sudo cp initrd/* /mnt/ -rf
e) $ sudo umount /mnt/tmp/ 替换为 sudo umount /mnt/
f) $ gzip -9 initrd.img
g) $ fastboot flash ramdisk initrd.img.gz


4) modify bootloader.
diff --git a/TC4_uboot/board/samsung/smdkc210/smdkc210.c b/TC4_uboot/board/samsung/smdkc210/smdkc210.c
index c5abd40..79d55db 100755
--- a/TC4_uboot/board/samsung/smdkc210/smdkc210.c
+++ b/TC4_uboot/board/samsung/smdkc210/smdkc210.c
@@ -246,7 +246,10 @@ int board_late_init (void)
&& boot_mode == 0) {
//printf("board_late_init\n");
char boot_cmd[100];
-               sprintf(boot_cmd, "movi read kernel 40008000;movi read rootfs 40d00000 100000;bootm 40008000 40d00000");
+               //sprintf(boot_cmd, "movi read kernel 40008000;movi read rootfs 40d00000 100000;bootm 40008000 40d00000");
+               sprintf(boot_cmd, "movi read kernel 40008000;movi read rootfs 40d00000 300000;bootm 40008000");
setenv("bootcmd", boot_cmd);
}


5) modify kernel cmdline.
diff --git a/TC4_Kernel_3.0/arch/arm/configs/m8012_defconfig b/TC4_Kernel_3.0/arch/arm/configs/m8012_defconfig
index 5ddb074..3d24ece 100755
--- a/TC4_Kernel_3.0/arch/arm/configs/m8012_defconfig
+++ b/TC4_Kernel_3.0/arch/arm/configs/m8012_defconfig
@@ -570,7 +570,10 @@ CONFIG_ALIGNMENT_TRAP=y
# CONFIG_USE_OF is not set
CONFIG_ZBOOT_ROM_TEXT=0
CONFIG_ZBOOT_ROM_BSS=0
-CONFIG_CMDLINE="console=ttySAC2,115200"
+#CONFIG_CMDLINE="console=ttySAC2,115200"
+CONFIG_CMDLINE="console=ttySAC2,115200 initrd=0x40d00000,8mb root=/dev/ram0"
+
# CONFIG_CMDLINE_FROM_BOOTLOADER is not set
CONFIG_CMDLINE_EXTEND=y
# CONFIG_CMDLINE_FORCE is not set


6) build uboot, kernel, and flash them.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值