├── COPYING ├── COPYING.GPLv2 ├── INSTALL.md ├── README.md ├── etc ├── bb.d │ ├── conf │ │ ├── autologin.conf │ │ ├── dbus.conf │ │ ├── inittab │ │ ├── mdev.conf │ │ └── mkramfs.conf │ ├── exec │ │ ├── autologin │ │ ├── cgroups │ │ ├── sysfs_mods │ │ └── udhcpc.sh │ ├── init │ ├── mdev │ │ ├── ifgrp │ │ ├── input │ │ ├── map-dev-by │ │ ├── modalias │ │ └── usb-dev │ ├── rc.local │ ├── rc0 │ ├── rcS │ └── task │ │ ├── 010-sysdirs │ │ ├── 020-rootfs │ │ ├── 030-mdev │ │ ├── 040-modules │ │ ├── 050-fstab │ │ ├── 060-haveged │ │ ├── 070-urandom │ │ ├── 080-syslog │ │ ├── 090-sysctl │ │ ├── 100-network │ │ ├── 120-dbus │ │ ├── 130-alsa │ │ ├── 140-gpm │ │ └── 150-local └── kernel.d │ ├── post-install │ └── 99-bbinit │ └── post-remove │ └── 21-bbinit ├── install ├── chk-busybox.sh ├── chk-fstab.sh ├── finish.sh ├── help.sh └── install.sh └── usr └── share ├── bbinit ├── generic ├── init ├── kvck ├── lsramfs ├── mkramfs └── utils │ ├── bbck │ ├── findmemdisk │ ├── pxesrv │ └── solister ├── doc └── bbinit │ ├── FILES.txt │ ├── bugs.txt │ ├── busybox.txt │ ├── inittab.txt │ ├── mkramfs.txt │ ├── params.txt │ ├── task.txt │ └── utils.txt └── libalpm ├── hooks ├── 59-bbinit-remove.hook └── 91-bbinit-install.hook └── scripts ├── bbinit-install └── bbinit-remove /COPYING: -------------------------------------------------------------------------------- 1 | 2 | ======================================================================== 3 | **** Unless noted otherwise, all files from the "bbinit" project ***** 4 | **** are released under the following terms: ***** 5 | ======================================================================== 6 | 7 | Copyright (C) 2017,2018 Jeff Pohlmeyer 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to 11 | deal in the Software without restriction, including without limitation the 12 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 13 | sell copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included 17 | in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- 21 | ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 24 | OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | ======================================================================== 28 | 29 | Exceptions: 30 | =========== 31 | 32 | The "findmemdisk" script is adapted from "memdiskfind.c" by H. Peter Anvin, 33 | Copyright 2010 Intel Corp. and is released under the terms of the GPLv2. 34 | 35 | =========== 36 | 37 | The "map-dev-by" script is a modified version of the "storage-device" script 38 | from the "mdev-like-a-boss" project, Copyright (c) 2012, Piotr Karbowski; 39 | Please consult the license notice in the file for terms and conditions. 40 | 41 | =========== 42 | 43 | The "udhcpc.sh" script is adapted from Alpine Linux "default.script" 44 | Copyright (c) 2008 Natanael Copa 45 | Released under terms of GPLv2. 46 | 47 | =========== 48 | 49 | -------------------------------------------------------------------------------- /COPYING.GPLv2: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | AUTOMATED INSTALLATION: 2 | 3 | The simplest way to install bbinit on a running system 4 | is to run the command: 5 | 6 | ./install/install.sh -y 7 | 8 | In order to access the root filesystem, this command must be run as root, 9 | but you can test the result of the command as a normal user: 10 | 11 | mkdir /tmp/bbinit-test 12 | ./install/install.sh -y /tmp/bbinit-test/ 13 | 14 | IMPORTANT: In order to boot from the installed files, your bootloader must 15 | also be configured to use bbinit's /boot/ramfs file as the initrd, and 16 | /etc/bb.d/init as the init program. If you don't know how to configure your 17 | bootloader, this project is probably not for you. 18 | 19 | Because bbinit does not automatically mount the /tmp , /run and /dev/shm 20 | directories, your /etc/fstab file might also need to be edited. If you 21 | don't know how to edit your /etc/fstab file, this project is probably not 22 | for you. 23 | 24 | Pay careful attention to the output of the installer for more information 25 | on these steps. 26 | 27 | NOTE: The install script should also work to update an existing installation 28 | to a newer version. It will try to detect any user-modifed files and, 29 | depending on the nature of the change, will either install the new file as 30 | *.new or rename the existing file as *.old file. After the update has 31 | completed you should check for these files and compare them to see if any 32 | of your locally modified have been affected. 33 | 34 | 35 | MANUAL INSTALLATION: 36 | 37 | If you would prefer to install bbinit manually, to better understand the 38 | way bbinit works, you can do things the old-fashioned way by following 39 | the steps below: 40 | 41 | 1. Copy the contents of bbinit/etc to /etc/ 42 | 43 | 2. If you don't already have a file named /etc/inittab, create a symbolic 44 | link from /etc/bb.d/conf/inittab to /etc/inittab like this: 45 | ln -s bb.d/conf/inittab /etc/ 46 | (If you already have a /etc/inittab file, leave it alone - your current 47 | init system probably needs it!) 48 | 49 | 3. If you don't already have a file named /etc/mdev.conf, create a symbolic 50 | link from /etc/bb.d/conf/mdev.conf to /etc/mdev.conf like this: 51 | ln -s bb.d/conf/mdev.conf /etc/ 52 | (If you already have a /etc/mdev.conf file, leave it alone - your current 53 | system probably needs it!) 54 | 55 | 4. Make sure you have a statically linked, fully functional /bin/busybox 56 | or /bin/busybox.static installed on your system. If you run the command: 57 | 'ldd /bin/busybox' on a GNU/Linux system, it should report: 58 | "Not a dynamic executable" <= (This is what you want) 59 | If your distro doesn't provide a usable busybox package, you should 60 | be able to download one from: https://busybox.net/downloads/binaries/ 61 | Look under the latest /*-defconfig-multiarch/ subdirectory for one that 62 | matches your machine's architecture. 63 | 64 | 5. Copy the contents of bbinit/usr/share/bbinit/ to /usr/share/bbinit/ 65 | 66 | 6. Run the command: /usr/share/bbinit/mkramfs 67 | 68 | 7. Edit your bootloader config and add an entry specifying /boot/ramfs 69 | as the initrd and init=/etc/bb.d/init 70 | 71 | 8. Cross your fingers, say a prayer, or whatever makes you feel invincible, 72 | and reboot, choosing your new bootloader option when prompted. 73 | 74 | 9. If something went wrong, should still be able to boot using your previous 75 | bootloader option. If not, you might need to boot from external media to 76 | fix things. 77 | 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bbinit is a minimal init system based on busybox. It is mostly developed 2 | and tested on Arch Linux and Alpine Linux but should be usable on other 3 | Linux distributions if you're willing to experiment. (I have had some 4 | success using it to boot OpenSuSE, Slackware, and VoidLinux.) 5 | 6 | Please note that bbinit simply launches a bare minimum of processes used 7 | to configure the system at startup and attempts to stop everything cleanly 8 | at shutdown. It is NOT a "service manager" 9 | 10 | To setup bbinit on an existing system, refer to the instructions in the 11 | ./INSTALL file. 12 | 13 | For a more detailed explanation of bbinit, check out the files in the 14 | ./usr/share/doc/bbinit/ directory. The file named "FILES.txt" is a good 15 | place to start. 16 | 17 | -------------------------------------------------------------------------------- /etc/bb.d/conf/autologin.conf: -------------------------------------------------------------------------------- 1 | # If you set AUTOLOGIN= to a valid username, that user will automatically 2 | # be logged in on tty1 at startup. (Use with caution!) 3 | 4 | # If set to a single question mark [AUTOLOGIN=?] the value will be determined 5 | # from the kernel boot parameter "autologin=" (Use with EXTREME caution!) 6 | 7 | # If AUTOLOGIN is empty, tty1 will behave as a normal login console. 8 | 9 | AUTOLOGIN= 10 | 11 | -------------------------------------------------------------------------------- /etc/bb.d/conf/dbus.conf: -------------------------------------------------------------------------------- 1 | # Some programs rely on /etc/machine-id to uniquely identify machines 2 | # on a network. Some people may consider this to be a security/privacy 3 | # concern, in spite of the fact that there are plenty of other ways to 4 | # fingerprint a machine. Set BBI_PERSIST_MACH_ID to zero if you would 5 | # prefer having a fresh machine-id on each reboot, or non-zero if you 6 | # want to always keep the same machine-id. 7 | 8 | BBI_PERSIST_MACH_ID=1 9 | 10 | -------------------------------------------------------------------------------- /etc/bb.d/conf/inittab: -------------------------------------------------------------------------------- 1 | # /etc/inittab 2 | 3 | ::sysinit:/etc/bb.d/rcS 4 | 5 | tty1::respawn:/lib/bb/getty -n -l /etc/bb.d/exec/autologin 0 tty1 6 | tty2::respawn:getty 0 -l login tty2 7 | tty3::respawn:getty 0 -l login tty3 8 | tty4::respawn:getty 0 -l login tty4 9 | tty5::respawn:getty 0 -l login tty5 10 | tty6::respawn:getty 0 -l login tty6 11 | 12 | # Stuff to do for the 3-finger salute 13 | ::ctrlaltdel:reboot 14 | 15 | # Stuff to do before rebooting 16 | ::shutdown:/etc/bb.d/rc0 17 | 18 | -------------------------------------------------------------------------------- /etc/bb.d/conf/mdev.conf: -------------------------------------------------------------------------------- 1 | # Devices: 2 | # Syntax: %s %d:%d %s 3 | # devices user:group mode 4 | 5 | # support module loading on hotplug 6 | $MODALIAS=.* 0:0 660 @/etc/bb.d/mdev/modalias "$MODALIAS" 7 | 8 | bus/usb/[0-9]+/[0-9]+ 0:0 0660 */etc/bb.d/mdev/usb-dev 9 | 10 | null 0:0 0666 @chmod 666 $MDEV 11 | zero 0:0 0666 12 | grsec 0:0 0660 13 | full 0:0 0666 14 | 15 | random 0:0 0666 16 | urandom 0:0 0444 17 | hwrandom 0:0 0660 18 | 19 | kmem 0:0 0640 20 | mem 0:0 0640 21 | port 0:0 0640 22 | fuse 0:0 0666 23 | 24 | fd0 0:0 0660 @/etc/bb.d/mdev/ifgrp floppy ln -sf $MDEV floppy 25 | sr0 0:0 0660 @/etc/bb.d/mdev/ifgrp optical ln -sf $MDEV cdrom 26 | 27 | sd[a-z].* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 28 | vd[a-z].* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 29 | hd[a-z].* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 30 | md[0-9]* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 31 | dm-[0-9]* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 32 | bcache[0-9]* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 33 | mmcblk[0-9].* 0:0 0660 */etc/bb.d/mdev/ifgrp disk /etc/bb.d/mdev/map-dev-by 34 | 35 | ram([0-9]*) 0:0 0660 >rd/%1 @/etc/bb.d/mdev/ifgrp disk 36 | loop([0-9]+) 0:0 0660 >loop/%1 @/etc/bb.d/mdev/ifgrp disk 37 | cciss!(.*) 0:0 0660 =cciss/%1 @/etc/bb.d/mdev/ifgrp disk 38 | ida!(.*) 0:0 0660 =ida/%1 @/etc/bb.d/mdev/ifgrp disk 39 | rd!(.*) 0:0 0660 =rd/%1 @/etc/bb.d/mdev/ifgrp disk 40 | 41 | console 0:0 0600 @/etc/bb.d/mdev/ifgrp tty 42 | ptmx 0:0 0666 @/etc/bb.d/mdev/ifgrp tty 43 | pty.* 0:0 0660 @/etc/bb.d/mdev/ifgrp tty 44 | vcs[0-9]* 0:0 0660 @/etc/bb.d/mdev/ifgrp tty 45 | vcsa[0-9]* 0:0 0660 @/etc/bb.d/mdev/ifgrp tty 46 | 47 | tty 0:0 0660 @/etc/bb.d/mdev/ifgrp tty 48 | tty[0-9] 0:0 0660 @/etc/bb.d/mdev/ifgrp tty 49 | tty[0-9][0-9] 0:0 0660 @/etc/bb.d/mdev/ifgrp tty 50 | ttyS[0-9]* 0:0 0660 @/etc/bb.d/mdev/ifgrp uucp 51 | 52 | snd/control.* 0:0 0660 @/etc/bb.d/mdev/ifgrp audio 53 | snd/hw.* 0:0 0660 @/etc/bb.d/mdev/ifgrp audio 54 | snd/pcm.* 0:0 0660 @/etc/bb.d/mdev/ifgrp audio 55 | snd/timer 0:0 0660 @/etc/bb.d/mdev/ifgrp audio 56 | 57 | adsp 0:0 0660 >sound/ @/etc/bb.d/mdev/ifgrp audio 58 | audio 0:0 0660 >sound/ @/etc/bb.d/mdev/ifgrp audio 59 | dsp 0:0 0660 >sound/ @/etc/bb.d/mdev/ifgrp audio 60 | mixer 0:0 0660 >sound/ @/etc/bb.d/mdev/ifgrp audio 61 | sequencer.* 0:0 0660 >sound/ @/etc/bb.d/mdev/ifgrp audio 62 | 63 | agpgart 0:0 0660 >misc/ 64 | psaux 0:0 0660 >misc/ 65 | rtc 0:0 0664 >misc/ 66 | 67 | input/event[0-9]+ 0:0 0660 */etc/bb.d/mdev/input 68 | input/mice 0:0 0660 @/etc/bb.d/mdev/ifgrp input 69 | input/mouse[0-9] 0:0 0640 70 | 71 | fb0 0:0 0660 @/etc/bb.d/mdev/ifgrp video 72 | dri/card[0-9] 0:0 0660 @/etc/bb.d/mdev/ifgrp video 73 | dri/render.* 0:0 0660 @/etc/bb.d/mdev/ifgrp video 74 | vbi[0-9] 0:0 0660 @/etc/bb.d/mdev/ifgrp video 75 | video[0-9]+ 0:0 0660 @/etc/bb.d/mdev/ifgrp video 76 | 77 | tun[0-9]* 0:0 0600 =net/ 78 | tap[0-9]* 0:0 0600 =net/ 79 | 80 | kvm 0:0 0660 @/etc/bb.d/mdev/ifgrp kvm 81 | net/tun 0:0 0660 @/etc/bb.d/mdev/ifgrp kvm 82 | 83 | # fallback for any!device -> any/device 84 | (.*)!(.*) 0:0 0660 =%1/%2 85 | 86 | -------------------------------------------------------------------------------- /etc/bb.d/conf/mkramfs.conf: -------------------------------------------------------------------------------- 1 | BBI_EXTRA_MODULES='ext2 ext3 ext4' 2 | BBI_COMPRESSOR='gzip' 3 | BBI_EXTRA_FILES='' 4 | BBI_MODULES_PATH='/lib/modules' 5 | BBI_HOST_BUSYBOX='/lib/bb/busybox' 6 | -------------------------------------------------------------------------------- /etc/bb.d/exec/autologin: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | [ -f /etc/bb.d/conf/autologin.conf ] && . /etc/bb.d/conf/autologin.conf 5 | 6 | # If no username is specified, fallback to normal login prompt 7 | [ "x$AUTOLOGIN" = 'x' ] && exec getty 0 -l login tty1 8 | 9 | # If username is '?' try to find "autologin=" on kernel command line 10 | if [ "$AUTOLOGIN" = '?' ] && [ -r '/proc/cmdline' ]; then 11 | for A in $(cat '/proc/cmdline') ; do 12 | case "$A" in 13 | autologin=*) 14 | AUTOLOGIN=${A#*=} 15 | break 16 | ;; 17 | esac 18 | done 19 | fi 20 | 21 | # If numeric value, consider it as a UID 22 | if printf '%d' "$AUTOLOGIN" &> /dev/null ; then 23 | AUTOLOGIN=$( 24 | awk -F : '{if ( $3 == "'$AUTOLOGIN'") {print $1}}' /etc/passwd 25 | ) 26 | fi 27 | 28 | # If username is invalid, fallback to normal login prompt 29 | id -u "$AUTOLOGIN" &> /dev/null || exec getty 0 tty1 30 | 31 | exec login -f "$AUTOLOGIN" 32 | 33 | -------------------------------------------------------------------------------- /etc/bb.d/exec/cgroups: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | TopDir='/sys/fs/cgroup' 4 | MntOpts='nodev,noexec,nosuid' 5 | RcName='openrc' 6 | RcDir="$TopDir/$RcName" 7 | 8 | if [ $# -eq 0 ] ; then # Mount the logind (openrc) namespace... 9 | HaveCG=false 10 | while read nodev fs ; do 11 | [ "$nodev" = 'nodev' ] && [ "$fs" = 'cgroup' ] && HaveCG=true && break 12 | done < /proc/filesystems 13 | if ! $HaveCG; then 14 | logger -s -t bbinit daemon.warn 'Kernel does not support cgroups' 15 | exit 1 16 | fi 17 | mountpoint -q "$TopDir" || 18 | mount -t tmpfs -o "$MntOpts,mode=755,size=10m" cgroup_root $TopDir 19 | mountpoint -q "$RcDir" && exit 0 20 | RelAgnt="release_agent="$(readlink -f "$0") 21 | mkdir -p "$RcDir" 22 | mount -t cgroup -o "none,$MntOpts,name=$RcName,$RelAgnt" $RcName "$RcDir" 23 | printf 1 > "$RcDir/notify_on_release" 24 | else # Here we act as the "release_agent" when logind unmounts a subdir... 25 | Dir="$RcDir/$1" 26 | [ -d "$Dir" ] && rmdir "$Dir" 27 | fi 28 | 29 | -------------------------------------------------------------------------------- /etc/bb.d/exec/sysfs_mods: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | ######################################################################## 4 | # Script to search the /sys/devices/ directory for "modalias" files. 5 | # If it finds any it will attempt to resolve the alias and load 6 | # the corresponding module, unless it is blacklisted in 7 | # /etc/modprobe.{conf,d} . If you want this script to run at boot-up, 8 | # you can create the following symbolic link: 9 | # 10 | # mkdir -p /etc/bb.d/conf/tasks 11 | # ln -s /etc/bb.d/exec/sysfs_mods /etc/bb.d/conf/tasks/modules.post_start 12 | # 13 | # This will probably increase your boot-up time by around 2 to 4 seconds, 14 | # possibly loading some modules that aren't needed, and might even cause 15 | # some undesirable side effects. On the other hand it can sometimes ease 16 | # the pain of managing new hardware. 17 | # 18 | # The script accepts some command line options, see the _usage() function 19 | # below for details, or run with -h for help. 20 | # 21 | # In some cases, inserting a module will cause new devices to appear, 22 | # so the script will re-scan the /sys/ directory a few times until 23 | # no new modalias files are found. This may result in more than one line 24 | # of -v output. (This obviously will not happen when running in "-n" mode.) 25 | ######################################################################## 26 | 27 | 28 | _usage () { 29 | cat << EOF >&2 30 | 31 | Searches the /sys/devices/ directory for "modalias" files, resolves 32 | the alias to a module name, and (optionally) loads the module. 33 | The following options are supported: 34 | 35 | -n Print the module names to stdout, rather than loading them. 36 | (This is the default behavior when running as a non-root user.) 37 | 38 | -v Print the names of the modules being loaded. 39 | 40 | -k Assume kernel version is ; defaults to \`uname -r\` 41 | (Use with care: Module names etc. can vary between kernels!) 42 | 43 | -a Show all modules found in /sys/devices 44 | (Includes loaded and blacklisted modules; implies -n) 45 | 46 | -h Print this help and exit. 47 | 48 | EOF 49 | } 50 | 51 | 52 | # The "modules.alias" file is just a long list of shell-style wildcard patterns 53 | # and their respective module names. We can use a case/esac block from ash 54 | # (or dash or bash) to test for a match, but scanning through 30,000+ patterns 55 | # each time can be painfully slow. We can speed things up considerably by keying 56 | # on the first character of the alias, and use a separate case block for each 57 | # one, wrapping it in its own function named lookup_X, where X is the initial 58 | # character of the alias we are searching for. 59 | 60 | _create_lookup_tables () { 61 | local ModAliasTmp=$TempDir/ModAliasTmp 62 | sort "$ModAlias" > "$ModAliasTmp" 63 | local footer='esac; printf "%s\n" "$M"; }' 64 | LookUp=$TempDir/LookUp 65 | C='' 66 | while read X A M ; do 67 | [ "$X" = 'alias' ] || continue 68 | I=${A:0:1} 69 | if [ "$I" != "$C" ]; then 70 | [ "$C" ] && echo $footer 71 | LookupFuncs="$LookupFuncs _lookup_$I" 72 | echo "_lookup_$I" '() { local M; case "$1" in' 73 | C="$I" 74 | fi 75 | case "$A" in 76 | *"("*) 77 | A=${A//(/\"(\"} 78 | A=${A//)/\")\"} 79 | ;; 80 | esac 81 | echo "$A) M='${M//-/_}' ;;" 82 | done < "$ModAliasTmp" > "$LookUp" 83 | echo $footer >> "$LookUp" 84 | rm -f "$ModAliasTmp" 85 | . "$LookUp" 86 | rm -f "$LookUp" 87 | } 88 | 89 | 90 | _get_sysfs_mods () { 91 | local Alias 92 | for Alias in $( 93 | find /sys/devices/ -type f -name modalias \ 94 | -exec cat {} + 2> /dev/null | sort -u 95 | ) ; do 96 | _lookup_${Alias:0:1} "$Alias" 97 | done | sort -u 98 | } 99 | 100 | 101 | _list_pending_mods () { 102 | local SysFsMods=$(_get_sysfs_mods) 103 | local ProcFsMods= 104 | local AvailableMods= 105 | local ModName Else 106 | while read ModName Else; do 107 | ProcFsMods="$ProcFsMods ${ModName//-/_}" 108 | done < /proc/modules 109 | for SysFsMod in $SysFsMods; do 110 | local GotIt=0 111 | local SkipIt=0 112 | if [ $ShowAll = 0 ]; then 113 | for ProcFsMod in $ProcFsMods; do 114 | [ "$SysFsMod" = "$ProcFsMod" ] && GotIt=1 && break 115 | done 116 | for Excluded in $BlackList; do 117 | [ "$SysFsMod" = "$Excluded" ] && SkipIt=1 && break 118 | done 119 | fi 120 | [ $GotIt = 0 ] && [ $SkipIt = 0 ] && AvailableMods="$AvailableMods $SysFsMod" 121 | done 122 | echo $AvailableMods 123 | } 124 | 125 | 126 | _build_blacklist () { 127 | local Key Val Else ModName BlackList 128 | for Conf in \ 129 | /lib/modprobe.d/*.conf \ 130 | /usr/local/lib/modprobe.d/*.conf \ 131 | /run/modprobe.d/*.conf \ 132 | /etc/modprobe.d/*.conf 133 | do 134 | [ -f "$Conf" ] || continue 135 | while read Key Val Else; do 136 | [ "$Key" = 'blacklist' ] || continue 137 | ModName=$(_lookup_${Val:0:1} "$Val") 138 | [ "x$ModName" = 'x' ] && ModName=$Val 139 | BlackList="$BlackList ${ModName//-/_}" 140 | done < $Conf 141 | done 142 | echo "$BlackList" 143 | } 144 | 145 | 146 | _load_sysfs_mods () { 147 | local UID=$(id -u) 148 | local KVER=$(uname -r) 149 | local NoOp=0 150 | local ShowCmd=0 151 | local ShowAll=0 152 | [ "$UID" = 0 ] || NoOp=1 153 | while getopts avnk:h OPT ; do 154 | case ${OPT} in 155 | a) ShowAll=1;; 156 | v) ShowCmd=1;; 157 | n) NoOp=1;; 158 | h) _usage; return 0;; 159 | k) KVER="${OPTARG%/}/";; 160 | ?) _usage; return 1;; 161 | esac 162 | done 163 | [ $NoOp = 1 ] && ShowCmd=1 164 | local ModAlias=/lib/modules/$KVER/modules.alias 165 | if ! [ -f "$ModAlias" ] ; then 166 | echo "Error: Cannot find '$ModAlias'" 167 | return 1 168 | fi 169 | [ -w /dev ] && TempDir=/dev || TempDir=/tmp # /dev > /tmp for early boot 170 | local Template=$(printf 'SysFsModAlias-%x%xXXXXXX' $RANDOM $$) 171 | TempDir=$(mktemp -d -p $TempDir $Template) || return 1 172 | local LookupFuncs 173 | _create_lookup_tables 174 | local Pending= 175 | local Len=${#Pending} 176 | local BlackList=$(_build_blacklist) 177 | local Loops=0 # Loading a module might cause more devices to appear 178 | while [ $Loops -lt 16 ] ; do 179 | Len=${#Pending} 180 | Pending=$(_list_pending_mods) 181 | [ $Len = ${#Pending} ] && break # Nothing more to add 182 | if [ $ShowAll = 1 ]; then 183 | echo $Pending 184 | break 185 | else 186 | [ $ShowCmd = 1 ] && echo $Pending 187 | [ $NoOp = 1 ] && break 188 | modprobe -ab $Pending 189 | sleep .1 190 | fi 191 | Loops=$((Loops+1)) 192 | done 193 | rmdir $TempDir 194 | unset -f _create_lookup_tables _get_sysfs_mods _list_pending_mods \ 195 | _load_sysfs_mods _build_blacklist $LookupFuncs 196 | } 197 | 198 | _load_sysfs_mods $@ 199 | 200 | -------------------------------------------------------------------------------- /etc/bb.d/exec/udhcpc.sh: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | # script for udhcpc 5 | # Copyright (c) 2008 Natanael Copa 6 | 7 | UDHCPC="/etc/udhcpc" 8 | UDHCPC_CONF="$UDHCPC/udhcpc.conf" 9 | 10 | RESOLV_CONF="/etc/resolv.conf" 11 | [ -f $UDHCPC_CONF ] && . $UDHCPC_CONF 12 | 13 | export broadcast 14 | export dns 15 | export domain 16 | export interface 17 | export ip 18 | export mask 19 | export metric 20 | export router 21 | export subnet 22 | 23 | export PATH=/etc/bb.d/exec:/usr/bin:/bin:/usr/sbin:/sbin 24 | 25 | run_scripts() { 26 | local dir=$1 27 | if [ -d $dir ]; then 28 | for i in $dir/*; do 29 | [ -f $i ] && $i 30 | done 31 | fi 32 | } 33 | 34 | deconfig() { 35 | ip -4 addr flush dev $interface 36 | } 37 | 38 | is_wifi() { 39 | test -e /sys/class/net/$interface/phy80211 40 | } 41 | 42 | if_index() { 43 | if [ -e /sys/class/net/$interface/ifindex ]; then 44 | cat /sys/class/net/$interface/ifindex 45 | else 46 | ip -4 link show dev $interface | head -n1 | cut -d: -f1 47 | fi 48 | } 49 | 50 | calc_metric() { 51 | local base= 52 | if is_wifi; then 53 | base=300 54 | else 55 | base=200 56 | fi 57 | echo $(( $base + $(if_index) )) 58 | } 59 | 60 | routes() { 61 | [ -z "$router" ] && return 62 | for i in $NO_GATEWAY; do 63 | [ "$i" = "$interface" ] && return 64 | done 65 | local gw= num= 66 | while ip -4 route del default via dev $interface 2>/dev/null; do 67 | : 68 | done 69 | num=0 70 | for gw in $router; do 71 | ip -4 route add 0.0.0.0/0 via $gw dev $interface \ 72 | metric $(( $num + ${IF_METRIC:-$(calc_metric)} )) 73 | num=$(( $num + 1 )) 74 | done 75 | } 76 | 77 | resolvconf() { 78 | local i 79 | [ -n "$IF_PEER_DNS" ] && [ "$IF_PEER_DNS" != "yes" ] && return 80 | if [ "$RESOLV_CONF" = "no" ] || [ "$RESOLV_CONF" = "NO" ] \ 81 | || [ -z "$RESOLV_CONF" ]; then 82 | return 83 | fi 84 | for i in $NO_DNS; do 85 | [ "$i" = "$interface" ] && return 86 | done 87 | local resolv_tmp=$(mktemp /tmp/resolv_conf_XXXXXX) 88 | echo -n > "$resolv_tmp" 89 | if [ -n "$search" ]; then 90 | echo "search $search" >> "$resolv_tmp" 91 | elif [ -n "$domain" ]; then 92 | echo "search $domain" >> "$resolv_tmp" 93 | fi 94 | for i in $dns; do 95 | echo "nameserver $i" >> "$resolv_tmp" 96 | done 97 | cat "$resolv_tmp" > "$RESOLV_CONF" 98 | rm -f "$resolv_tmp" 99 | } 100 | 101 | bound() { 102 | ip -4 addr add $ip/$mask ${broadcast:+broadcast $broadcast} dev $interface 103 | ip -4 link set dev $interface up 104 | routes 105 | resolvconf 106 | } 107 | 108 | renew() { 109 | if ! ip -4 addr show dev $interface | grep $ip/$mask; then 110 | ip -4 addr flush dev $interface 111 | ip -4 addr add $ip/$mask ${broadcast:+broadcast $broadcast} dev $interface 112 | fi 113 | 114 | local i 115 | for i in $router; do 116 | if ! ip -4 route show | grep ^default | grep $i; then 117 | routes 118 | break 119 | fi 120 | done 121 | 122 | if ! grep "^search $domain"; then 123 | resolvconf 124 | return 125 | fi 126 | for i in $dns; do 127 | if ! grep "^nameserver $i"; then 128 | resolvconf 129 | return 130 | fi 131 | done 132 | } 133 | 134 | case "$1" in 135 | deconfig|renew|bound) 136 | run_scripts $UDHCPC/pre-$1 137 | $1 138 | run_scripts $UDHCPC/post-$1 139 | ;; 140 | leasefail) 141 | echo "udhcpc failed to get a DHCP lease" >&2 142 | ;; 143 | nak) 144 | echo "udhcpc received DHCP NAK" >&2 145 | ;; 146 | *) 147 | echo "Error: this script should be called from udhcpc" >&2 148 | exit 1 149 | ;; 150 | esac 151 | exit 0 152 | 153 | -------------------------------------------------------------------------------- /etc/bb.d/init: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | [ -f /etc/inittab ] && [ -f /etc/bb.d/conf/inittab ] && \ 5 | ! /lib/bb/busybox diff -q /etc/bb.d/conf/inittab /etc/inittab && \ 6 | /lib/bb/busybox mount --bind /etc/bb.d/conf/inittab /etc/inittab 7 | 8 | exec /lib/bb/busybox init $@ 9 | 10 | -------------------------------------------------------------------------------- /etc/bb.d/mdev/ifgrp: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | # Change device's group ownership to $1, then execute remaining args. 5 | [ "x$1" != 'x' ] && [ -e "$MDEV" ] || exit 1 6 | [ "$ACTION" = 'add' ] && [ -f /etc/group ] && \ 7 | grep -q "^$1:" /etc/group && chgrp "$1" "$MDEV" 8 | [ $# -gt 1 ] && shift && exec $@ 9 | 10 | -------------------------------------------------------------------------------- /etc/bb.d/mdev/input: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | # An attempt to populate /run/udev/data/ with the appropriate 4 | # input device information, for systems with Xorg/libinput but 5 | # without a running udev daemon. Partially working but does 6 | # not support dynamic input device connections, e.g. unplugging 7 | # and re-plugging the keyboard or mouse will cause it to stop 8 | # functioning.) 9 | 10 | pidof udevd > /dev/null && exit 0 11 | 12 | [ "$ACTION" = 'add' ] || exit 0 13 | [ "$SUBSYSTEM" = 'input' ] || exit 0 14 | 15 | mountpoint -q /run || exit 0 16 | 17 | EVENTN=${MDEV##*/} 18 | DEVPATH=$(readlink -f "/sys/class/input/$EVENTN") 19 | INPUTN=${DEVPATH%/*} 20 | INPUTN=${INPUTN##*/} 21 | CAPS= 22 | ID_BUS= 23 | ID_SERIAL= 24 | ID_VENDOR_ID= 25 | ID_MODEL_ID= 26 | 27 | GRP='input' 28 | grep -q "^$GRP:" /etc/group && chgrp "$GRP" "/dev/$MDEV" 29 | 30 | cd "$DEVPATH" || exit 1 31 | 32 | EV_SYN=0x00 33 | EV_KEY=0x01 34 | EV_REL=0x02 35 | EV_ABS=0x03 36 | EV_MSC=0x04 37 | EV_SW=0x05 38 | EV_LED=0x11 39 | EV_SND=0x12 40 | EV_REP=0x14 41 | EV_FF=0x15 42 | EV_PWR=0x16 43 | EV_FF_STATUS=0x17 44 | 45 | CAP=0x$(cat device/capabilities/ev) 46 | 47 | if [ $((CAP&2**EV_KEY)) -ne 0 ] && [ $((CAP&2**EV_REP)) -ne 0 ] ; then 48 | CAPS='K' 49 | else 50 | if [ $((CAP&2**EV_REL)) -ne 0 ] && [ $((CAP&2**EV_ABS)) -eq 0 ] ; then 51 | CAPS='M' 52 | else 53 | if [ $((CAP&2**EV_KEY)) -ne 0 ] && [ $((CAP&2**EV_ABS)) -ne 0 ] ; then 54 | CAPS='T' 55 | else 56 | : 57 | exit 58 | fi 59 | fi 60 | fi 61 | 62 | INDEX=$$ 63 | 64 | ID_SERIAL=$(cat device/name) 65 | ID_SERIAL=${ID_SERIAL// /_} 66 | BUSTYPE=$(cat device/id/bustype) 67 | 68 | case "$BUSTYPE" in 69 | 0001) ID_BUS='pci' ;; 70 | 0002) ID_BUS='isapnp' ;; 71 | 0003) ID_BUS='usb' ;; 72 | 0004) ID_BUS='hil' ;; 73 | 0005) ID_BUS='bluetooth' ;; 74 | 0006) ID_BUS='virtual' ;; 75 | 0010) ID_BUS='isa' ;; 76 | 0011) ID_BUS='i8042' ;; 77 | 0012) ID_BUS='xtkbd' ;; 78 | 0013) ID_BUS='rs232' ;; 79 | 0014) ID_BUS='gameport' ;; 80 | 0015) ID_BUS='parport' ;; 81 | 0016) ID_BUS='amiga' ;; 82 | 0017) ID_BUS='adb' ;; 83 | 0018) ID_BUS='i2c' ;; 84 | 0019) ID_BUS='host' ;; 85 | 001A) ID_BUS='gsc' ;; 86 | 001B) ID_BUS='atari' ;; 87 | 001C) ID_BUS='spi' ;; 88 | 001D) ID_BUS='rmi' ;; 89 | 001E) ID_BUS='cec' ;; 90 | 001F) ID_BUS='intel_ishtp' ;; 91 | *) ID_BUS='unknown' ;; 92 | esac 93 | 94 | HWPATH=$DEVPATH 95 | while [ ${#HWPATH} -gt 5 ] ; do 96 | if [ -f $HWPATH/idProduct ] && [ -f $HWPATH/idVendor ]; then 97 | ID_MODEL_ID=$(cat $HWPATH/idProduct) 98 | ID_VENDOR_ID=$(cat $HWPATH/idVendor) 99 | break 100 | fi 101 | NEXT=${HWPATH%/*} 102 | [ "${#NEXT}" -lt "${#HWPATH}" ] && HWPATH=$NEXT || break 103 | done 104 | 105 | print_caps () { 106 | case "$CAPS" in 107 | K) printf "%s\n%s\n%s\n" 'E:ID_INPUT=1' 'E:ID_INPUT_KEY=1' 'E:ID_INPUT_KEYBOARD=1' ;; 108 | M) printf "%s\n%s\n" 'E:ID_INPUT=1' 'E:ID_INPUT_MOUSE=1' ;; 109 | T) printf "%s\n%s\n" 'E:ID_INPUT=1' 'E:ID_INPUT_TOUCHPAD=1' ;; 110 | esac 111 | } 112 | 113 | print_make_and_model () { 114 | [ "$ID_VENDOR_ID" ] && echo "E:ID_VENDOR_ID=$ID_VENDOR_ID" 115 | [ "$ID_MODEL_ID" ] && echo "E:ID_MODEL_ID=$ID_MODEL_ID" 116 | } 117 | 118 | 119 | OUTDIR='/run/udev/data' 120 | mkdir -m 755 -p "${OUTDIR%/*}" 121 | mkdir -m 755 -p "$OUTDIR" 122 | 123 | OUTFILE="$OUTDIR/+input:$INPUTN" 124 | 125 | cat << EOF > "$OUTFILE" 126 | E:ID_BUS=$ID_BUS 127 | E:ID_SERIAL=$ID_SERIAL 128 | $(print_make_and_model) 129 | $(print_caps) 130 | I:$(printf '%08d' ${INDEX}1) 131 | G:seat 132 | EOF 133 | 134 | OUTFILE=$OUTDIR/$(stat -c "0x%t 0x%T" "/dev/$MDEV" | awk '{printf("c%d:%d\n",$1,$2)}') 135 | 136 | cat << EOF > "$OUTFILE" 137 | E:ID_BUS=$ID_BUS 138 | E:ID_SERIAL=$ID_SERIAL 139 | $(print_make_and_model) 140 | $(print_caps) 141 | I:$(printf '%08d' ${INDEX}2) 142 | EOF 143 | 144 | -------------------------------------------------------------------------------- /etc/bb.d/mdev/map-dev-by: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | # Copyright (c) 2012, Piotr Karbowski 5 | # All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without modification, are 8 | # permitted provided that the following conditions are met: 9 | # 10 | # * Redistributions of source code must retain the above copyright notice, this list 11 | # of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above copyright notice, this list 13 | # of conditions and the following disclaimer in the documentation and/or other 14 | # materials provided with the distribution. 15 | # * Neither the name of the Piotr Karbowski nor the names of its contributors may be 16 | # used to endorse or promote products derived from this software without specific 17 | # prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 24 | # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | # This script meant to create /dev/disk/by-* and /dev/mapper/* symlinks. 30 | # and remove them after storage device is removed. 31 | # the /dev/disk/by-* handling based on the idea and proof of concept from BitJam. 32 | 33 | # debug 34 | #exec >> /run/debug-mdev 2>&1 35 | #set -x 36 | #echo '### ENV:' 37 | #env 38 | #echo '### CODE:' 39 | # 40 | 41 | umask 077 42 | 43 | storage_dir="/dev/.mdev" 44 | [ -d "${storage_dir}" ] || mkdir -p "${storage_dir}" 45 | 46 | [ "${MDEV}" ] || exit 2 47 | 48 | create_uuid_label_symlink() { 49 | local target_dir="/dev/disk/by-${1}" 50 | local target_symlink="${target_dir}/${2}" 51 | [ -e "${target_symlink}" ] && return 52 | mkdir -p "${target_dir}" 53 | local temp_symlink=$(mktemp -p "${target_dir}" $$-XXXXXX) 54 | ln -snf /dev/${MDEV} "${temp_symlink}" 55 | mv -fT "${temp_symlink}" "${target_symlink}" 56 | rm -f "${temp_symlink}" 57 | echo "${target_symlink}" >"${storage_dir}/storage_symlink_${1}_${MDEV}" 58 | } 59 | 60 | add_symlinks() { 61 | # Skip temp cryptsetup nodes. 62 | case "${MDEV}" in 63 | 'dm-'[0-9]*) 64 | case "$(cat "/sys/block/${MDEV}/dm/name")" in 65 | 'temporary-cryptsetup-'[0-9]*) 66 | return 0 67 | ;; 68 | esac 69 | ;; 70 | esac 71 | 72 | if command -v blkid >/dev/null 2>&1; then 73 | local field name value UUID LABEL TYPE PTTYPE PARTLABEL PARTUUID 74 | local blkid_output="$(blkid "/dev/${MDEV}")" 75 | eval "${blkid_output#*: }" 76 | 77 | [ "${UUID}" ] && create_uuid_label_symlink 'uuid' "${UUID}" 78 | [ "${LABEL}" ] && create_uuid_label_symlink 'label' "${LABEL}" 79 | fi 80 | 81 | if [ -f "/sys/block/${MDEV}/dm/name" ]; then 82 | [ -d '/dev/mapper' ] || mkdir -p '/dev/mapper' 83 | if ! [ -c '/dev/mapper/control' ]; then 84 | local misc_minor misc_name 85 | while read misc_minor misc_name; do 86 | if [ "${misc_name}" = 'device-mapper' ]; then 87 | mknod '/dev/mapper/control' c 10 "${misc_minor}" 88 | break 89 | fi 90 | done < /proc/misc 91 | fi 92 | local dmname="$(cat "/sys/block/${MDEV}/dm/name")" 93 | if [ "${dmname}" ]; then 94 | local target_symlink="/dev/mapper/${dmname}" 95 | [ -e "${target_symlink}" ] && return 96 | local temp_symlink=$(mktemp -p "${target_dir}" $$-XXXXXX) 97 | ln -snf /dev/${MDEV} "${temp_symlink}" 98 | mv -fT "${temp_symlink}" "${target_symlink}" 99 | rm -f "${temp_symlink}" 100 | echo "${target_symlink}" >"${storage_dir}/storage_symlink_mapper_${MDEV}" 101 | fi 102 | fi 103 | } 104 | 105 | drop_symlinks() { 106 | local type 107 | for type in uuid label mapper; do 108 | [ -f "${storage_dir}/storage_symlink_${type}_${MDEV}" ] || continue 109 | local target_symlink="$(cat "${storage_dir}/storage_symlink_${type}_${MDEV}" 2>/dev/null)" 110 | [ "${target_symlink}" ] || continue 111 | 112 | local target_symlink_device="$(readlink "${target_symlink}")" 113 | if [ "${target_symlink_device}" = "/dev/${MDEV}" ]; then 114 | rm "${target_symlink}" 115 | fi 116 | rm "${storage_dir}/storage_symlink_${type}_${MDEV}" 117 | done 118 | } 119 | 120 | case "${ACTION}" in 121 | 'add'|'') 122 | add_symlinks 123 | ;; 124 | 'remove') 125 | drop_symlinks 126 | ;; 127 | esac 128 | 129 | -------------------------------------------------------------------------------- /etc/bb.d/mdev/modalias: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | # Try to load a module, by name or by alias. 4 | 5 | modprobe -b "$1" 2> /dev/null && exit 0 # It worked? We're done! 6 | 7 | ResolveAlias () { 8 | local DB Type Key Pattern Name 9 | DB="/lib/modules/$(uname -r)/modules.alias" 10 | [ -f "$DB" ] || return 11 | Type=${1:0:3} # Faster to filter first 3 chars as literal 12 | grep -F "alias $Type" "$DB" | while read Key Pattern Name ; do 13 | case "$1" in 14 | $Pattern) echo "$Name" ;; 15 | esac 16 | done | sort -u 17 | } 18 | 19 | Error=1 20 | for M in $(ResolveAlias "$1") ; do 21 | logger -s -t bbinit -p daemon.info "Loading module '$M'" 22 | modprobe -b "$M" 2> /dev/null && Error=0 23 | done 24 | [ $Error -eq 0 ] && exit 0 # Claim success if at least one loaded 25 | 26 | logger -s -t bbinit -p daemon.warn "Failed to load module '$1'" 27 | exit 1 28 | 29 | -------------------------------------------------------------------------------- /etc/bb.d/mdev/usb-dev: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | # If you want to run a script when a specific USB device is inserted or 4 | # removed, you can create the script in /etc/bb.b/usb/ and name it 5 | # according to its device ID as shown in the output of the "lsusb" 6 | # command, only substitute a dot '.' for the colon ':'. For example 7 | # if lsusb identifies your device as "abcd:1234" you should create an 8 | # executable shell script named "/etc/bb.b/usb/abcd.1234" . Your script 9 | # should check the $ACTION environment variable to see if the event is 10 | # "add" (device inserted) or "remove" (device removed). There are other 11 | # possible values for $ACTION, for instance "bind" indicates a kernel 12 | # module being loaded and bound to the device. 13 | 14 | if [ -n "$DEVPATH" ] ; then 15 | d="/sys/$DEVPATH" 16 | p="$d/idProduct" 17 | v="$d/idVendor" 18 | if [ -d "$d/" ] && [ -r "$p" ] && [ -r "$v" ] ; then 19 | sh=/etc/bb.d/usb/$(cat "$v").$(cat "$p") 20 | [ -f "$sh" ] && [ -x "$sh" ] && exec "$sh" "$@" 21 | fi 22 | fi 23 | 24 | -------------------------------------------------------------------------------- /etc/bb.d/rc.local: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | case "$1" in 5 | start) 6 | echo "Hello from $0" 7 | ;; 8 | stop) 9 | echo "Goodbye from $0" 10 | ;; 11 | esac 12 | 13 | -------------------------------------------------------------------------------- /etc/bb.d/rc0: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | 5 | # Shutdown any active TCP/UDP servers before bringing down 6 | # network interfaces, else some remote clients might hang. 7 | stop_servers () { 8 | local srv_pids=$( 9 | netstat -ntulp 2> /dev/null | awk \ 10 | '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+.*/ { 11 | gsub(/\/.*$/,""); 12 | print $7 13 | }' | sort -n 14 | ) 15 | local all_pids=$( 16 | cd /proc 17 | find . -maxdepth 1 -type d -name '[0-9]*' | cut -c 3- 18 | ) 19 | local kid_pids=$( 20 | for P in $all_pids 21 | do 22 | [ -e /proc/$P/status ] || continue 23 | PP=$(awk '/^PPid:/ {print $2}' /proc/$P/status ) 24 | for NP in $srv_pids 25 | do 26 | [ $PP = $NP ] && echo $P 27 | done 28 | done 29 | ) 30 | [ -z "$kid_pids" ] && [ -z "$srv_pids" ] && return 31 | echo "Sending active TCP/UDP servers the $1 signal." 32 | kill -$1 $kid_pids $srv_pids 33 | sleep 1 34 | } 35 | 36 | 37 | # Return a list of all PIDs, sorted by time: most recently started first, oldest last 38 | get_pid_list () { 39 | cd /proc 40 | local P 41 | for P in [0-9]*; do 42 | [ -d "$P" ] || continue 43 | awk '{sub(/.*) /,""); printf("%s.%.08d\n",$20,'$P')}' $P/stat 44 | done | sort -gr | awk '{sub(/[0-9]+\.[0]+/,""); print}' 45 | cd / 46 | } 47 | 48 | 49 | stop_tasks () { 50 | local reversed='' 51 | for include_file in /etc/bb.d/task/* ; do 52 | [ -f $include_file ] && reversed="$include_file $reversed" 53 | done 54 | task_stop () { : ; } 55 | for include_file in $reversed ; do 56 | local base_name=/etc/bb.d/task/local/${include_file#*-} 57 | [ -f $base_name.pre_stop ] && . $base_name.pre_stop 58 | [ -f $base_name.mask_stop ] && include_file=$base_name.mask_stop 59 | [ -f $include_file ] && . $include_file && task_stop 60 | task_stop () { : ; } 61 | [ -f $base_name.post_stop ] && . $base_name.post_stop 62 | done 63 | } 64 | 65 | 66 | # Return 0 if there are any block devices under /dev/mapper/ 67 | have_devmaps () { 68 | local devmap 69 | for devmap in /dev/mapper/* ; do 70 | [ -b "$devmap" ] && return 0 71 | done 72 | return 1 73 | } 74 | 75 | 76 | rcz_main () { 77 | 78 | cd / 79 | chvt 1 80 | echo 'The system is going down for the count, NOW!' >&2 81 | sleep 2 82 | 83 | stop_tasks 84 | 85 | mount -t nfs | while read Dev on MtPt Etc ; do 86 | NfsSrv="${Dev%:*}" 87 | if ping -q -c 1 -W 3 ${Dev%:*} > /dev/null ; then 88 | umount "$MtPt" || umount -l "$MtPt" 89 | else 90 | umount -f "$MtPt" || umount -f -l "$MtPt" 91 | fi 92 | done 93 | 94 | stop_servers TERM 95 | stop_servers KILL 96 | local sig_spec 97 | if pgrep '^pppd$' > /dev/null ; then 98 | echo "Shutting down ppp daemons" 99 | which poff > /dev/null && poff -a 100 | for sig_spec in TERM KILL; do 101 | pgrep '^pppd$' > /dev/null && killall -${sig_spec} pppd && sleep 1 102 | done 103 | fi 104 | 105 | ( 106 | cd /sys/class/net 107 | for iface in *; do 108 | case "$iface" in 109 | lo) ;; 110 | *) 111 | case $(cat "$iface/operstate") in 112 | down) ;; 113 | *) 114 | echo "Bringing down network interface '$iface'" 115 | ifconfig "$iface" down 116 | sleep 0.25s 117 | ;; 118 | esac 119 | ;; 120 | esac 121 | done 122 | ) 123 | 124 | sleep 1s 125 | 126 | # If there are devices in /dev/mapper/ and udevd is running 127 | # don't kill it else cryptsetup might hang. 128 | local udevd=0 129 | 130 | for sig_spec in TERM KILL KILL; do 131 | echo "Sending remaining processes the $sig_spec signal" 132 | local some_pid 133 | for some_pid in $(get_pid_list) ; do 134 | [ $some_pid -eq 1 ] && continue 135 | [ $some_pid -eq $$ ] && continue 136 | if have_devmaps ; then 137 | comm="/proc/$some_pid/comm" 138 | [ -e $comm ] && read exe < $comm && [ -n "$exe" ] \ 139 | && [ $exe = 'udevd' ] && udevd=1 && continue 140 | fi 141 | [ -d /proc/$some_pid ] || continue 142 | kill -$sig_spec $some_pid 143 | done 144 | sleep 1 145 | done 146 | 147 | N=0 148 | while [ $N -lt 10 ]; do 149 | if [ -e /proc/swaps ]; then 150 | [ $(wc -l < /proc/swaps) -gt 1 ] && swapoff -a 151 | else 152 | swapoff -a # What else can we do if there is no /proc/swaps ? 153 | fi 154 | if [ -e /proc/mounts ] ; then 155 | local mounts="$(tac /proc/mounts)" 156 | echo "${mounts}" | while read dev mnt typ opt dmp pss; do 157 | case $mnt in 158 | /|/proc|/sys|/dev/pts|/dev) ;; 159 | *) 160 | case "$typ" in 161 | proc|devtmpfs|devpts|sysfs) ;; 162 | *) 163 | if umount -r $mnt; then 164 | echo "Unmounted $dev on $mnt" 165 | case "$dev" in 166 | /dev/mapper/*) 167 | MapDev=${dev##*/} 168 | if cryptsetup close "$MapDev" ; then 169 | echo "Removed mapping $dev" 170 | else 171 | echo "Failed to remove mapping $dev" 172 | fi 173 | if [ $udevd = 1 ] && ! have_devmaps ; then 174 | killall udevd 175 | udevd=0 176 | fi 177 | ;; 178 | esac 179 | else 180 | echo "Failed to unmount $dev on $mnt" 181 | sleep 2 182 | fi 183 | ;; 184 | esac 185 | ;; 186 | esac 187 | done 188 | fi 189 | sync 190 | mount -o remount,ro / && break 191 | N=$((N+1)) 192 | sleep 1 193 | case $N in 194 | 10) 195 | echo "Read-only remount of root filesystem failed after $N tries, giving up!" 196 | remount_ro_error_log='/var/log/remount-ro-error.log' 197 | touch $remount_ro_error_log || break 198 | echo "PID (Name) cmdline" > $remount_ro_error_log 199 | for P in $(fuser /); do 200 | printf "%s " $P 201 | [ -e /proc/$P/status ] && awk '/^Name:/ {printf(" (%s) ", $2)}' /proc/$P/status || printf " (???) " 202 | [ -e /proc/$P/cmdline ] && tr '\0' ' ' < /proc/$P/cmdline || printf "???" 203 | echo 204 | done >> $remount_ro_error_log 205 | echo "Devices:" >> $remount_ro_error_log 206 | mount >> $remount_ro_error_log 207 | echo "Check $remount_ro_error_log after next boot!" 208 | for N in 1 2 3 209 | do 210 | sync 211 | sync 212 | sleep 1 213 | done 214 | exec reboot -d 2 -f 215 | ;; 216 | *) echo "Read-only remount of root filesystem failed, retrying..." ;; 217 | esac 218 | done 219 | 220 | echo "Returning control to init" 221 | sleep 1s 222 | exec kill -KILL -1 223 | 224 | } 225 | 226 | rcz_main 227 | -------------------------------------------------------------------------------- /etc/bb.d/rcS: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # -*- mode: sh; -*- 3 | 4 | export PATH=/sbin:/usr/sbin:/bin:/usr/bin 5 | 6 | rcs_main () { 7 | 8 | printf 'Beginning %s [%s]\r' "$0" "$$" 1>&2 9 | printf 'Beginning %s [%s]\n' "$0" "$$" 10 | 11 | local MODULES_DIR="/lib/modules/$(uname -r)" 12 | local include_file 13 | 14 | task_start () { : ; } 15 | for include_file in /etc/bb.d/task/* ; do 16 | [ -f $include_file ] || continue 17 | local base_name=/etc/bb.d/task/local/${include_file#*-} 18 | [ -f $base_name.pre_start ] && . $base_name.pre_start 19 | [ -f $base_name.mask_start ] && include_file=$base_name.mask_start 20 | [ -f $include_file ] && . $include_file && task_start 21 | task_start () { : ; } 22 | [ -f $base_name.post_start ] && . $base_name.post_start 23 | done 24 | 25 | printf 'Leaving %s\r' "$0" 1>&2 26 | printf 'Leaving %s\n' "$0" 27 | } 28 | 29 | rcs_main 30 | 31 | -------------------------------------------------------------------------------- /etc/bb.d/task/010-sysdirs: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Mount /proc , /dev , /sys directories if they are not mounted already. 5 | task_start () { 6 | MntPtIsType () { grep -q " $(readlink -f $1) $2 " /proc/mounts; } 7 | 8 | if [ -f /proc/mounts ] && MntPtIsType /proc proc && \ 9 | [ $(stat -c %d /) -ne $(stat -c %d /proc) ] 10 | then 11 | : 12 | else 13 | /lib/bb/busybox mount -t proc proc /proc 14 | fi 15 | 16 | MntPtIsType /sys sysfs || mount -t sysfs sysfs /sys 17 | MntPtIsType /dev devtmpfs || mount -t devtmpfs devtmpfs /dev 18 | 19 | if ! MntPtIsType /dev/pts devpts; then 20 | mkdir -p /dev/pts 21 | mount -t devpts devpts /dev/pts 22 | fi 23 | 24 | [ -c /dev/null ] || ( rm -f /dev/null ; mknod -m 666 /dev/null c 1 3 ) 25 | [ -e /dev/fd ] || ln -sf /proc/self/fd /dev/fd 26 | 27 | ln -sf /proc/self/fd/0 /dev/stdin 28 | ln -sf /proc/self/fd/1 /dev/stdout 29 | ln -sf /proc/self/fd/2 /dev/stderr 30 | } 31 | 32 | -------------------------------------------------------------------------------- /etc/bb.d/task/020-rootfs: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Determine root device, ensure it is mounted read-only, fsck it, 5 | # then remount it read-write, unless /etc/fstab says otherwise. 6 | task_start () { 7 | local rootdev=$(rdev) 8 | if [ "x$rootdev" != 'x' ]; then 9 | local dev mnt typ opts ro 10 | for dev in $rootdev; do rootdev=$dev; break; done 11 | ro=0 12 | while read dev mnt typ opts; do 13 | if [ "$dev" = "$rootdev" ] && [ "$mnt" = '/' ]; then 14 | case "$opts" in 15 | ro|ro,*) ro=1 ;; 16 | rw|rw,*) ro=0 ;; 17 | esac 18 | break 19 | fi 20 | done < /proc/mounts 21 | fi 22 | 23 | forcefsck='' 24 | [ -f /forcefsck ] && forcefsck='-f' || \ 25 | for arg in $(cat /proc/cmdline); do 26 | [ "$arg" = 'forcefsck' ] && forcefsck='-f' && break 27 | done 28 | 29 | if [ "$ro" = '0' ]; then 30 | echo 'Warning! root fs is mounted read/write, skipping fsck!' 31 | sleep 5 32 | else 33 | echo 'Root fs mounted read-only [good]' 34 | local rv=0 35 | local fstype=$(blkid $rootdev | awk '{gsub(/.*TYPE="/, ""); gsub(/".*/,""); print}') 36 | type -p fsck.$fstype > /dev/null && fsck_root=fsck.$fstype || fsck_root=fsck 37 | $fsck_root -p $rootdev $forcefsck 38 | rv=$? 39 | if [ $rv -gt 1 ]; then 40 | if [ $rv -gt 3 ]; then 41 | echo 'Error: fsck encountered problems.' 42 | echo 'Entering repair mode' 43 | PS1='(Rescue) \#' 44 | export PS1 45 | login 46 | else 47 | echo "Notice: fsck returned [$rv], requires reboot." 48 | fi 49 | echo 'Rebooting system.' 50 | sleep 5 51 | exec reboot -f 52 | fi 53 | echo 'Remounting root fs read/write.' 54 | mount -w -v -n -o remount / 55 | if [ $? -ne 0 ]; then 56 | echo 'Error: remount of root fs read/write failed!' 57 | sleep 10 58 | fi 59 | fi 60 | 61 | if [ "$(readlink /etc/mtab)" != '/proc/mounts' ] ; then 62 | rm -rf /etc/mtab 63 | ln -sf /proc/mounts /etc/mtab 64 | fi 65 | } 66 | 67 | -------------------------------------------------------------------------------- /etc/bb.d/task/030-mdev: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Start mdev hotplugging, either by the old /proc/sys/kernel/hotplug 5 | # method or the newer netlink-based "mdev -d" daemon 6 | task_start () { 7 | local mdev='/lib/bb/mdev' 8 | [ -e "$mdev" ] || ln -sf busybox $mdev || mdev='/lib/bb/busybox mdev' 9 | echo 'Initializing mdev' 10 | if [ -e /proc/sys/kernel/hotplug ] ; then 11 | echo 'Enabling legacy hotplugging.' 12 | echo $mdev > /proc/sys/kernel/hotplug 13 | else 14 | echo "Starting mdev in daemon mode" 15 | $mdev -d & 16 | fi 17 | $mdev -s 18 | } 19 | 20 | -------------------------------------------------------------------------------- /etc/bb.d/task/040-modules: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Load any additional modules listed in /etc/modules 5 | task_start () { 6 | if [ -f /etc/modules ] && [ -d "$MODULES_DIR" ]; then 7 | printf 'Loading modules... ' 8 | local m= 9 | while read m; do 10 | [ "x$m" = 'x' ] && continue 11 | case $m in 12 | \#*) ;; 13 | *) 14 | modprobe $m 15 | ;; 16 | esac 17 | done < /etc/modules 18 | echo "done." 19 | fi 20 | } 21 | 22 | -------------------------------------------------------------------------------- /etc/bb.d/task/050-fstab: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # fsck and mount any filesystems listed in /etc/fstab 5 | # also setup swap files/partitions and mount /dev/shm 6 | task_start () { 7 | if [ -f /etc/fstab ]; then 8 | echo 'Mounting filesystems in /etc/fstab...' 9 | local dev mtpt fstype opts freq passno rem 10 | sed 's/\\040/\\ /g' /etc/fstab | while read dev mtpt fstype opts freq passno rem; do 11 | case $opts in 12 | *noauto*) 13 | continue 14 | ;; 15 | esac 16 | case $dev in 17 | UUID=*|LABEL=*) dev=$(findfs "$dev") ;; 18 | esac 19 | case $dev in 20 | /dev/*) 21 | if [ "$mtpt" = '/' ]; then 22 | mount -o "remount,$opts" "$mtpt" 23 | continue; 24 | fi 25 | printf '%d' $passno &> /dev/null || passno=0 26 | case $fstype in 27 | ext[2-4]|vfat|msdos) 28 | [ -d $MODULES_DIR ] && modprobe $fstype 2> /dev/null 29 | if type -p fsck.$fstype > /dev/null; then 30 | local fsck_cmd="fsck.$fstype -p $dev $forcefsck" 31 | if [ $passno -eq 0 ] || $fsck_cmd || $fsck_cmd; then 32 | mount -t $fstype -o $opts $dev $mtpt 33 | fi 34 | fi 35 | ;; 36 | esac 37 | ;; 38 | esac 39 | done 40 | mkdir -p /dev/shm 41 | mount -a 42 | swapon -a 43 | echo 'fstab done.' 44 | else 45 | echo '/etc/fstab not found, skipping.' 46 | fi 47 | } 48 | 49 | -------------------------------------------------------------------------------- /etc/bb.d/task/060-haveged: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # haveged 5 | task_start () { 6 | if type -p haveged &> /dev/null ; then 7 | echo 'Starting haveged daemon...' 8 | haveged 9 | fi 10 | } 11 | 12 | -------------------------------------------------------------------------------- /etc/bb.d/task/070-urandom: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Initialize random number generator (seed /dev/(u)random) 5 | task_start () { 6 | local statedir='/var/lib' 7 | local seedfile="$statedir/seedrng/seed.credit" 8 | local timeout=20 # Seconds to keep trying before backgrounding 9 | local elapsed=0 10 | local start=$EPOCHREALTIME 11 | # With an existing seedfile and/or haveged running, intitialization 12 | # happens almost instantly. Otherwise it might take a long time. 13 | if [ ! -e "$seedfile" ] && ! pidof haveged > /dev/null ; then 14 | printf '%s\n%s\n' \ 15 | 'NOTE: Entropy is low, RNG intitialization may be slow.' \ 16 | 'Do some "monkey typing" on your keyboard to speed it up.' 17 | fi 18 | printf 'Initializing random number generator...' 19 | mkdir -p "$statedir" 20 | while : ; do 21 | seedrng > /dev/null 22 | if [ -e "$seedfile" ] ; then 23 | elapsed=$(echo 2 k $EPOCHREALTIME $start - 1 / p | dc) 24 | printf "\nRNG Successfully seeded after %s seconds.\n" "$elapsed" 25 | break 26 | fi 27 | printf '.' 28 | sleep 1 29 | elapsed=$((elapsed+1)) 30 | if [ $elapsed -ge $timeout ] ; then 31 | printf '\nTried for %s seconds to seed RNG, backgrounding.\n' $elapsed 32 | ( 33 | while : ; do 34 | seedrng > /dev/null 35 | if [ -e "$seedfile" ] ; then 36 | local logit='logger -t seedrng -p daemon.notice' 37 | local line 38 | seedrng | while read line ; do $logit "$line" ; done 39 | $logit "Successfully seeded after $elapsed seconds." 40 | break 41 | fi 42 | sleep 1 43 | elapsed=$((elapsed+1)) 44 | done 45 | ) & 46 | break 47 | fi 48 | done 49 | local oldfile='/var/lib/random-seed' # Previous version used this 50 | [ -e "$oldfile" ] && rm -f "$oldfile" # we don't need it anymore. 51 | } 52 | 53 | 54 | task_stop () { 55 | echo "Saving random seed..." 56 | mkdir -p '/var/lib/' 57 | seedrng 58 | } 59 | 60 | -------------------------------------------------------------------------------- /etc/bb.d/task/080-syslog: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Logging 5 | task_start () { 6 | echo 'Starting syslog daemon' 7 | local SysLogFile='/var/log/messages' 8 | local SysLogMaxKB='200' 9 | local SysLogPri='6' 10 | [ -L "$SysLogFile" ] && SysLogFile=$(readlink "$SysLogFile") 11 | SysLogDir=$(dirname "$SysLogFile") 12 | [ -d "$SysLogDir" ] || mkdir -p "$SysLogDir" 13 | 14 | dmesg -n 2 15 | syslogd -l "$SysLogPri" -s "$SysLogMaxKB" -O "$SysLogFile" 16 | klogd -c 3 17 | } 18 | 19 | -------------------------------------------------------------------------------- /etc/bb.d/task/090-sysctl: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Load sysctl configuration settings. 5 | task_start () { 6 | echo 'Loading sysctl settings...' 7 | local F 8 | for F in /etc/sysctl.d/*.conf /etc/sysctl.conf ; do 9 | [ -f "$F" ] && sysctl -p "$F" 10 | done 11 | unset F 12 | } 13 | 14 | -------------------------------------------------------------------------------- /etc/bb.d/task/100-network: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | NetMod () { # preload softdeps (for realtek on kernel >= 5.3) 5 | local m= d= 6 | [ "$2" ] && m=$2 || \ 7 | for m in $(modprobe -D "$1"); do : ; done 2> /dev/null 8 | [ "$m" ] && for d in $(modinfo -F softdep "$m"); do 9 | [ "$d" = post: ] && break 10 | [ "$d" = pre: ] && continue 11 | modprobe -b "$d" 12 | done 13 | modprobe -b "$1" 14 | } 15 | 16 | # network 17 | task_start () { 18 | echo 'Configuring network interfaces...' 19 | [ -f /etc/hostname ] && hostname -F /etc/hostname 20 | ifconfig lo 127.0.0.1 up netmask 255.0.0.0 21 | [ -f /etc/mactab ] && nameif -c /etc/mactab 22 | if [ -f /etc/network/interfaces ] ; then 23 | local key val junk # Try to load missing devices before we "ifup" 24 | while read key val junk ; do 25 | [ "$key" = auto ] || continue 26 | [ -e "/sys/class/net/$val" ] && continue 27 | logger -s -t IFUP -p warning "Missing auto iface '$val', trying harder" 28 | local file line 29 | for file in $(find /sys/devices -type f -name class) ; do 30 | read line < $file && [ "${line:0:6}" = 0x0200 ] || continue 31 | file=${file%/*}/modalias; 32 | [ -f "$file" ] && read line < $file || continue 33 | NetMod "$line" 34 | done 35 | sleep 0.5 36 | [ -f /etc/mactab ] && nameif -c /etc/mactab 37 | [ -e "/sys/class/net/$val" ] && continue # Not there? Maybe it's USB... 38 | local modalias 39 | for modalias in $( find /sys/devices -path '*/usb[0-9]*/*' \ 40 | -type f -name modalias -exec cat '{}' + ) 41 | do 42 | local modfile= 43 | for modfile in $(modprobe -D "$modalias"); do 44 | : # Do nothing, we're just looking for the final module name. 45 | done 2> /dev/null 46 | [ "$modfile" ] || continue 47 | case "$modfile" in 48 | */kernel/drivers/net/usb/*) 49 | local modname=${modfile##*/} 50 | modname=${modname%%.*} 51 | NetMod "$modname" "$modfile" 52 | sleep 0.5 53 | ;; 54 | esac 55 | done 56 | [ -f /etc/mactab ] && nameif -c /etc/mactab 57 | done < /etc/network/interfaces 58 | IfUp () { SHELL=/lib/bb/sh ifup $@ ; } # Need busybox SHELL for run-parts 59 | if grep -qw dhcp /etc/network/interfaces ; then 60 | if IfUp -anm | grep -q '^udhcpc ' ; then 61 | local UDHCPC_SCRIPT=$(udhcpc --help 2>&1 | awk '/^[\t ]+-s / { 62 | sub(/^[^\/]+/,""); 63 | sub(/)$/,""); print 64 | }') 65 | if [ ! -e "$UDHCPC_SCRIPT" ] ; then 66 | local UDHCPC_SCRIPT_DIR=$(dirname "$UDHCPC_SCRIPT") 67 | if mkdir -p "$UDHCPC_SCRIPT_DIR" 2> /dev/null ; then 68 | ln -s /etc/bb.d/exec/udhcpc.sh "$UDHCPC_SCRIPT" 69 | fi 70 | fi 71 | fi 72 | fi 73 | local PROG MSG 74 | IfUp -a 2>&1 | while read PROG MSG ; do 75 | case "$PROG" in 76 | udhcpc*) logger -t "${PROG/:/}" -p daemon.notice "$MSG" ;; 77 | *) logger -s -t "${PROG/:/}" -p daemon.warn "$MSG" ;; 78 | esac 79 | done & 80 | fi 81 | unset -f NetMod IfUp 82 | } 83 | 84 | -------------------------------------------------------------------------------- /etc/bb.d/task/120-dbus: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | 5 | # At first glance, it might seem that launching dbus-daemon and elogind 6 | # should be two separate tasks, but it's not that simple. See the section 7 | # on dbus and elogind in /usr/share/doc/bbinit/task.txt for more info. 8 | 9 | # Start dbus daemon, mount cgroups and start elogind 10 | task_start () { 11 | local DBusDaemon 12 | DBusDaemon=$(type -p dbus-daemon) || return 0 13 | if type -p dbus-uuidgen &> /dev/null ; then 14 | local BBI_PERSIST_MACH_ID=1 15 | local DBusConf='/etc/bb.d/conf/dbus.conf' 16 | [ -f "$DBusConf" ] && . "$DBusConf" 17 | rm -f /run/dbus/pid /var/lib/dbus/machine-id 18 | case "$BBI_PERSIST_MACH_ID" in 19 | 0) dbus-uuidgen > /etc/machine-id ;; 20 | *) dbus-uuidgen --ensure=/etc/machine-id ;; 21 | esac 22 | fi 23 | 24 | local logind='' 25 | local libexec 26 | for libexec in 'lib' 'libexec' ; do 27 | logind="/usr/$libexec/elogind/elogind" 28 | if [ -f "$logind" ] && [ -x "$logind" ] ; then 29 | break 30 | else 31 | logind='' 32 | fi 33 | done 34 | # Causes problems if daemon links to libsystemd and systemd isn't running. 35 | # Causes problems if daemon links to libelogind and elogind isn't installed. 36 | if grep -Eq 'libsystemd|libelogind' "$DBusDaemon" && [ -z "$logind" ]; then 37 | echo 'Not starting dbus daemon; [e]logind needed but not found.' 38 | return 0 39 | fi 40 | echo 'Starting dbus daemon...' 41 | mkdir -p /run/dbus 42 | dbus-daemon --system 43 | [ "$logind" ] || return 0 44 | touch /run/utmp 45 | echo "Enabling cgroups support..." 46 | /etc/bb.d/exec/cgroups 47 | # In order for elogind's poweroff and reboot functions to work under bbinit, 48 | # the /bin/reboot and /bin/poweroff files should point to busybox. If they 49 | # already exist, but are owned by some other init system, we can bind-mount 50 | # on top of them. If they don't exist, we can create our own symlinks, but 51 | # if /bin/ is read-only, then there is nothing else we can do, and the 52 | # elogind shutdown commands will fail. 53 | local cmd 54 | local bb='/lib/bb/busybox' 55 | for cmd in /bin/reboot /bin/poweroff ; do 56 | local err="WARNING: Failed to set up $cmd (logind needs it)" 57 | if [ -e "$cmd" ] ; then 58 | diff -q "$bb" "$cmd" > /dev/null && continue 59 | if ! mount --bind "$bb" "$cmd" ; then 60 | logger -s -t bbinit -p daemon.warn "$err" 61 | fi 62 | else 63 | if ln -s "$bb" "$cmd" ; then 64 | logger -s -t bbinit -p daemon.notice "Created symlink: $cmd" 65 | else 66 | logger -s -t bbinit -p daemon.warn "$err" 67 | fi 68 | fi 69 | done 70 | echo "Starting login daemon..." 71 | "$logind" & 72 | } 73 | 74 | -------------------------------------------------------------------------------- /etc/bb.d/task/130-alsa: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Restore alsa settings 5 | task_start () { 6 | if type -p alsactl &> /dev/null ; then 7 | echo 'intializing ALSA...' 8 | mkdir -p /run/lock 9 | [ -f /var/lib/alsa/asound.state ] && alsactl restore || alsactl init 10 | fi 11 | } 12 | 13 | task_stop () { 14 | type -p alsactl &> /dev/null && \ 15 | echo 'Saving ALSA settings...' && \ 16 | alsactl store 17 | } 18 | 19 | -------------------------------------------------------------------------------- /etc/bb.d/task/140-gpm: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Start gpm console mouse daemon 5 | task_start () { 6 | if type -p gpm &> /dev/null ; then 7 | echo 'Starting gpm console mouse daemon...' 8 | gpm -m /dev/input/mice -t imps2 9 | fi 10 | } 11 | 12 | -------------------------------------------------------------------------------- /etc/bb.d/task/150-local: -------------------------------------------------------------------------------- 1 | #!/bin/false 2 | # -*- mode: sh; -*- 3 | 4 | # Launch rc.local script 5 | task_start () { 6 | local RCLOCAL=$(dirname $(readlink -f $0))/rc.local 7 | if [ -f "$RCLOCAL" -a -x "$RCLOCAL" ] ; then 8 | echo 'Launching local startup script...' 9 | "$RCLOCAL" start 10 | fi 11 | } 12 | 13 | 14 | task_stop () { 15 | local RCLOCAL=$(dirname $(readlink -f $0))/rc.local 16 | if [ -f "$RCLOCAL" -a -x "$RCLOCAL" ] ; then 17 | echo 'Launching local shutdown script...' 18 | "$RCLOCAL" stop 19 | fi 20 | } 21 | 22 | -------------------------------------------------------------------------------- /etc/kernel.d/post-install/99-bbinit: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | # Kernel post-install hook for bbinit. 4 | 5 | PKGNAME="$1" 6 | VERSION="$2" 7 | 8 | [ -x /usr/share/bbinit/mkramfs ] || exit 0 9 | 10 | /usr/share/bbinit/mkramfs "$VERSION" "void-$VERSION.bbi" 11 | 12 | # To make bootloader configuration easier, we want to maintain 13 | # the non-versioned symlinks "vmlinuz" and "void.bbi" but 14 | # we want these to always point to the latest kernel version, 15 | # which might not be the one we are installing now. So we must 16 | # parse the version numbers from all kernels in /boot to determine 17 | # which one is the latest. 18 | 19 | cd /boot || exit 1 20 | 21 | Parse () { 22 | V=${1/vmlinuz-/} 23 | Bld=${V/*_/} 24 | V=${V/_*/} 25 | Maj=${V%%.*} 26 | V=${V#*.} 27 | Min=${V%%.*} 28 | Mic=${V#*.} 29 | } 30 | 31 | 32 | MajHi=0 33 | for K in vmlinuz-[0-9]*.[0-9]*.[0-9]*_[0-9]* ; do 34 | Parse "$K" 35 | printf '%d' "$Maj" &> /dev/null || continue 36 | [ "$Maj" -gt "$MajHi" ] && MajHi=$Maj 37 | done 38 | 39 | MinHi=0 40 | for K in vmlinuz-$MajHi.[0-9]*.[0-9]*_[0-9]* ; do 41 | Parse "$K" 42 | printf '%d' "$Min" &> /dev/null || continue 43 | [ "$Min" -gt "$MinHi" ] && MinHi=$Min 44 | done 45 | 46 | MicHi=0 47 | for K in vmlinuz-$MajHi.$MinHi.[0-9]*_[0-9]* ; do 48 | Parse "$K" 49 | printf '%d' "$Mic" &> /dev/null || continue 50 | [ "$Mic" -gt "$MicHi" ] && MicHi=$Mic 51 | done 52 | 53 | BldHi=0 54 | for K in vmlinuz-$MajHi.$MinHi.${MicHi}_[0-9]* ; do 55 | Parse "$K" 56 | printf '%d' "$Bld" &> /dev/null || continue 57 | [ "$Bld" -gt "$BldHi" ] && BldHi=$Bld 58 | done 59 | 60 | LATEST=$MajHi.$MinHi.${MicHi}_$BldHi 61 | 62 | if [ "$LATEST" = "$VERSION" ] ; then 63 | echo 'Updating symlinks...' 64 | ln -sfv vmlinuz-${VERSION} /boot/vmlinuz 65 | ln -sfv "void-$VERSION.bbi" /boot/void.bbi 66 | fi 67 | 68 | -------------------------------------------------------------------------------- /etc/kernel.d/post-remove/21-bbinit: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | 3 | # Kernel post-remove hook for bbinit. 4 | 5 | PKGNAME="$1" 6 | VERSION="$2" 7 | 8 | kernel=$(readlink -f /boot/vmlinuz-$VERSION) 9 | ramfs=$(readlink -f /boot/void-$VERSION.bbi) 10 | 11 | for link in $(find /boot/ -type l ) ; do 12 | deref=$(readlink -f "$link") 13 | case "$link" in 14 | /boot/vmlinuz) 15 | [ "$deref" = "$kernel" ] || continue 16 | [ -e "$kernel" ] || rm -f "$link" 17 | ;; 18 | /boot/void*.bbi) 19 | [ "$deref" = "$ramfs" ] && rm -f "$link" 20 | ;; 21 | esac 22 | done 23 | 24 | rm -f "$ramfs" 25 | 26 | -------------------------------------------------------------------------------- /install/chk-busybox.sh: -------------------------------------------------------------------------------- 1 | 2 | BBCK_SCRIPTS_ROOT='.' ./$UsrShareBbInit/utils/bbck 3 | if [ $? -ne 0 ] ; then 4 | echo 5 | echo "Compatibility test for busybox failed." 6 | M="You could try replacing it with this one:" 7 | case $(uname -m) in 8 | x86_64|x86-64) F='busybox-x86_64';; 9 | i?86) F='busybox-i686';; 10 | *) 11 | F= 12 | M="See if you can find a replacement here:" 13 | ;; 14 | esac 15 | U="https://busybox.net/downloads/binaries/1.26.2-defconfig-multiarch/$F" 16 | echo "$M" 17 | echo " $U" 18 | exit 1 19 | fi 20 | -------------------------------------------------------------------------------- /install/chk-fstab.sh: -------------------------------------------------------------------------------- 1 | #!/lib/bb/sh 2 | # Check to see if /tmp /run and /dev/shm are mentioned in /etc/fstab. 3 | # If not, explain to the user that they probably should be. 4 | 5 | TmpMnts='' 6 | 7 | HaveTmpInFsTab=0 8 | HaveRunInFsTab=0 9 | HaveShmInFsTab=0 10 | 11 | if [ -f $RootDir/etc/fstab ] ; then 12 | FsTab=$RootDir/etc/fstab 13 | else 14 | echo "*** Warning: $RootDir/etc/fstab file not found." 15 | FsTab='/dev/null' 16 | fi 17 | 18 | while read Dev MtPt Typ Opts Dump Pass ; do 19 | case "$Dev" in 20 | \#*) continue 21 | esac 22 | MtPt=$(echo "$MtPt" | sed -e 's#/\+#/#g' -e 's#/$##') # No // or final / 23 | case "$MtPt" in 24 | /tmp) HaveTmpInFsTab=1 ;; 25 | /run) HaveRunInFsTab=1 ;; 26 | /dev/shm) HaveShmInFsTab=1 ;; 27 | esac 28 | done < "$FsTab" 29 | 30 | if [ $HaveTmpInFsTab -eq 0 ] || \ 31 | [ $HaveRunInFsTab -eq 0 ] || \ 32 | [ $HaveShmInFsTab -eq 0 ] ; then 33 | cat << EOF 34 | *** Important! *** 35 | bbinit does not automatically mount /tmp or /run or /dev/shm 36 | unless they are specified in $RootDir/etc/fstab. 37 | 38 | If you need these directories to be mounted (Probably you do) 39 | You should add entries similar to these in your /etc/fstab: 40 | 41 | tmp /tmp tmpfs nosuid,nodev 0 0 42 | shm /dev/shm tmpfs nosuid,nodev 0 0 43 | run /run tmpfs nosuid,nodev,mode=0755 0 0 44 | 45 | EOF 46 | fi 47 | -------------------------------------------------------------------------------- /install/finish.sh: -------------------------------------------------------------------------------- 1 | [ "$1" = '-n' ] || printf "\n\n%s\n\n" 'bbinit successfully installed!' 2 | 3 | Ramfs="$RootDir/boot/test.bbi" 4 | 5 | if ! mountpoint -q '/sys' ; then 6 | echo "/sys is not mounted." 7 | echo "skipping creation of $Ramfs" 8 | exit 9 | fi 10 | 11 | if ! [ -d /lib/modules/ ] ; then 12 | echo "/lib/modules/ directory not found." 13 | echo "skipping creation of $Ramfs" 14 | exit 15 | fi 16 | 17 | if [ "$Ask" = '-i' ] ; then 18 | printf "Shall I create an initramfs ($Ramfs) now? [Y/N]: " 19 | while read YN ; do 20 | case "$YN" in 21 | Y|y) YN='Y' ; break ;; 22 | N|n) YN='N' ; break ;; 23 | *) 24 | printf 'Please press "Y" for "yes" or "N" for "no"\n' 25 | printf "Shall I create an initramfs ($Ramfs) now? [Y/N]: " 26 | ;; 27 | esac 28 | done 29 | else 30 | YN='Y' 31 | fi 32 | 33 | if [ "$YN" = 'N' ] ; then 34 | echo 'Skipped creation of initramfs' 35 | echo 'You can create one later by running:' 36 | echo $UsrShareBbInit/mkramfs 37 | exit 38 | fi 39 | 40 | if [ "$1" = '-n' ] ; then 41 | echo 42 | Ramfs=$(mktemp -t "__DryRun__ramfs.XXXXXX" ) 43 | echo ./$UsrShareBbInit/mkramfs $(uname -r) "$Ramfs" 44 | ./$UsrShareBbInit/mkramfs $(uname -r) "$Ramfs" || exit 1 45 | rm -f "$Ramfs" 46 | echo 47 | # exit 48 | else 49 | mkdir -p $(dirname "$Ramfs") 50 | ./$UsrShareBbInit/mkramfs $(uname -r) "$Ramfs" || exit 1 51 | fi 52 | 53 | printf "\n%s %s\n\n%s\n%s\n%s\n\n" \ 54 | 'I have created an initramfs image named' \ 55 | "$Ramfs" \ 56 | 'To boot the currently running system with bbinit,' \ 57 | 'ensure that you have a bootloader entry matching' \ 58 | 'these parameters:' 59 | 60 | for Arg in $(cat /proc/cmdline); do 61 | case "$Arg" in 62 | rw) printf ' %s\n' ' ro' ;; 63 | initrd=*) 64 | eval "$Arg" 65 | printf ' initrd=%s/%s\n' "${initrd%/*}" "${Ramfs##*/}" 66 | ;; 67 | init=*) ;; 68 | *) printf ' %s\n' "$Arg" 69 | esac 70 | done 71 | echo ' init=/etc/bb.d/init' 72 | echo 73 | echo '(At least that is my best guess.)' 74 | echo 'Please use your own good judgement!' 75 | echo 76 | 77 | -------------------------------------------------------------------------------- /install/help.sh: -------------------------------------------------------------------------------- 1 | [ $# -eq 1 ] || [ $# -eq 2 ] || Die "Try '${0#*/} -h'" 2 | 3 | OP= 4 | Ask= 5 | 6 | help () { 7 | cat << EOF 8 | 9 | Usage: ${0#*/}