Linux2.4.18 ---- 25. File System Construction

Source: Internet
Author: User

Linux2.4.18 ---- 25. File System Construction
1. File System Construction
1. Compilation of busybox
Method: Use the redhat9.0 of the Virtual Machine for compilation.
Version: busybox-1.00 --> make menuconfig --> make install

  1. Cong @ msi:/work/OS/rootfs/busybox/busybox-1.00 $ readelf-a./busybox | grep "NEEDED"
  2. 0x00000001 (NEEDED) Shared library: [libm. so.6] --> therefore, the file system must contain the libm and libcrypt libraries, which are optional.
  3. 0x00000001 (NEEDED) Shared library: [libcrypt. so.1]
  4. 0x00000001 (NEEDED) Shared library: [libc. so.6] --> the libc library is required and the most basic library.
You do not need to select [] Build BusyBox as a static binary (no shared libs)

2. kernel Modification
  1. L128 in init/main. c
  2. // Int root_mountflags = MS_RDONLY;
  3. Int root_mountflags = 0
Remove the read-only attribute of the root file system,
The root_mountflags will set the/dev/hda1 attribute to MS_RDONLY in mount_root --> read_super.

3. files under the etc directory
  1. Cong @ msi:/work/OS/rootfs/ext2/etc $ tree
  2. .
  3. ├ ── Fstab --> only fstab and rcS are required.
  4. ── Init. d
  5. │ ── RcS --> only the cross-section and cross section are required.
  6. ── Mtab --> this file is created by the mount program and is not in the file system.
Fstab content: Mount proc
  1. Cong @ msi:/work/OS/rootfs/ext2/etc $ cat fstab
  2. Proc/proc defaults 0 0
The content of the rcS, mount all
  1. Cong @ msi:/work/OS/rootfs/ext2/etc $ cat init. d/rcS
  2. #! /Bin/sh
  3. Mount-
4. Create a script for the root file system
Cong @ msi:/work/OS/rootfs/ext2 $ cat creatext2.sh

  1. #! /Bin/sh
  2. TOPDIR = 'pwd'
  3. Create_fs ()
  4. {
  5. Echo "cong: next create fs"
  6. # Create filesystem
  7. Cd/tmp/ext2

  8. # Create a system directory first
  9. Sudo mkdir-pv dev/tmp/sys/proc/
  10. Sudo mknod./dev/tty1 c 4 1
  11. Sudo mknod./dev/console c 5 1
  12. # Sudo cp $ TOPDIR/busybox./bin/
  13. # Sudo cp $ TOPDIR/src/hello./bin/sh
  14. Sudo cp-Arn $ TOPDIR/lib ./
  15. Sudo cp-Arn $ TOPDIR/bin ./
  16. Sudo cp-Arn $ TOPDIR/sbin ./
  17. Sudo cp-Arn $ TOPDIR/etc ./
  18. }
  19. Mount_fs ()
  20. {
  21. Echo "cong: next losetup/dev/loop0"
  22. Sudo losetup/dev/loop0./hdc. img
  23. #512*2048 = 1048576
  24. Echo "cong: next losetup/dev/loop1"
  25. Sudo losetup-o 1048576/dev/loop1/dev/loop0
  26. Echo "cong: next show losetup all"
  27. Sudo losetup-

  28. Echo "cong: next mount"
  29. Mkdir/tmp/ext2
  30. Sudo mount-t ext2/dev/loop1/tmp/ext2/
  31. }
  32. # Fdisk hdc. img to ext2 83
  33. Make_fs ()
  34. {
  35. #64 M
  36. Dd if =/dev/zero of =./hdc. img bs = 1 M count = 64
  37. Fdisk./hdc. img <EOF
  38. N
  39. P
  40. 1
  41. 2048
  42. 131071
  43. T
  44. 83
  45. W
  46. EOF
  47. Sleep 1
  48. Fdisk-l./hdc. img

  49. Echo "cong: next losetup/dev/loop0"
  50. Sudo losetup/dev/loop0./hdc. img
  51. #512*2048 = 1048576
  52. Echo "cong: next losetup/dev/loop1"
  53. Sudo losetup-o 1048576/dev/loop1/dev/loop0
  54. Echo "cong: next show losetup all"
  55. Sudo losetup-

  56. Echo "cong: next mkfs ext2/dev/loop1"
  57. Sudo mkfs. ext2/dev/loop1

  58. Echo "cong: next mount"
  59. Mkdir/tmp/ext2
  60. Sudo mount-t ext2/dev/loop1/tmp/ext2/
  61. Create_fs
  62. }
  63. Umount_fs ()
  64. {
  65. Sudo umount/tmp/ext2
  66. Sudo losetup-d/dev/loop0
  67. Sudo losetup-d/dev/loop1
  68. Sudo losetup-
  69. }

  70. Clean_fs ()
  71. {
  72. Echo "cong: next umount/tmp/ext2"
  73. Sudo umount/tmp/ext2
  74. Echo "cong: next rm-rf/tmp/ext2"
  75. Sudo rm-rf/tmp/ext2
  76. Echo "cong: next losetup-d"
  77. Sudo losetup-d/dev/loop0
  78. Sudo losetup-d/dev/loop1
  79. Echo "cong: next show losetup"
  80. Sudo losetup-
  81. Echo "cong: next rm-rf./hdc. img"
  82. Rm-rf./hdc. img
  83. }

  84. Case "$1" in
  85. Fs)
  86. Make_fs
  87. ;;
  88. Clean)
  89. Clean_fs
  90. ;;
  91. Mount)
  92. Mount_fs
  93. ;;
  94. Umount)
  95. Umount_fs
  96. ;;
  97. *)
  98. Make_fs
  99. ;;
  100. Esac
5. Used
  1. Cong @ msi:/work/OS/rootfs/ext2 $ tree
  2. .
  3. ── Bin --> copies the bin directory of the root file system.
  4. │ ── Busybox
  5. │ ── Busybox_0.60.5
  6. │ ── Cat-> busybox
  7. │ ── Cp-> busybox
  8. │ ── Df-> busybox
  9. │ ── Dmesg-> busybox
  10. │ ── Echo-> busybox
  11. │ ├ ── Grep-> busybox
  12. │ ── Hostname-> busybox
  13. │ ── Ln-> busybox
  14. │ ├ ── Ls-> busybox
  15. │ ── Mkdir-> busybox
  16. │ ── Mknod-> busybox
  17. │ ── Mount-> busybox
  18. │ ── Mv-> busybox
  19. │ ── Netstat-> busybox
  20. │ ├ ── Ping-> busybox
  21. │ ── Ps-> busybox
  22. │ ── Pwd-> busybox
  23. │ ── Rm-> busybox
  24. │ ├ ── Sh-> busybox
  25. │ ── Sync-> busybox
  26. │ ── Touch-> busybox
  27. │ ── Umount-> busybox
  28. │ ── Vi-> busybox
  29. ── Creatext2.sh --> Create a script for the root file system
  30. ── Etc--> Is copiedEtc of the root file systemDirectory
  31. │ ── Fstab
  32. │ ── Init. d
  33. │ ── RcS
  34. │ ── Mtab
  35. ── Lib--> Is copiedLib of the root file systemDirectory
  36. │ ── Ld-linux.so.2 // Interpreter
  37. │ ├ ── Libc-2.3.2.so // libc library, this is the most basic
  38. │ ├ ── Libcrypt-2.3.2.so // The Rest Of The libcrypt and libm library single run helloworld is not needed
  39. │ ├ ── Libcrypt. so.1-> libcrypt-2.3.2.so
  40. │ ├ ── Libc. so.6-> libc-2.3.2.so // but here the busybox is used, it is added
  41. │ ── Libm-2.3.2.so.
  42. │ └ ── Libm. so.6-> libm-2.3.2.so
  43. ── Makefile
  44. ── Sbin--> Is copiedSbin of the root file systemDirectory
  45. │ ├ ── Ifconfig-> ../bin/busybox
  46. │ ── Init-> ../bin/busybox
  47. │ ── Insmod-> ../bin/busybox
  48. │ ── Lsmod-> ../bin/busybox
  49. │ ── Modprobe-> ../bin/busybox
  50. │ ── Rmmod-> ../bin/busybox
  51. ── Src--> Code of some test programs
  52. ──
  53. │ ── Hello. s
  54. │ ── Makefile
  55. ── Hello. c
  56. ── Makefile
  57. ── Mycompile. sh
  58. ── Nasm
  59. ── Hello
  60. ── Hello. o
  61. ── Hello. s
  62. ── Hello. s_nasm
  63. ── Init. c_hello
  64. ── Makefile

  65. 8 directories, 54 files
5.1 package the files used
Ext2.rar(change the name to ext2.tar.gz after downloading)


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.