{"id":7150,"date":"2019-01-22T23:11:18","date_gmt":"2019-01-22T22:11:18","guid":{"rendered":"https:\/\/pi3g.com\/?p=7150"},"modified":"2019-01-27T19:05:39","modified_gmt":"2019-01-27T18:05:39","slug":"debugging-the-alpine-boot-process","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/debugging-the-alpine-boot-process\/","title":{"rendered":"Fehlersuche im Alpine-Boot-Prozess"},"content":{"rendered":"<p>As discussed in my <a href=\"https:\/\/pi3g.com\/2019\/01\/10\/alpine-boot-process-on-the-raspberry-pi\/\" target=\"_blank\" rel=\"noopener\">previous post<\/a>, Alpine Linux goes through several stages when it boots.<\/p>\n<p>Just after mounting the boot media, and scanning it for apkovl\u2019s (with nlplug-findfs), there is an option for you to get a console, by setting $SINGLEMODE to yes.<\/p>\n<p>Setting SINGLEMODE to yes is easy, <span style=\"background-color: #ffff00;\">you simply add the word \u201c<strong>single<\/strong>\u201d to the cmdline.txt<\/span> (if on Raspberry Pi) \/ your kernel parameters (if not on Raspberry Pi):<\/p>\n<blockquote><p>modules=loop,squashfs,sd-mod,usb-storage <strong>single<\/strong> noquiet dwc_otg.lpm_enable=0 console=tty1<\/p><\/blockquote>\n<p>Note that I have also prepended the word quiet with no to effectively disable it \u2013 you will get more output during boot. (NB: this is actually the way this is meant to be done, as defined in the init script)<\/p>\n<p>Once you boot, this will drop you into a shell session (with ash, the built-in shell of busybox).<\/p>\n<p>Note: if you have set the root kernel parameter, to specify a root filesystem to boot from, your console is mounted <strong>before <\/strong>the root partition\u00a0 is mounted \u2013 probably so you can better debug it yourself.<\/p>\n<p>This single mode is very useful for trying boot configurations and debugging boot problems, and experimenting with the system and it\u2019s capabilities (which come <strong>entirely <\/strong>from the initramfs and the kernel).<\/p>\n<h2>can\u2019t access tty error<\/h2>\n<p>The following error is thrown when Single mode is enabled:<\/p>\n<blockquote><p>sh: can&#8217;t access tty: job control turned off<\/p><\/blockquote>\n<p>It seems to be related to sh\u2019s capabilities, and how it is executed \u2013 no need to be alarmed.<\/p>\n<h2>USB keyboard doesn\u2019t work<\/h2>\n<p><del>At first, the USB keyboard didn\u2019t work for me; I am not sure what the reason for this is. After several power cycles it started working. Maybe it can\u2019t be switched in via KVM.<\/del><\/p>\n<p><del>In any case, keep trying, it should work. Try to type immediately when the sh warning comes \u2026<\/del><\/p>\n<p>On the Pi 3B+ the keyboard does not work; it only works on a Pi 3A+. I suspect this is due to the additional internal USB Hub on the Pi 3B+ &#8211; please try to use a Pi 3A+ to debug in single mode. (I know, not ideal for networking setups).<\/p>\n<h2>Is there a shorter way to activate single mode? I am lazy<\/h2>\n<p>These are your options:<\/p>\n<blockquote><p>s|single|1<\/p><\/blockquote>\n<p>So you should be able to get into single mode by adding an \u201cs\u201d or a \u201c1\u201d to the cmdline.txt. Not tested by me.<\/p>\n<p>&nbsp;<\/p>\n<h2>How can I exit singlemode?<\/h2>\n<p>Type<\/p>\n<blockquote><p>exit<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2>What happens after the single mode check?<\/h2>\n<p>Our answer refers <strong>only <\/strong>to the RAM (\u201cdiskless\u201d) boot mode of Alpine Linux.<\/p>\n<p>The following operations are done only after the single mode check, so you will have to run them manually if you want:<\/p>\n<ul>\n<li>a tmpfs is mounted to \/sysroot ($sysroot)<\/li>\n<li>the apkovl location is set up \u2013 per default, if you did not specify the apkovl kernel parameter, nlplug-findfs will have tried to locate it for you on your boot media\n<ul>\n<li>there is, as discussed previously, also the option for you to obtain it via http, etc.<\/li>\n<\/ul>\n<\/li>\n<li>the pkgs kernel parameter is parsed \u2013 you can specify additional packages here, which the system should install\n<ul>\n<li>this parameter is useful in colloboration with alpine_repo \u2013 allowing you to inject additional packages into Alpine<\/li>\n<\/ul>\n<\/li>\n<li>the apkovl is unpacked<\/li>\n<li>if the file \/sysroot\/etc\/.default_boot_services exists or the apkovl location is not a file, then default boot services will be set up, and the file will be removed (so it will not be persisted in the apkovl when you do lbu commit)<\/li>\n<\/ul>\n<blockquote><p>if [ -f &#8220;$sysroot\/etc\/.default_boot_services&#8221; -o ! -f &#8220;$ovl&#8221; ]; then<br \/>\n# add some boot services by default<br \/>\nrc_add devfs sysinit<br \/>\nrc_add dmesg sysinit<br \/>\nrc_add mdev sysinit<br \/>\nrc_add hwdrivers sysinit<br \/>\nrc_add modloop sysinit<\/p>\n<p>rc_add hwclock boot<br \/>\nrc_add modules boot<br \/>\nrc_add sysctl boot<br \/>\nrc_add hostname boot<br \/>\nrc_add bootmisc boot<br \/>\nrc_add syslog boot<\/p>\n<p>rc_add mount-ro shutdown<br \/>\nrc_add killprocs shutdown<br \/>\nrc_add savecache shutdown<\/p>\n<p>rc_add firstboot default<\/p>\n<p>rm -f &#8220;$sysroot\/etc\/.default_boot_services&#8221;<br \/>\nfi<\/p><\/blockquote>\n<ul>\n<li>code for executing a splash screen is run<\/li>\n<li>it is checked whether \/sysroot\/etc\/fstab exists, and conditionally on that relocate_mount is executed<\/li>\n<li>alpine-base is always included in the packages which are going to be installed<\/li>\n<li>apk is prepared\n<ul>\n<li>optionally networking is configured so apk can pull the packages through the network<\/li>\n<li>it is also told that the packages are being installed in \u2013initramfs-diskless-boot mode, and told to display \u2013progress<\/li>\n<li>if quiet is set, then apk is told to stay &#8211;quiet<\/li>\n<\/ul>\n<\/li>\n<li>packages are installed to the root filesystem<\/li>\n<li>if the kernel option ssh_key is given, openssh is added to the packages and as a service\n<ul>\n<li>please note that you still need to pass in the key \u2013 this will happen either through a file in your apkovl or some other method<\/li>\n<li>as such, the option ssh_key might be a kind of fallback if you have turned off ssh and want it back again.<\/li>\n<\/ul>\n<\/li>\n<li>finally the root is switched into the new system which is built from the packages and the apkovl<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Note, for anyone wondering what the keep_apk_new kernel parameter is supposed to do:<\/p>\n<blockquote><p>if [ &#8220;$KOPT_keep_apk_new&#8221; != yes ]; then<br \/>\napkflags=&#8221;$apkflags &#8211;clean-protected&#8221;<br \/>\n[ -n &#8220;$ovlfiles&#8221; ] &amp;&amp; apkflags=&#8221;$apkflags &#8211;overlay-from-stdin&#8221;<br \/>\nfi<\/p><\/blockquote>\n<p>Please refer to the init file in the initramfs for further details.<\/p>\n<p>&nbsp;<\/p>\n<h2>References:<\/h2>\n<ul>\n<li><a href=\"https:\/\/ss64.com\/bash\/test.html\">https:\/\/ss64.com\/bash\/test.html<\/a>\u00a0 Useful page to understand the init file better (scripting in ash \/ bash)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>We\u2019re for hire<\/h2>\n<p>If you are looking to solve your Alpine Linux problem, and want consulting <a href=\"https:\/\/pi3g.com\/kontakt\" target=\"_blank\" rel=\"noopener\">we are for hire<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wie in meinem vorherigen Beitrag beschrieben, durchl\u00e4uft Alpine Linux beim Booten mehrere Phasen. Direkt nach dem Mounten des Bootmediums und dem Scannen nach apkovl's (mit nlplug-findfs), gibt es eine Option f\u00fcr Sie, eine Konsole zu erhalten, indem Sie $SINGLEMODE auf yes setzen. Die Einstellung von SINGLEMODE auf yes ist einfach, Sie f\u00fcgen einfach das Wort \"single\" hinzu...<\/p>","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[401],"tags":[506,507,435,505,504,502,503],"class_list":["post-7150","post","type-post","status-publish","format-standard","hentry","category-alpine-linux","tag-506","tag-alpine-boot-process","tag-alpine-linux","tag-s","tag-single","tag-single-mode","tag-singlemode"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/7150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=7150"}],"version-history":[{"count":3,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/7150\/revisions"}],"predecessor-version":[{"id":7269,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/7150\/revisions\/7269"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=7150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=7150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=7150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}