{"id":13513497,"url":"https://github.com/mehdichaouch/pi-boot-script","last_synced_at":"2025-10-10T23:23:39.436Z","repository":{"id":142395501,"uuid":"361292874","full_name":"mehdichaouch/pi-boot-script","owner":"mehdichaouch","description":"Fork of Jim Danner's excellent pi-boot-script found on GitLab.","archived":false,"fork":false,"pushed_at":"2021-04-25T22:10:04.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T00:14:20.602Z","etag":null,"topics":["boot","kodi","minecraft-server","nabaztag","octoprint","raspberry","raspberry-pi","raspberrypi"],"latest_commit_sha":null,"homepage":"https://gitlab.com/JimDanner/pi-boot-script","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehdichaouch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-04-25T00:09:17.000Z","updated_at":"2022-02-20T23:28:31.000Z","dependencies_parsed_at":"2024-01-19T02:59:12.887Z","dependency_job_id":"f84c926a-4d02-4947-ac75-061399773b76","html_url":"https://github.com/mehdichaouch/pi-boot-script","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdichaouch%2Fpi-boot-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdichaouch%2Fpi-boot-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdichaouch%2Fpi-boot-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdichaouch%2Fpi-boot-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehdichaouch","download_url":"https://codeload.github.com/mehdichaouch/pi-boot-script/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252584585,"owners_count":21771986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boot","kodi","minecraft-server","nabaztag","octoprint","raspberry","raspberry-pi","raspberrypi"],"created_at":"2024-08-01T05:00:29.169Z","updated_at":"2025-10-10T23:23:34.406Z","avatar_url":"https://github.com/mehdichaouch.png","language":"Shell","funding_links":[],"categories":["Shell","Outils"],"sub_categories":[],"readme":"# pi-boot-script\n\n#### Run your own startup scripts on Raspbian, without ever having touched the Linux partition.\n\nThis is a 100% script-based way to run commands at boot. It only uses the FAT32 */boot* partition on the SD card or the .img file. You don't need to change anything about the ext4 (Linux) partition.\n\nThis is useful if:\n\n* you want to do unattended configuration at the first boot of the new SD card. For example, to configure networking, hostname, localisation and SSH; to create and resize partitions; and to install packages\n* you broke something in the operating system, and just need to remove that *one* file to get it running again\n* you write a lot of SD cards and don't want to spend time configuring each one\n* you prefer to use the pristine Linux partition, rather than a modified version from someone you don't know\n* you prefer a readable and editable shell script over a compiled program.\n\nDoing it only with the */boot* partition is attractive because Macs and PCs don't easily write to the Linux partition. Who wants to install yet another program on their computer?\n\n## Usage\nEach of these can be done on an SD card with Raspbian or on the downloaded *.img* disk image, which you can then flash to any number of SD cards. Most computers auto-mount the */boot* partition when you insert the SD card or double-click the *.img* file.\n\nFrom very limited to an elaborate configuration:\n### 1. Basic: just run a few shell commands\nThis requires the *unattended* file and a change to the file *cmdline.txt* on the boot partition.\n\n1. Download the file [unattended](./unattended) from this project\n2. Open the file for editing. Look at section 2: remove what is there, and put your commands there. \\*\n3. Save the file and put it on the boot partition. Now open *cmdline.txt*, which is already on that partition \\*\\*\n4. Remove the item with `init=` (if it is there) and put the following at the end of the line:\n```\ninit=/bin/bash -c \"mount -t proc proc /proc; mount -t sysfs sys /sys; mount /boot; source /boot/unattended\"\n```\n5. Save the file, eject the SD card or .img file, and you're done.\n\n***Example***: at section 2 of *unattended*, you could put the command\n\n```bash\nraspi-config nonint do_hostname MyLittlePi\n```\nto change the hostname of the Pi.\n\n\\* when your commands run, the PATH is `/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.`; the working directory is `/`; the entire Linux partition is available; systemd isn't up yet so there are no services, the network is unavailable, and the system thinks it's January 1st, 1970.\n\n\\*\\* the [cmdline.txt](./cmdline.txt) in this project is from Raspbian Buster Lite 2020-02-13. If you happen to have that version, you can drop my cmdline.txt in.\n\n### 2. Medium: copy files over to the Linux partition\nTo do this, you can leave the *unattended* file unchanged; it was written for this task.\n\n1. Put your files in a directory *payload/* in a subdirectory equivalent to where they will be on the Pi:\n    * a file *payload/etc/hosts* will become */etc/hosts* on the Pi (yes, this overwrites it if it is already there)\n    * *payload/home/pi/.bashrc* will become */home/pi/.bashrc* in the user profile\n2. Put the *payload/* folder in the boot partition\n3. Also put *unattended* there\n4. Open *cmdline.txt* on the boot partition, remove the item with `init=` (if it is there) and put the following at the end of the line:\n```\ninit=/bin/bash -c \"mount -t proc proc /proc; mount -t sysfs sys /sys; mount /boot; source /boot/unattended\"\n```\n5. Save the file, eject the SD card or .img file, and you're done.\n\n### 3. Full: run configuration \u0026 installation scripts\n\nFor elaborate configuration it makes sense to run a script during a 'normal' boot. In that case, the *unattended* script only does the preparations to make it possible. This project has two scripts for normal-boot execution:\n\n* *payload/usr/local/bin/one-time-script.sh* for configuration\n* *payload/usr/local/bin/packages-script.sh* for installation of packages, using apt-get.\n\nThe way to proceed, after downloading the project, is:\n\n1. Rewrite the scripts to your liking, or replace them with your own (or, if you like [what they do](#what-the-scripts-do), configure them in *one-time-script.conf*)\n2. Put any other files that you want to copy to the root filesystem, in the corresponding place in *payload/*, e.g. if you want */var/opt/myfile* on the Pi, you create *payload/var/opt/myfile*. This will overwrite the file if it was already there.\n3. Copy files over to the boot partition:\n    * *unattended*\n    * *one-time-script.conf* (if you made any changes to it)\n    * the *payload* folder with the scripts and all the other things you want to put on the Pi\n4. Open *cmdline.txt* on the boot partition, remove the item with `init=` (if it is there) and put the following at the end of the line:\n```\ninit=/bin/bash -c \"mount -t proc proc /proc; mount -t sysfs sys /sys; mount /boot; source /boot/unattended\"\n```\n5. Eject the SD card or .img file \\*\\*\\*\n\nYou now have an SD card that will self-configure when put into a Pi, or you have an .img file that can be flashed to an unlimited number of SD cards which will all self-configure when put in a Pi.\n\nIf you're using the .img file, every time you have flashed an SD card with it you can open */boot/one-time-script.conf* on the SD card, to do some configuration for that particular card.\n\n\\*\\*\\* If you mounted the card or image from a Mac, you might like to remove some trash first: in Terminal,\n\n```bash\nfind /Volumes/boot/payload/ -name '._*' -delete\nfind /Volumes/boot/payload/ -name '.DS_Store' -delete\n```\n\nI'm not sure what kind of trash Windows puts in.\n\n#### What the scripts do\nThe scripts write log messages to */boot/configuration.log*.\n\nThe script ***one-time-script.sh*** runs during the reboot at the end of the *unattended* script. It reads optional configuration parameters from */boot/one-time-script.conf* and does the following:\n\n* create and format an additional FAT32 partition, configuring it to be owned by the user *pi* for writing application logs etc. (This part is disabled for Raspbian Stretch (9) and earlier because it didn't work there.)\n* make the Linux (root) partition take up the remaining space on the card\n* set file permissions for hidden files in /home/pi (if any were moved there) as non-executable, and for SSH public keys as private\n* set the timezone\n* set the hostname, based on the hardware generation and CPU serial number: a Pi 3 with serial 2c45df gets hostname *pi3-2c45df*. Or if new\\_hostname\\_tag was set to *basement*, the hostname becomes *pi3-basement-2c45df*\n* turn SSH on\n* set the WIFi country\n* solve a locale-mixing problem for SSH logins (warnings like `locale: Cannot set LC_CTYPE to default locale: No such file or directory` when you open a manpage or install a package)\n* set the default way of booting (console or desktop, auto-login or prompting)\n* change the locale\n* write some data about the card and the operating system to a file on the boot partition\n* disable itself for future boots, enable the package installation script, reboot\n\nThen ***packages-script.sh*** does this:\n\n* update the package lists\n* install a bunch of packages specified in */boot/one-time-script.conf*\n* if given the URL, install a recent version of Node.js\n* disable itself from running again\n* reboot.\n\n## Warnings and recovery\nYou probably wouldn't do this sort of thing to an SD card that holds all your most important files, or that is urgently needed in a production situation. Remember that these scripts are all-powerful: they run as the administrator, so `rm -rf /` will *really* erase everything. To state the obvious, ***I don't accept any responsibility for what you do to your system using this***. Also, it's advisable to test it before using it when it matters.\n\nIf you have overwritten *cmdline.txt* on the boot partition with another version and the Pi doesn't boot from that card, copy the original cmdline.txt from the *.img* file. Or if you don't have that, correct the partition UUID in cmdline.txt:\n\n* find the disk's UUID for partitions (distinct from 'disk UUID' and 'filesystem UUID'), a 32-bit integer saved in little-endian order at offset 0x1b8 from the start of the SD card or .img, with a command like\n\n```\nsudo dd if=/dev/disk2 bs=4 skip=110 count=1 | hexdump -e '1/4 \"%02x\"'\n```\nwhich emits the integer in hexadecimal notation, like `402e4a57` (example value, for 2017-04-10-raspbian-jessie).\n\n* append `-02` for the root partition, and put the result in *cmdline.txt* in the form `root=PARTUUID=402e4a57-02`\n\n## References\nI first described this at [StackExchange](https://raspberrypi.stackexchange.com/a/105534/94485) and the [Raspberry Pi Forums](https://www.raspberrypi.org/forums/viewtopic.php?p=1567588#p1567588). Some inspiration has come from Raspbian's built-in [partition resizing script](https://github.com/RPi-Distro/raspi-config/blob/master/usr/lib/raspi-config/init_resize.sh), in particular the mounting commands that make the script run.\n\n## Thanks to \u0026 Inspired by\nThanks to [Jim Danner's](https://gitlab.com/JimDanner/pi-boot-script) original repository.\n\nInspired from [mizraith/pi-boot-script](https://github.com/mizraith/pi-boot-script).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdichaouch%2Fpi-boot-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehdichaouch%2Fpi-boot-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdichaouch%2Fpi-boot-script/lists"}