2.1.3 Kernel command line: ro root=/dev/hda1


from Linuxデバイスドライバ開発に精通
 
2.1.3 Kernel command line: ro root=/dev/hda1
Linuxのブートローダは、通常、カーネルにコマンドラインを渡します.コマンドラインのパラメータは、Cプログラムのmain()関数に渡されるargv[]リストと似ています.唯一の違いは、カーネルに渡されることです.ブートローダのプロファイルにコマンドラインパラメータを追加することもできます.もちろん、実行中にブートローダでLinuxのコマンドラインを変更することもできます.GRUBというブートローダを使用する場合は、リリースバージョンによっては/boot/grub/grubとなる可能性があります.confまたは/boot/grub/menu.lst.LILOを使用する場合、プロファイルは/etc/liloです.conf.次にgrubを示します.confファイルの例(注釈をいくつか追加)では、title kernel 2.6.23に続く行のコードを見て、前述の印刷情報の由来がわかります.

  
  
  
  
  1. default 0  #Boot the 2.6.23 kernel by default  
  2. timeout 5  #5 second to alter boot order or parameters  
  3.  
  4. title kernel 2.6.23     #Boot Option 1  
  5.   #The boot image resides in the first partition of the first disk  
  6.   #under the /boot/ directory and is named vmlinuz-2.6.23. 'ro'  
  7.   #indicates that the root partition should be mounted read-only.  
  8.   kernel (hd0,0)/boot/vmlinuz-2.6.23 ro  root =/dev/hda1  
  9.  
  10.   #Look under section "Freeing initrd memory:387k freed"  
  11.   initrd (hd0,0)/boot/initrd  
  12.  
  13. #... 

コマンドラインパラメータは、起動中のコード実行パスに影響します.一例として、あるコマンドラインパラメータがbootmodeであると仮定し、そのパラメータが1に設定されている場合、起動中にデバッグ情報を印刷し、起動終了時にrunlevelの3番目のレベルに切り替えることを意味します.(初期化プロセスの起動情報印刷後にrunlevelの意味がわかります).bootmodeパラメータが0に設定されている場合は、起動プロセスを比較的簡潔にし、runlevelを2に設定したいことを意味します.init/main.cファイルに慣れている以上、以下の変更を加えます.

  
  
  
  
  1. static unsigned int  bootmode  =  1 ;  
  2. static int __init  
  3. is_bootmode_setup(char *str)  
  4. {  
  5.   get_option(&str, &bootmode);  
  6.   return 1;  
  7. }  
  8.  
  9. /* Handle parameter " bootmode =" */  
  10. __setup(" bootmode =", is_bootmode_setup);  
  11.  
  12. if (bootmode) {  
  13.   /* Print verbose output */  
  14.   /* ... */  
  15. }  
  16.  
  17. /* ... */  
  18.  
  19. /* If bootmode is 1, choose an init runlevel of 3, else  
  20.    switch to a run level of 2 */  
  21. if (bootmode) {  
  22.   argv_init[++args] = "3";  
  23. } else {  
  24.   argv_init[++args] = "2";  
  25. }  
  26.  
  27. /* ... */ 

カーネルを再コンパイルし、新しい変更を実行してください.また、本書18.5節では、カーネルコマンドラインパラメータについてもより詳細に説明します.