├── .gitignore ├── LICENSE-GPLv2.md ├── README.md ├── delivery ├── README.md ├── install.sh └── update.sh ├── install.sh ├── raspbian └── build_raspbian_sd_card.sh └── wheezy └── build_rpi_wheezy_sd_card.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | delivery/* 3 | !delivery/README.md 4 | !delivery/install.sh 5 | !delivery/update.sh 6 | rpi/*/* 7 | rpi/* 8 | rpi 9 | log/*.log 10 | *.log 11 | tmp/**/* 12 | tmp/* 13 | log/* 14 | log 15 | Gemfile.lock 16 | doc/api 17 | doc/app 18 | *.swp 19 | *.swo 20 | *~ 21 | .DS_Store 22 | -------------------------------------------------------------------------------- /LICENSE-GPLv2.md: -------------------------------------------------------------------------------- 1 | The GNU General Public License, Version 2, June 1991 2 | ==================================================== 3 | 4 | > Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | > 59 Temple Place, Suite 330 6 | > Boston, MA 02111-1307 USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this license 9 | document, but changing it is not allowed. 10 | 11 | 12 | Preamble 13 | -------- 14 | 15 | The licenses for most software are designed to take away your freedom to share 16 | and change it. By contrast, the GNU General Public License is intended to 17 | guarantee your freedom to share and change free software--to make sure the 18 | software is free for all its users. This General Public License applies to most 19 | of the Free Software Foundation's software and to any other program whose 20 | authors commit to using it. (Some other Free Software Foundation software is 21 | covered by the GNU Library General Public License instead.) You can apply it to 22 | your programs, too. 23 | 24 | When we speak of free software, we are referring to freedom, not price. Our 25 | General Public Licenses are designed to make sure that you have the freedom to 26 | distribute copies of free software (and charge for this service if you wish), 27 | that you receive source code or can get it if you want it, that you can change 28 | the software or use pieces of it in new free programs; and that you know you can 29 | do these things. 30 | 31 | To protect your rights, we need to make restrictions that forbid anyone to deny 32 | you these rights or to ask you to surrender the rights. These restrictions 33 | translate to certain responsibilities for you if you distribute copies of the 34 | software, or if you modify it. 35 | 36 | For example, if you distribute copies of such a program, whether gratis or for a 37 | fee, you must give the recipients all the rights that you have. You must make 38 | sure that they, too, receive or can get the source code. And you must show them 39 | these terms so they know their rights. 40 | 41 | We protect your rights with two steps: (1) copyright the software, and (2) offer 42 | you this license which gives you legal permission to copy, distribute and/or 43 | modify the software. 44 | 45 | Also, for each author's protection and ours, we want to make certain that 46 | everyone understands that there is no warranty for this free software. If the 47 | software is modified by someone else and passed on, we want its recipients to 48 | know that what they have is not the original, so that any problems introduced by 49 | others will not reflect on the original authors' reputations. 50 | 51 | Finally, any free program is threatened constantly by software patents. We wish 52 | to avoid the danger that redistributors of a free program will individually 53 | obtain patent licenses, in effect making the program proprietary. To prevent 54 | this, we have made it clear that any patent must be licensed for everyone's free 55 | use or not licensed at all. 56 | 57 | The precise terms and conditions for copying, distribution and modification 58 | follow. 59 | 60 | 61 | Terms And Conditions For Copying, Distribution And Modification 62 | --------------------------------------------------------------- 63 | 0. This License applies to any program or other work which contains a notice 64 | placed by the copyright holder saying it may be distributed under the terms 65 | of this General Public License. The "Program", below, refers to any such 66 | program or work, and a "work based on the Program" means either the Program 67 | or any derivative work under copyright law: that is to say, a work 68 | containing the Program or a portion of it, either verbatim or with 69 | modifications and/or translated into another language. (Hereinafter, 70 | translation is included without limitation in the term "modification".) 71 | Each licensee is addressed as "you". 72 | 73 | Activities other than copying, distribution and modification are not 74 | covered by this License; they are outside its scope. The act of running the 75 | Program is not restricted, and the output from the Program is covered only 76 | if its contents constitute a work based on the Program (independent of 77 | having been made by running the Program). Whether that is true depends on 78 | what the Program does. 79 | 80 | 1. You may copy and distribute verbatim copies of the Program's source code as 81 | you receive it, in any medium, provided that you conspicuously and 82 | appropriately publish on each copy an appropriate copyright notice and 83 | disclaimer of warranty; keep intact all the notices that refer to this 84 | License and to the absence of any warranty; and give any other recipients 85 | of the Program a copy of this License along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and you 88 | 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 of it, 91 | thus forming a work based on the Program, and copy and distribute such 92 | modifications or work under the terms of Section 1 above, provided that you 93 | also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices stating 96 | 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 whole 99 | or in part contains or is derived from the Program or any part thereof, 100 | to be licensed as a whole at no charge to all third parties under the 101 | terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively when run, 104 | you must cause it, when started running for such interactive use in the 105 | most ordinary way, to print or display an announcement including an 106 | appropriate copyright notice and a notice that there is no warranty (or 107 | else, saying that you provide a warranty) and that users may 108 | redistribute the program under these conditions, and telling the user 109 | how to view a copy of this License. (Exception: if the Program itself 110 | is interactive but does not normally print such an announcement, your 111 | work based on the Program is not required to print an announcement.) 112 | 113 | These requirements apply to the modified work as a whole. If identifiable 114 | sections of that work are not derived from the Program, and can be 115 | reasonably considered independent and separate works in themselves, then 116 | this License, and its terms, do not apply to those sections when you 117 | distribute them as separate works. But when you distribute the same 118 | sections as part of a whole which is a work based on the Program, the 119 | distribution of the whole must be on the terms of this License, whose 120 | permissions for other licensees extend to the entire whole, and thus to 121 | each and every part regardless of who wrote it. 122 | 123 | Thus, it is not the intent of this section to claim rights or contest your 124 | rights to work written entirely by you; rather, the intent is to exercise 125 | the right to control the distribution of derivative or collective works 126 | based on the Program. 127 | 128 | In addition, mere aggregation of another work not based on the Program with 129 | the Program (or with a work based on the Program) on a volume of a storage 130 | or distribution medium does not bring the other work under the scope of 131 | this License. 132 | 133 | 3. You may copy and distribute the Program (or a work based on it, under 134 | Section 2) in object code or executable form under the terms of Sections 1 135 | and 2 above provided that you also do one of the following: 136 | 137 | a) Accompany it with the complete corresponding machine-readable source 138 | code, which must be distributed under the terms of Sections 1 and 2 139 | above on a medium customarily used for software interchange; or, 140 | 141 | b) Accompany it with a written offer, valid for at least three years, to 142 | give any third party, for a charge no more than your cost of physically 143 | performing source distribution, a complete machine-readable copy of the 144 | corresponding source code, to be distributed under the terms of 145 | Sections 1 and 2 above on a medium customarily used for software 146 | interchange; or, 147 | 148 | c) Accompany it with the information you received as to the offer to 149 | distribute corresponding source code. (This alternative is allowed only 150 | for noncommercial distribution and only if you received the program in 151 | object code or executable form with such an offer, in accord with 152 | Subsection b above.) 153 | 154 | The source code for a work means the preferred form of the work for making 155 | modifications to it. For an executable work, complete source code means all 156 | the source code for all modules it contains, plus any associated interface 157 | definition files, plus the scripts used to control compilation and 158 | installation of the executable. However, as a special exception, the source 159 | code distributed need not include anything that is normally distributed (in 160 | either source or binary form) with the major components (compiler, kernel, 161 | and so on) of the operating system on which the executable runs, unless 162 | that component itself accompanies the executable. 163 | 164 | If distribution of executable or object code is made by offering access to 165 | copy from a designated place, then offering equivalent access to copy the 166 | source code from the same place counts as distribution of the source code, 167 | even though third parties are not compelled to copy the source along with 168 | the object code. 169 | 170 | 4. You may not copy, modify, sublicense, or distribute the Program except as 171 | expressly provided under this License. Any attempt otherwise to copy, 172 | modify, sublicense or distribute the Program is void, and will 173 | automatically terminate your rights under this License. However, parties 174 | who have received copies, or rights, from you under this License will not 175 | have their licenses terminated so long as such parties remain in full 176 | compliance. 177 | 178 | 5. You are not required to accept this License, since you have not signed it. 179 | However, nothing else grants you permission to modify or distribute the 180 | Program or its derivative works. These actions are prohibited by law if you 181 | do not accept this License. Therefore, by modifying or distributing the 182 | Program (or any work based on the Program), you indicate your acceptance of 183 | this License to do so, and all its terms and conditions for copying, 184 | distributing or modifying the Program or works based on it. 185 | 186 | 6. Each time you redistribute the Program (or any work based on the Program), 187 | the recipient automatically receives a license from the original licensor 188 | to copy, distribute or modify the Program subject to these terms and 189 | conditions. You may not impose any further restrictions on the recipients' 190 | exercise of the rights granted herein. You are not responsible for 191 | enforcing compliance by third parties to this License. 192 | 193 | 7. If, as a consequence of a court judgment or allegation of patent 194 | infringement or for any other reason (not limited to patent issues), 195 | conditions are imposed on you (whether by court order, agreement or 196 | otherwise) that contradict the conditions of this License, they do not 197 | excuse you from the conditions of this License. If you cannot distribute so 198 | as to satisfy simultaneously your obligations under this License and any 199 | other pertinent obligations, then as a consequence you may not distribute 200 | the Program at all. For example, if a patent license would not permit 201 | royalty-free redistribution of the Program by all those who receive copies 202 | directly or indirectly through you, then the only way you could satisfy 203 | both it and this License would be to refrain entirely from distribution of 204 | the Program. 205 | 206 | If any portion of this section is held invalid or unenforceable under any 207 | particular circumstance, the balance of the section is intended to apply 208 | and the section as a whole is intended to apply in other circumstances. 209 | 210 | It is not the purpose of this section to induce you to infringe any patents 211 | or other property right claims or to contest validity of any such claims; 212 | this section has the sole purpose of protecting the integrity of the free 213 | software distribution system, which is implemented by public license 214 | practices. Many people have made generous contributions to the wide range 215 | of software distributed through that system in reliance on consistent 216 | application of that system; it is up to the author/donor to decide if he or 217 | she is willing to distribute software through any other system and a 218 | licensee cannot impose that choice. 219 | 220 | This section is intended to make thoroughly clear what is believed to be a 221 | consequence of the rest of this License. 222 | 223 | 8. If the distribution and/or use of the Program is restricted in certain 224 | countries either by patents or by copyrighted interfaces, the original 225 | copyright holder who places the Program under this License may add an 226 | explicit geographical distribution limitation excluding those countries, so 227 | that distribution is permitted only in or among countries not thus excluded. 228 | In such case, this License incorporates the limitation as if written in 229 | the body of this License. 230 | 231 | 9. The Free Software Foundation may publish revised and/or new versions of the 232 | General Public License from time to time. Such new versions will be similar 233 | in spirit to the present version, but may differ in detail to address new 234 | problems or concerns. 235 | 236 | Each version is given a distinguishing version number. If the Program 237 | specifies a version number of this License which applies to it and "any 238 | later version", you have the option of following the terms and conditions 239 | either of that version or of any later version published by the Free 240 | Software Foundation. If the Program does not specify a version number of 241 | this License, you may choose any version ever published by the Free 242 | Software Foundation. 243 | 244 | 10. If you wish to incorporate parts of the Program into other free programs 245 | whose distribution conditions are different, write to the author to ask for 246 | permission. For software which is copyrighted by the Free Software 247 | Foundation, write to the Free Software Foundation; we sometimes make 248 | exceptions for this. Our decision will be guided by the two goals of 249 | preserving the free status of all derivatives of our free software and of 250 | promoting the sharing and reuse of software generally. 251 | 252 | 253 | No Warranty 254 | ----------- 255 | 256 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR 257 | THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 258 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 259 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 260 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 261 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO 262 | THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM 263 | PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 264 | CORRECTION. 265 | 266 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL 267 | ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE 268 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 269 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 270 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 271 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 272 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 273 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 274 | SUCH DAMAGES. 275 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BuildRaspbianImage 2 | ========================================================= 3 | 4 | Build (and cross-compile) your own image for Raspberry Pi 5 | 6 | Set of bash scripts for your Debian or Ubuntu Linux to create your own .img file for Raspberry Pi. 7 | Have your own image with YOUR content in minutes! 8 | 9 | *Initial script was taken from the [Klaus Maria Pfeiffer blog] (http://blog.kmp.or.at/2012/05/build-your-own-raspberry-pi-image/).* 10 | 11 | About initial code 12 | --------------------------------------------------------- 13 | 14 | Original script was created to burn Debian Wheezy, my target is Raspbian, which is better for Raspberry Pi. You can read more about Raspbian (and its difference from stock Debian) at project page: http://raspbian.org 15 | 16 | Milestones of this project 17 | --------------------------------------------------------- 18 | - [x] Add script to create minimal Raspbian image 19 | - [ ] Add image mount / unmount script with cross-compilation environment for mounted system 20 | - [ ] Be able to deploy images (add individual hostname and root password, OpenVPN client settings) 21 | 22 | Instructions 23 | --------------------------------------------------------- 24 | 25 | It is possible to prepare environment on almost every Linux, where chroot, QEMU and debootstrap exists. 26 | I strictly recommend to install apt-cacher-ng (apt-get install apt-cacher-ng), that caches all downloaded deb packages and lets you to use deb_local_mirror, what's extreamely useful for further experiments, system won't download packages from internet anymore! [Read more about apt-cacher-ng] (https://www.unix-ag.uni-kl.de/~bloch/acng/html/config-servquick.html#config-client) 27 | 28 | Install minimal set of packages: 29 | ./install.sh 30 | 31 | Run build_raspbian_sd_card.sh script, do burn your SD card 32 | 33 | ./build_raspbian_sd_card.sh /dev/sdX 34 | 35 | OR to create IMG file (you'll find it under /tmp/rpi folder) 36 | 37 | ./build_raspbian_sd_card.sh 38 | -------------------------------------------------------------------------------- /delivery/README.md: -------------------------------------------------------------------------------- 1 | Delivery contents 2 | ========================================================= 3 | 4 | Put all your delivery files, scripts, SQL's to this folder. It will be mounted to the Raspbian environment and you'll access them. 5 | 6 | -------------------------------------------------------------------------------- /delivery/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | machine=`uname -m` 4 | if [ "${machine}" != "armv7l" ]; then 5 | echo "This script will be executed at mounted raspbian enviroment (armv7l). Current environment is ${machine}." 6 | exit 1 7 | fi 8 | 9 | echo "Please check environment variables etc, this script can be executed ONLY within RPI environment!" 10 | echo "When tasks done, type \"exit\" to return" 11 | echo "" 12 | 13 | bash 14 | 15 | -------------------------------------------------------------------------------- /delivery/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "`uname -m`" <> "armv7l" ]; then 4 | echo "This script will be executed at mounted raspbian enviroment" 5 | exit 1 6 | fi 7 | 8 | echo "Please check environment variables etc, this script can be executed ONLY within RPI environment!" 9 | echo "When tasks done, type \"exit\" to return" 10 | echo "" 11 | 12 | bash 13 | 14 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools apt-cacher-ng 3 | -------------------------------------------------------------------------------- /raspbian/build_raspbian_sd_card.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # build your own Raspberry Pi SD card 4 | # 5 | # Modifications by 6 | # Andrius Kairiukstis , http://andrius.mobi/ 7 | # 8 | # 2013-05-05 9 | # resulting files will be stored in rpi folder of script 10 | # during installation, delivery contents folder will be mounted and install.sh script within it will be called 11 | # 12 | # 2013-04-20 13 | # distro replaced from Debian Wheezy to Raspbian (http://raspbian.org) 14 | # build environment and resulting files not in /tmp/rpi instead of /root/rpi 15 | # fixed umount issue 16 | # keymap selection replaced from German (deadkeys) to the US 17 | # size of resulting image was increased to 2GB 18 | # 19 | # Install apt-cacher-ng (apt-get install apt-cacher-ng) and use deb_local_mirror 20 | # more: https://www.unix-ag.uni-kl.de/~bloch/acng/html/config-servquick.html#config-client 21 | # 22 | # 23 | # 24 | # by Klaus M Pfeiffer, http://blog.kmp.or.at/ 25 | # 26 | # 2012-06-24 27 | # just checking for how partitions are called on the system (thanks to Ricky Birtles and Luke Wilkinson) 28 | # using http.debian.net as debian mirror, 29 | # see http://rgeissert.blogspot.co.at/2012/06/introducing-httpdebiannet-debians.html 30 | # tested successfully in debian squeeze and wheezy VirtualBox 31 | # added hint for lvm2 32 | # added debconf-set-selections for kezboard 33 | # corrected bug in writing to etc/modules 34 | # 35 | # 2012-06-16 36 | # improoved handling of local debian mirror 37 | # added hint for dosfstools (thanks to Mike) 38 | # added vchiq & snd_bcm2835 to /etc/modules (thanks to Tony Jones) 39 | # take the value fdisk suggests for the boot partition to start (thanks to Mike) 40 | # 41 | # 2012-06-02 42 | # improoved to directly generate an image file with the help of kpartx 43 | # added deb_local_mirror for generating images with correct sources.list 44 | # 45 | # 2012-05-27 46 | # workaround for https://github.com/Hexxeh/rpi-update/issues/4 47 | # just touching /boot/start.elf before running rpi-update 48 | # 49 | # 2012-05-20 50 | # back to wheezy, http://bugs.debian.org/672851 solved, 51 | # http://packages.qa.debian.org/i/ifupdown/news/20120519T163909Z.html 52 | # 53 | # 2012-05-19 54 | # stage3: remove eth* from /lib/udev/rules.d/75-persistent-net-generator.rules 55 | # initial 56 | 57 | # you need at least 58 | # apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools 59 | 60 | deb_mirror="http://archive.raspbian.org/raspbian" 61 | deb_local_mirror="http://localhost:3142/archive.raspbian.org/raspbian" 62 | 63 | if [ ${EUID} -ne 0 ]; then 64 | echo "this tool must be run as root" 65 | exit 1 66 | fi 67 | 68 | device=$1 69 | if ! [ -b ${device} ]; then 70 | echo "${device} is not a block device" 71 | exit 1 72 | fi 73 | 74 | if [ "${deb_local_mirror}" == "" ]; then 75 | deb_local_mirror=${deb_mirror} 76 | fi 77 | 78 | bootsize="64M" 79 | deb_release="wheezy" 80 | 81 | relative_path=`dirname $0` 82 | 83 | # locate path of this script 84 | absolute_path=`cd ${relative_path}; pwd` 85 | 86 | # locate path of delivery content 87 | delivery_path=`cd ${absolute_path}/../delivery; pwd` 88 | 89 | # define destination folder where created image file will be stored 90 | buildenv=`cd ${absolute_path}; cd ..; mkdir -p rpi/images; cd rpi; pwd` 91 | # buildenv="/tmp/rpi" 92 | 93 | # cd ${absolute_path} 94 | 95 | rootfs="${buildenv}/rootfs" 96 | bootfs="${rootfs}/boot" 97 | 98 | today=`date +%Y%m%d` 99 | 100 | image="" 101 | 102 | if [ "${device}" == "" ]; then 103 | echo "no block device given, just creating an image" 104 | mkdir -p ${buildenv} 105 | image="${buildenv}/images/raspbian_basic_${deb_release}_${today}.img" 106 | dd if=/dev/zero of=${image} bs=1MB count=3800 107 | device=`losetup -f --show ${image}` 108 | echo "image ${image} created and mounted as ${device}" 109 | else 110 | dd if=/dev/zero of=${device} bs=512 count=1 111 | fi 112 | 113 | fdisk ${device} << EOF 114 | n 115 | p 116 | 1 117 | 118 | +${bootsize} 119 | t 120 | c 121 | n 122 | p 123 | 2 124 | 125 | 126 | w 127 | EOF 128 | 129 | 130 | if [ "${image}" != "" ]; then 131 | losetup -d ${device} 132 | device=`kpartx -va ${image} | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1` 133 | device="/dev/mapper/${device}" 134 | bootp=${device}p1 135 | rootp=${device}p2 136 | else 137 | if ! [ -b ${device}1 ]; then 138 | bootp=${device}p1 139 | rootp=${device}p2 140 | if ! [ -b ${bootp} ]; then 141 | echo "uh, oh, something went wrong, can't find bootpartition neither as ${device}1 nor as ${device}p1, exiting." 142 | exit 1 143 | fi 144 | else 145 | bootp=${device}1 146 | rootp=${device}2 147 | fi 148 | fi 149 | 150 | mkfs.vfat ${bootp} 151 | mkfs.ext4 ${rootp} 152 | 153 | mkdir -p ${rootfs} 154 | 155 | mount ${rootp} ${rootfs} 156 | 157 | mkdir -p ${rootfs}/proc 158 | mkdir -p ${rootfs}/sys 159 | mkdir -p ${rootfs}/dev 160 | mkdir -p ${rootfs}/dev/pts 161 | mkdir -p ${rootfs}/usr/src/delivery 162 | 163 | mount -t proc none ${rootfs}/proc 164 | mount -t sysfs none ${rootfs}/sys 165 | mount -o bind /dev ${rootfs}/dev 166 | mount -o bind /dev/pts ${rootfs}/dev/pts 167 | mount -o bind ${delivery_path} ${rootfs}/usr/src/delivery 168 | 169 | cd ${rootfs} 170 | 171 | debootstrap --foreign --arch armhf ${deb_release} ${rootfs} ${deb_local_mirror} 172 | cp /usr/bin/qemu-arm-static usr/bin/ 173 | LANG=C chroot ${rootfs} /debootstrap/debootstrap --second-stage 174 | 175 | mount ${bootp} ${bootfs} 176 | 177 | echo "deb ${deb_local_mirror} ${deb_release} main contrib non-free 178 | " > etc/apt/sources.list 179 | 180 | echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > boot/cmdline.txt 181 | 182 | echo "proc /proc proc defaults 0 0 183 | /dev/mmcblk0p1 /boot vfat defaults 0 0 184 | " > etc/fstab 185 | 186 | echo "raspberrypi" > etc/hostname 187 | 188 | echo "auto lo 189 | iface lo inet loopback 190 | 191 | auto eth0 192 | iface eth0 inet dhcp 193 | " > etc/network/interfaces 194 | 195 | echo "vchiq 196 | snd_bcm2835 197 | " >> etc/modules 198 | 199 | echo "console-common console-data/keymap/policy select Select keymap from full list 200 | console-common console-data/keymap/full select us 201 | " > debconf.set 202 | 203 | echo "#!/bin/bash 204 | debconf-set-selections /debconf.set 205 | rm -f /debconf.set 206 | 207 | cd /usr/src/delivery 208 | apt-get update 209 | apt-get -y install git-core binutils ca-certificates curl 210 | wget --continue https://raw.github.com/Hexxeh/rpi-update/master/rpi-update -O /usr/bin/rpi-update 211 | chmod +x /usr/bin/rpi-update 212 | mkdir -p /lib/modules/3.1.9+ 213 | touch /boot/start.elf 214 | rpi-update 215 | 216 | apt-get -y install locales console-common ntp openssh-server less vim 217 | 218 | # execute install script at mounted external media (delivery contents folder) 219 | cd /usr/src/delivery 220 | ./install.sh 221 | cd 222 | 223 | echo \"root:raspberry\" | chpasswd 224 | sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules 225 | rm -f /etc/udev/rules.d/70-persistent-net.rules 226 | rm -f third-stage 227 | " > third-stage 228 | chmod +x third-stage 229 | LANG=C chroot ${rootfs} /third-stage 230 | 231 | echo "deb ${deb_mirror} ${deb_release} main contrib non-free 232 | " > etc/apt/sources.list 233 | 234 | echo "#!/bin/bash 235 | aptitude update 236 | aptitude clean 237 | apt-get clean 238 | rm -f cleanup 239 | " > cleanup 240 | chmod +x cleanup 241 | LANG=C chroot ${rootfs} /cleanup 242 | 243 | cd ${rootfs} 244 | 245 | sync 246 | sleep 15 247 | 248 | # Make sure we're out of the root fs. We won't be able to unmount otherwise, and umount -l will fail silently. 249 | cd 250 | 251 | umount -l ${bootp} 252 | 253 | umount -l ${rootfs}/usr/src/delivery 254 | umount -l ${rootfs}/dev/pts 255 | umount -l ${rootfs}/dev 256 | umount -l ${rootfs}/sys 257 | umount -l ${rootfs}/proc 258 | 259 | umount -l ${rootfs} 260 | umount -l ${rootp} 261 | 262 | # Remove device mapper bindings. Avoids running out of loop devices if run repeatedly. 263 | dmsetup remove_all 264 | 265 | echo "finishing ${image}" 266 | 267 | if [ "${image}" != "" ]; then 268 | kpartx -d ${image} 269 | echo "created image ${image}" 270 | fi 271 | 272 | echo "done." 273 | -------------------------------------------------------------------------------- /wheezy/build_rpi_wheezy_sd_card.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # build your own Raspberry Pi SD card 4 | # 5 | # by Klaus M Pfeiffer, http://blog.kmp.or.at/ , 2012-06-24 6 | 7 | # 2012-06-24 8 | # just checking for how partitions are called on the system (thanks to Ricky Birtles and Luke Wilkinson) 9 | # using http.debian.net as debian mirror, see http://rgeissert.blogspot.co.at/2012/06/introducing-httpdebiannet-debians.html 10 | # tested successfully in debian squeeze and wheezy VirtualBox 11 | # added hint for lvm2 12 | # added debconf-set-selections for kezboard 13 | # corrected bug in writing to etc/modules 14 | # 2012-06-16 15 | # improoved handling of local debian mirror 16 | # added hint for dosfstools (thanks to Mike) 17 | # added vchiq & snd_bcm2835 to /etc/modules (thanks to Tony Jones) 18 | # take the value fdisk suggests for the boot partition to start (thanks to Mike) 19 | # 2012-06-02 20 | # improoved to directly generate an image file with the help of kpartx 21 | # added deb_local_mirror for generating images with correct sources.list 22 | # 2012-05-27 23 | # workaround for https://github.com/Hexxeh/rpi-update/issues/4 just touching /boot/start.elf before running rpi-update 24 | # 2012-05-20 25 | # back to wheezy, http://bugs.debian.org/672851 solved, http://packages.qa.debian.org/i/ifupdown/news/20120519T163909Z.html 26 | # 2012-05-19 27 | # stage3: remove eth* from /lib/udev/rules.d/75-persistent-net-generator.rules 28 | # initial 29 | 30 | # you need at least 31 | # apt-get install binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools 32 | 33 | deb_mirror="http://http.us.debian.org/debian" 34 | #deb_local_mirror="http://debian.kmp.or.at:3142/debian" 35 | 36 | bootsize="64M" 37 | deb_release="wheezy" 38 | 39 | device=$1 40 | buildenv="/root/rpi" 41 | rootfs="${buildenv}/rootfs" 42 | bootfs="${rootfs}/boot" 43 | 44 | mydate=`date +%Y%m%d` 45 | 46 | if [ "$deb_local_mirror" == "" ]; then 47 | deb_local_mirror=$deb_mirror 48 | fi 49 | 50 | image="" 51 | 52 | 53 | if [ $EUID -ne 0 ]; then 54 | echo "this tool must be run as root" 55 | exit 1 56 | fi 57 | 58 | if ! [ -b $device ]; then 59 | echo "$device is not a block device" 60 | exit 1 61 | fi 62 | 63 | if [ "$device" == "" ]; then 64 | echo "no block device given, just creating an image" 65 | mkdir -p $buildenv 66 | image="${buildenv}/rpi_basic_${deb_release}_${mydate}.img" 67 | dd if=/dev/zero of=$image bs=1MB count=1000 68 | device=`losetup -f --show $image` 69 | echo "image $image created and mounted as $device" 70 | else 71 | dd if=/dev/zero of=$device bs=512 count=1 72 | fi 73 | 74 | fdisk $device << EOF 75 | n 76 | p 77 | 1 78 | 79 | +$bootsize 80 | t 81 | c 82 | n 83 | p 84 | 2 85 | 86 | 87 | w 88 | EOF 89 | 90 | 91 | if [ "$image" != "" ]; then 92 | losetup -d $device 93 | device=`kpartx -va $image | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1` 94 | device="/dev/mapper/${device}" 95 | bootp=${device}p1 96 | rootp=${device}p2 97 | else 98 | if ! [ -b ${device}1 ]; then 99 | bootp=${device}p1 100 | rootp=${device}p2 101 | if ! [ -b ${bootp} ]; then 102 | echo "uh, oh, something went wrong, can't find bootpartition neither as ${device}1 nor as ${device}p1, exiting." 103 | exit 1 104 | fi 105 | else 106 | bootp=${device}1 107 | rootp=${device}2 108 | fi 109 | fi 110 | 111 | mkfs.vfat $bootp 112 | mkfs.ext4 $rootp 113 | 114 | mkdir -p $rootfs 115 | 116 | mount $rootp $rootfs 117 | 118 | cd $rootfs 119 | 120 | debootstrap --foreign --arch armel $deb_release $rootfs $deb_local_mirror 121 | cp /usr/bin/qemu-arm-static usr/bin/ 122 | LANG=C chroot $rootfs /debootstrap/debootstrap --second-stage 123 | 124 | mount $bootp $bootfs 125 | 126 | echo "deb $deb_local_mirror $deb_release main contrib non-free 127 | " > etc/apt/sources.list 128 | 129 | echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait" > boot/cmdline.txt 130 | 131 | echo "proc /proc proc defaults 0 0 132 | /dev/mmcblk0p1 /boot vfat defaults 0 0 133 | " > etc/fstab 134 | 135 | echo "raspberrypi" > etc/hostname 136 | 137 | echo "auto lo 138 | iface lo inet loopback 139 | 140 | auto eth0 141 | iface eth0 inet dhcp 142 | " > etc/network/interfaces 143 | 144 | echo "vchiq 145 | snd_bcm2835 146 | " >> etc/modules 147 | 148 | echo "console-common console-data/keymap/policy select Select keymap from full list 149 | console-common console-data/keymap/full select de-latin1-nodeadkeys 150 | " > debconf.set 151 | 152 | echo "#!/bin/bash 153 | debconf-set-selections /debconf.set 154 | rm -f /debconf.set 155 | apt-get update 156 | apt-get -y install git-core binutils ca-certificates 157 | wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update 158 | chmod +x /usr/bin/rpi-update 159 | mkdir -p /lib/modules/3.1.9+ 160 | touch /boot/start.elf 161 | rpi-update 162 | apt-get -y install locales console-common ntp openssh-server less vim 163 | echo "execute all necessary commands, then type exit" 164 | bash 165 | echo \"root:raspberry\" | chpasswd 166 | sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules 167 | rm -f /etc/udev/rules.d/70-persistent-net.rules 168 | rm -f third-stage 169 | " > third-stage 170 | chmod +x third-stage 171 | LANG=C chroot $rootfs /third-stage 172 | 173 | echo "deb $deb_mirror $deb_release main contrib non-free 174 | " > etc/apt/sources.list 175 | 176 | echo "#!/bin/bash 177 | aptitude update 178 | aptitude clean 179 | apt-get clean 180 | rm -f cleanup 181 | " > cleanup 182 | chmod +x cleanup 183 | LANG=C chroot $rootfs /cleanup 184 | 185 | cd 186 | 187 | sync 188 | sleep 15 189 | 190 | umount -l $bootp 191 | umount -l $rootp 192 | 193 | if [ "$image" != "" ]; then 194 | kpartx -d $image 195 | echo "created image $image" 196 | fi 197 | 198 | 199 | echo "done." 200 | 201 | --------------------------------------------------------------------------------