嵌入式


setting up a serial console

<h3>Edit the GRUB configuration</h3> <p>edit the GRUB configuration, so it sends its messages to the serial console. One of the most important things is to set a password, otherwise anyone can connect a serial cable, edit the GRUB configuration line while the system is booting (via the &quot;e&quot; key), and get root access. When a password is set, interactive menu editing will be disabled, unless the correct password is entered. To set the password, we first need to get the encrypted version of it.</p> <p>Run grub, and use the <code>"md5crypt"</code> command to encrypt the password:</p> <pre><code>grub&gt; md5crypt Password: ******** Encrypted: $1$AlfMq1$FxRolxW5XvSLAOksiC7MD1</code></pre> <p>Copy the encrypted version of the password (we need it for the next step), and then type quit to exit. Now, we need to edit the GRUB configuration. Edit the <code>/boot/grub/menu.lst</code> file, and find this section:</p> <pre><code>## password ['--md5'] passwd # If used in the first section of a menu file, disable all interactive editing # control (menu entry editor and command-line) and entries protected by the # command 'lock' # e.g. password topsecret # password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/ # password topsecret</code></pre> <p>Below that, add:</p> <pre><code>password --md5 $1$AlfMq1$FxRolxW5XvSLAOksiC7MD1 serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1 terminal --timeout=10 serial console</code></pre> <p>Note that the --unit=0 means that it will use the first serial port (ttyS0). If you're using the second serial port (ttyS1), change it to --unit=1. The last line tells GRUB to show its menu on both the serial line and the console (monitor).</p> <p>Now, we also need to edit the kernel sections, so that they output messages to the serial console. At the end of every kernel line, add console=tty0 console=ttyS0,38400n8 (replace ttyS0 with the correct serial port). In my case, it ended up looking like:</p> <pre><code>title Debian GNU/Linux, kernel 2.6.18-4-vserver-686 root (hd0,1) kernel /vmlinuz-2.6.18-4-vserver-686 root=/dev/hda3 ro console=tty0 console=ttyS0,38400n8 initrd /initrd.img-2.6.18-4-vserver-686 savedefault title Debian GNU/Linux, kernel 2.6.18-4-vserver-686 (single-user mode) root (hd0,1) kernel /vmlinuz-2.6.18-4-vserver-686 root=/dev/hda3 ro single console=tty0 console=ttyS0,38400n8 initrd /initrd.img-2.6.18-4-vserver-686 savedefault title Debian GNU/Linux, kernel 2.6.18-3-686 root (hd0,1) kernel /vmlinuz-2.6.18-3-686 root=/dev/hda3 ro console=tty0 console=ttyS0,38400n8 initrd /initrd.img-2.6.18-3-686 savedefault title Debian GNU/Linux, kernel 2.6.18-3-686 (single-user mode) root (hd0,1) kernel /vmlinuz-2.6.18-3-686 root=/dev/hda3 ro single console=tty0 console=ttyS0,38400n8 initrd /initrd.img-2.6.18-3-686 savedefault</code></pre>

页面列表

ITEM_HTML