Create rootfs and ramdisk

Source: Internet
Author: User
Tags gz file

1. ramdisk is the smallest Linux rootfs system. It contains all Linux systems except the kernel
Tools required for import and management include the following directories: Bin, Dev, etc, home, Lib, MNT, Proc, sbin, USR, VA
R. Some basic tools are also required: Sh, ls, CP, MV ...... (In the/bin directory); necessary configuration files
Pieces: inittab, RC, fstab ...... Located in (/etc directory); required Device Files:/dev/tty *,/dev/CO
Nsole,
/Dev/MEN ...... (In the/dev directory); SH, ls and other tools necessary Runtime Library: Glibc.

2. Create an empty ramdisk image file:
Xuxian @ omap1 :~ $ CD/home/xuxian/fsys
Xuxian @ omap1 :~ $ Dd If =/dev/Zero of = rootfs BS = 1 m COUNT = 16
The ramdisk image file name is rootfs and the size is 16 Mb.
Format the file system as needed, such as ext2 and ext3.
For example, ext3:
Xuxian @ omap1 :~ $ Mkfs. ext3-M 0-N 2000./rootfs
-N 2000 indicates that the maximum number of nodes is 2000. Because Linux devices are also based on file systems
If the number of nodes that occupy the file system is too small, it may not be enough in the future.
Then mount it to a directory:
Xuxian @ omap1 :~ $ Mkdir ramdisk
Xuxian @ omap1 :~ $ Mount-T ext3-o loop./rootfs./ramdisk
Xuxian @ omap1 :~ $ CD ramdisk
Xuxian @ omap1 :~ $ Ls
Xuxian @ omap1 :~ $ Lost + found
In this step, an empty ramdisk image file is obtained.

3. create various directories:
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir Dev
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir proc
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir etc
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir sbin
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir Bin
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir lib
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir mnt
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir USR
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir TMP
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir Root
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir home
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir VaR
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir usr/bin
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir usr/sbin
Xuxian @ omap1 :~ /Fsys/ramdisk $ mkdir usr/lib

For a single user, home and root are not required.

4./dev directory:

Omap1:/home/xuxian/fsys/ramdisk/dev $ mknod-m 600 console C 5 1
Omap1:/home/xuxian/fsys/ramdisk/dev $ mknode-M 666 tty C 5 0
Omap1:/home/xuxian/fsys/ramdisk/dev $ mknod-m 600 tty0 C 4 0
Omap1:/home/xuxian/fsys/ramdisk/dev $ mknod-m 600 ttys0 C 4 64

You can also use a simple method to create files in/dev: First, you need to download a file system.

Omap1:/home/xuxian/fsys/ramdisk/dev $ CP-DPR/home/xuxian/osk/rootfs2.6/dev /*
.
This command copies the/dev directory of the downloaded file system to the/dev directory of ramdisk. The DP parameter indicates the symbolic connection copy.
Beian is a symbolic connection. It does not copy the connected symbols and copies all the properties of the source file.

5./lib directory:

The following is a dynamic library of arm-linux. You can select some required copies to the Lib of ramdisk.
Omap1:/home/iaadoa/work/crosstool/gcc-3.3.2-glibc-2.3.2/ARM-Linux/L
IB # ls
Crt1.o libc_nonshared.a libmcheck.
Libnss_hesiod.so.2 librt.
Crti. O libcrypt-2.3.2.so libmemusage. So
Libnss_nis-2.3.2.so librt. So
Crtn. O libcrypt. A libm. So
Libnss_nisplus-2.3.2.so librt. so.1
Gconv libcrypt. So libm. so.6
Libnss_nisplus.so libsegfault. So
Gcrt1.o libcrypt. so.1 libnsl-2.3.2.so
Libnss_nisplus.so.2 libstdc ++.
Ld-2.3.2.so libc. So libnsl..
Libnss_nis.so libstdc ++. La
Ld-linux.so.2 libc. so.6 libnsl. So.
Libnss_nis.so.2 libstdc ++. So
Ldscripts libc. so_orig libnsl. so.1
Libpcprofile. So libstdc ++. so.5
Libanl-2.3.2.so libdl-2.3.2.so libnss_compat-2.3.2.so
Libpthread-0.10.so libstdc ++. so.5.0.5
Libanl. A libdl. A libnss_compat.so
Libpthread. A libsupc ++.
Libanl. So libdl. So libnss_compat.so.2
Libpthread_nonshared.a libsupc ++. La
Libanl. so.1 libdl. so.2 libnss_dns-2.3.2.so
Libpthread. So libthread_db-1.0.so
LibBrokenLocale-2.3.2.so libg. A libnss_dns.so
Libpthread. so.0 libthread_db.so
Libbrokenlocale. A libgcc_s.so libnss_dns.so.2
Libpthread. so_orig libthread_db.so.1
Libbrokenlocale. So libgcc_s.so.1 libnss_files-2.3.2.so
Libresolv-2.3.2.so libutil-2.3.2.so
Libbrokenlocale. so.1 libiberty. A libnss_files.so
Libresolv. A libutil.
Libbsd-compat.a libieee. A libnss_files.so.2
Libresolv. So libutil. So
Libc-2.3.2.so libm-2.3.2.so libnss_hesiod-2.3.2.so
Libresolv. so.2 libutil. so.1
Libc. A libm. A libnss_hesiod.so
Librt-2.3.2.so mcrt1.o

The following are required:

Ld-2.3.2.so libmemusage. So libnss_nisplus.so.2
Ld-linux.so.2 libm. so.6 libnss_nis.so.2
Libanl-2.3.2.so libnsl-2.3.2.so libpcprofile. So
Libanl. so.1 libnsl. so.1 libpthread-0.10.so
LibBrokenLocale-2.3.2.so libnss_compat-2.3.2.so libpthread. so.0
Libbrokenlocale. so.1 libnss_compat.so.2 libresolv-2.3.2.so
Libc-2.3.2.so libnss_dns-2.3.2.so libresolv. so.2
Libcrypt-2.3.2.so libnss_dns.so.2 librt-2.3.2.so
Libcrypt. so.1 libnss_files-2.3.2.so librt. so.1
Libc. so.6 libnss_files.so.2 libsegfault. So
Libdl-2.3.2.so libnss_hesiod-2.3.2.so libthread_db-1.0.so
Libdl. so.2 libnss_hesiod.so.2 libthread_db.so.1
Libgcc_s.so.1 libnss_nis-2.3.2.so libutil-2.3.2.so
Libm-2.3.2.so libnss_nisplus-2.3.2.so libutil. so.1

Copy it to the lib directory of ramdisk.

6. Install busybox:

Download busybox-1.01
Xuxian @ omap1 :~ /Osk $ tar-xjvf busybox-1.01.tar.bz2
Xuxian @ omap1 :~ /Osk/busybox-1.01 $ make target_arch = arm cross = arm-Linux-
Prefix =/home/xuxian/fsys/ramdisk menuconfig
Xuxian @ omap1 :~ /Osk/busybox-1.01 $ make target_arch = arm cross = arm-Linux-
Prefix =/home/xuxian/fsys/ramdisk Dep
Xuxian @ omap1 :~ /Osk/busybox-1.01 $ make target_arch = arm cross = arm-Linux-
Prefix =/home/xuxian/fsys/ramdisk
Xuxian @ omap1 :~ /Osk/busybox-1.01 $ make target_arch = arm cross = arm-Linux-
Prefix =/home/xuxian/fsys/ramdisk inatall
Xuxian @ omap1 :~ /Fsys/ramdisk/bin $ ls
Addgroup chown dmesg gzip login netstat sed true
Adduser CP echo hostname ls pidof sh umount
Ash date egrep IP mkdir Ping sleep uname
Busybox dd false ipaddr mknod PS su usleep
Cat delgroup fgrep iproute more PWD sync vi
Chgrp deluser grep kill Mount RM tar zcat
Chmod DF gunzip ln MV rmdir touch
These are available commands.

7. Descriptions of system configuration files in/etc:

Xuxian @ omap1 :~ /Fsys/ramdisk/etc/$ VI inittab
#
# This is run first packet t when booting in single-user mode
# Specify the initialization file

: Sysinit:/etc/init. d/RCS

#/Bin/sh
#
# Start an "askfirst" shell on the console (whatever that may be)
# Shell executed at startup

: Askfirst:-/bin/sh

# Stuff to do when restarting the INIT process
# Restart

: Restart:/sbin/init

# Stuff to do before rebooting
: Ctrlaltdel:/sbin/reboot

# Action when shutting down, Uninstall all file systems

: Shutdown:/bin/umount-a-r
: Shutdown:/sbin/swapoff-

Then write the RCS script:

Xuxian @ omap1 :~ /Fsys/ramdisk/etc/$ mkdir init. d

Xuxian @ omap1 :~ /Fsys/ramdisk/etc/$ CD init. d

Xuxian @ omap1 :~ /Fsys/ramdisk/etc/init. d $ VI RCS
The script is as follows:

#! /Bin/sh

Path =/bin:/sbin:/usr/bin:/usr/sbin

Hostname = omap5912osk
Hostname $ hostname
Echo ""
Echo "************************************** ****"
Echo "starting system init for $ hostname"
Echo "************************************** ****"

# Goto the init. d directory
CD/etc/init. d

# Mount the default file systems
Mount-A # mount the default file systems

# Configure network
#/Sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255
#/Sbin/ifconfig eth0 128.247.75.151 netmask 255.255.254.0 Broadcast
128.247.75.255
#/Sbin/route add default GW 128.247.74.1 eth0

Then the rcs2 script:

Xuxian @ omap1 :~ /Fsys/ramdisk/etc/init. d $ VI rcs2

#! /Bin/sh
/Bin/Mount-n-o remount, RW/

/Bin/Mount-
Echo starting Network
# Modprobe i2c-core
# Modprobe i2c-algo-bit
# Modprobe i2c-omap1510
# Modprobe soundcore
# Modprobe OMAP-Audio
# Modprobe omap1510-aic23

/Sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255
/Sbin/route add-net 127.0.0.0 netmask 255.0.0.0 Lo
/Sbin/ifconfig eth0 10.1.3.3 netmask 255.255.0.0 broadcast 10.1.20.255
/Sbin/route add default GW 10.1.0.100 eth0
~
~

Finally, I wrote the fstab script, which is simple:

Xuxian @ omap1 :~ /Fsys/ramdisk/etc $ VI fstab
Proc/proc defaults 0 0

8. Use NFS to check the root file system:

After completing these steps, you can use NFS to start the target system. Add/etc/exports to/home/xuxian/FSY
S/ramdisk 192.168.4.190 (RW, sync, no_root_squash, no_all_squash) Where 192.168.4.19
0 is the IP address of the target board.
Use TFTP or serial port to download U-boot and kernel from the target board, and add seten to the environment variable of U-boot.
V bootargs console = ttys0, 115200n8 noinitrd rw ip = DHCP root =/dev/nfs
Nfsroot = 192.168.0.11:/home/xuxian/fsys/ramdisk, nolock mem = 30m where 192.168.0.11
It is the Host IP address, and/home/xuxian/fsys/ramdisk is the ramdisk directory.

9. Check the file system by burning the flash

Finally, if you want to generate an image file and burn it into flash, run the following command:

Xuxian @ omap1 :~ /Fsys $ umount ramdisk
Xuxian @ omap1 :~ /Fsys $ gzip-V9 rootfs

In this example, the rootfs.gz file is generated and can be burned to flash together with U-boot and kernel.

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: info-contact@alibabacloud.com 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.