標準/ sbin / initの置き換えについて

initはUnixライクなオペレーティングシステムでの最初のユーザープロセスです

init-システムのカーネルによって直接起動されます。

init-システムのすべてのユーザー(ユーザー空間)プロセスの親です。



標準/ sbin / initは、構成ファイル/ etc / inittabを読み取り、システムを起動して、いくつかの「ランレベル」を使用してシステムを管理します。



同じ名前のinitキーを使用して、Linuxカーネルにstandard / sbin / initの代わりに別のファイルを使用するように指示できます



この機会に、次の設定を/boot/grub/menu.lstに追加します

タイトルLinuxカーネルとカスタムinit

ルート(hd0,1)

カーネル/linux/vmlinuz-2.6.26-1-686 root = / dev / hda2 init = / linux / init

initrd /linux/initrd.img-2.6.26-1-686



initプロセスを置き換える機会は誰にありますか? 組み込みシステムの開発者はこれに頼ることがあります-このようにして、デバイスの開発を簡素化し、オペレーティングシステムの環境全体に沿ってドラッグすることはできません。



私の場合、initを置き換えるという要望は別の面にありました。Linuxカーネルによって実行されるXameleonシステムのinitプロセスがどのように動作するかを確認したかったのです。 あなたも試してみませんか?



標準/ sbin / initをXameleon initに変更した方法。 (ソースコードと説明)



プロジェクトをビルドするには、gcc開発ツールがインストールされた最新のLinuxディストリビューションを使用します。 最も簡単なMakefileを書きましょう。

プログラム= init



Srcs = init.cc



LDFLAGS + = -static

Libs + = -lc



すべて:

g ++ -D POSIX -D LINUX $(CFLAGS)$(SRCS)$(LIBS)$(LDFLAGS)-o init





実際、この記事をこれ以上読むことはできません。この方法で収集されたほとんどすべてのソースコードは、initの代替として使用できます。 好奇心reader盛な読者のために、私はChameleonオペレーティングシステムの初期initプロセスを投稿します。 これは特定の初期化プロセスです。オペレーティングシステムの唯一のプロセスとして使用できます。これには、いくつかのコマンドの最も原始的なインタープリターとプロセスを開始する機能が含まれています。



この記事について考えながら、初期化コードをどのライセンスに適用するかについての疑問に悩まされました。 多くの苦痛を伴う審議の後、選択はTwo Clause BSD Licenseに落ちました。



このソースの歴史は単純です-カメレオンオペレーティングシステム用に作成され、現在カメレオンが意図した目的で使用しています。 最近、アイデアが浮上しました-Linuxでinitバージョンを試してみませんか? 一種の互換性テスト。



typedef struct typeCommandEntry { const char * szCmd; int nLength; int (*fHandler)( int argc, char * argv[], char * envp[] ); const char * szHelpString; } typeCommandEntry; /////////////////////////////////////////////////////////////////////////////// // Callback's array // static typeCommandEntry CommandList[] = { { "help", 0, tcmdHelp, "Show list of built-in commands. Use 'help command-name' to see detail description of the command-name argument." }, { "exec", 0, tcmdExec, "Execite file. Please note that this command overwrites current process by new executable image" }, { "info", 0, tcmdSysInfo, "Show some information from the L4 KIP" }, { "memmap", 0, tcmdMemMap, "Show a kernel memory map" }, { "modules", 0, tcmdShowModules, "Show registered drivers" }, { "term", 0, tcmdDestroyProcess, "Destriy the init process" }, { "fork", 0, tcmdForkProcess, "Forks (creates copy of) the init process to another console." }, { "wait", 0, tcmdWaitProcess, "Waits for the process termination" }, { "kill", 0, tcmdKillProcess, "Sends signal to the process" }, { "trap", 0, tcmdTrapProcess, "Sends the trap signal to the process" }, { "reset", 0, tcmdReset, "Reset current console to the initial state" }, { "mount", 0, tcmdMount, "This command shows mounted filesyetems if used without arguments.\nUse 'mount device mount-point' to mount device into filesystem tree." }, { "umount", 0, tcmdUnmount, "Unmounts filesystem that provided as command argument. " }, { "cd", 0, tcmdChangeDir, "Change current directory" }, { "dir", 0, tcmdShowDirectory, "Show directory without parsing inodes" }, { "ls", 0, tcmdListDirectory, "List files into current directrory or files that reside to a path provded as command argument" }, { "chroot", 0, tcmdChangeRootDirectory, "Changes the root directory of the caller process." }, { "cat", 0, tcmdShowFile, "List file on active console" }, { "rm", 0, tcmdRemoveFile, "Remove file" }, { "rmdir", 0, tcmdRemoveDirectory, "Remove directory" }, { "mkdir", 0, tcmdMakeDirectory, "Create directory" }, { "ln", 0, tcmdMakeLink, "Link the file inode as a new file" }, { "mv", 0, tcmdMoveFile, "Moves file into another place. Please note that this command able to move files within same filesystem." }, { "df", 0, tcmdDiskInformation, "Show mounted partitions information" }, { "chown", 0, tcmdChangeOwner, "Chane owner of file or directory" }, { "sync", 0, tcmdFlushCaches, "Flush disk caches" }, { "cp", 0, tcmdCopyFile, "Copy file" }, { "setenv", 0, tcmdSetEnvironment, "Set environment variable" }, { "getenv", 0, tcmdGetEnvironment, "Get environment variable" }, { "unsetenv", 0, tcmdUnsetEnvironment, "Unset environent variable" }, { "pwd", 0, tcmdPwd, "Print working directory" }, { "dump", 0, tcmdDump, "Show file/device hex dump" }, { "env", 0, tcmdEnv, "Show current environment" }, { "exit", 0, tcmdExit, "Terminates init process. This command have no meaning in production sysstem, but usefull for debugging)" }, { "quit", 0, tcmdExit, "A synonym for the exit command" }, };
      
      







たとえば、標準シェルを起動するには、次のコマンドを使用します

/#exec / bin / sh


コンピューターの電源を切るには

/#exec / sbin / halt


コードの英語が下手で申し訳ありません-ロシア語のメッセージの方が良いでしょうが、初期化プロセスの段階では、ロシア語の文字ジェネレータはまだロードされていません-これは最初のプロセスの子孫の懸念です。

パッチを受け入れます。

FreeBSDで試しませんでした。 あなたが突然集まらない場合-書き込みます。



xameleon initソースコードのダウンロード


http://narod.ru/disk/26585438001/xam_init.tgz.html



いいメイクをしてください。



All Articles