@@ -149,6 +149,9 password, use only in trusted environments. | |||||
149 | ##### `ENABLE_HARDNET`=false |
|
149 | ##### `ENABLE_HARDNET`=false | |
150 | Enable IPv4/IPv6 network stack hardening settings. |
|
150 | Enable IPv4/IPv6 network stack hardening settings. | |
151 |
|
151 | |||
|
152 | ##### `ENABLE_SPLITFS`=false | |||
|
153 | Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`. | |||
|
154 | ||||
152 | ##### `CHROOT_SCRIPTS`="" |
|
155 | ##### `CHROOT_SCRIPTS`="" | |
153 | Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this direcory is run in lexicographical order. |
|
156 | Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this direcory is run in lexicographical order. | |
154 |
|
157 | |||
@@ -167,3 +170,8 After the image file was successfully created by the `rpi2-gen-image.sh` script | |||||
167 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0 |
|
170 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0 | |
168 | dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0 |
|
171 | dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0 | |
169 | ``` |
|
172 | ``` | |
|
173 | If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive: | |||
|
174 | ```shell | |||
|
175 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0 | |||
|
176 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc | |||
|
177 | ``` |
@@ -25,8 +25,8 cleanup (){ | |||||
25 | umount -l $R/dev/pts 2> /dev/null |
|
25 | umount -l $R/dev/pts 2> /dev/null | |
26 | umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null |
|
26 | umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null | |
27 | umount "$BUILDDIR/mount" 2> /dev/null |
|
27 | umount "$BUILDDIR/mount" 2> /dev/null | |
28 |
losetup -d "$ |
|
28 | losetup -d "$ROOT_LOOP" 2> /dev/null | |
29 |
losetup -d "$ |
|
29 | losetup -d "$FRMW_LOOP" 2> /dev/null | |
30 | trap - 0 1 2 3 6 |
|
30 | trap - 0 1 2 3 6 | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
@@ -94,6 +94,7 ENABLE_UBOOT=${ENABLE_UBOOT:=false} | |||||
94 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} |
|
94 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} | |
95 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} |
|
95 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} | |
96 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} |
|
96 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} | |
|
97 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} | |||
97 |
|
98 | |||
98 | # Image chroot path |
|
99 | # Image chroot path | |
99 | R=${BUILDDIR}/chroot |
|
100 | R=${BUILDDIR}/chroot | |
@@ -408,7 +409,11 else | |||||
408 | fi |
|
409 | fi | |
409 |
|
410 | |||
410 | # Set up firmware boot cmdline |
|
411 | # Set up firmware boot cmdline | |
|
412 | if [ "$ENABLE_SPLITFS" = true ] ; then | |||
|
413 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1" | |||
|
414 | else | |||
411 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1" |
|
415 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1" | |
|
416 | fi | |||
412 |
|
417 | |||
413 | # Set up serial console support (if requested) |
|
418 | # Set up serial console support (if requested) | |
414 | if [ "$ENABLE_CONSOLE" = true ] ; then |
|
419 | if [ "$ENABLE_CONSOLE" = true ] ; then | |
@@ -457,6 +462,9 install -o root -g root -m 644 files/modprobe.d/raspi-blacklist.conf $R/etc/modp | |||||
457 |
|
462 | |||
458 | # Create default fstab |
|
463 | # Create default fstab | |
459 | install -o root -g root -m 644 files/fstab $R/etc/fstab |
|
464 | install -o root -g root -m 644 files/fstab $R/etc/fstab | |
|
465 | if [ "$ENABLE_SPLITFS" = true ] ; then | |||
|
466 | sed -i '/mmcblk0p2/sda1/' $R/etc/fstab | |||
|
467 | fi | |||
460 |
|
468 | |||
461 | # Avoid swapping and increase cache sizes |
|
469 | # Avoid swapping and increase cache sizes | |
462 | install -o root -g root -m 644 files/sysctl.d/81-rpi-vm.conf $R/etc/sysctl.d/81-rpi-vm.conf |
|
470 | install -o root -g root -m 644 files/sysctl.d/81-rpi-vm.conf $R/etc/sysctl.d/81-rpi-vm.conf | |
@@ -645,8 +653,8 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`) | |||||
645 |
|
653 | |||
646 | # Calculate the amount of needed 512 Byte sectors |
|
654 | # Calculate the amount of needed 512 Byte sectors | |
647 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) |
|
655 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) | |
648 |
|
|
656 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) | |
649 |
ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${ |
|
657 | ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS}) | |
650 |
|
658 | |||
651 | # The root partition is EXT4 |
|
659 | # The root partition is EXT4 | |
652 | # This means more space than the actual used space of the chroot is used. |
|
660 | # This means more space than the actual used space of the chroot is used. | |
@@ -654,37 +662,63 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS}) | |||||
654 | ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512) |
|
662 | ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512) | |
655 |
|
663 | |||
656 | # Calculate required image size in 512 Byte sectors |
|
664 | # Calculate required image size in 512 Byte sectors | |
657 |
IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${ |
|
665 | IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS}) | |
658 |
|
666 | |||
659 | # Prepare date string for image file name |
|
667 | # Prepare date string for image file name | |
660 | DATE="$(date +%Y-%m-%d)" |
|
668 | DATE="$(date +%Y-%m-%d)" | |
661 |
|
669 | |||
662 | # Prepare image file |
|
670 | # Prepare image file | |
|
671 | if [ "$ENABLE_SPLITFS" = true ] ; then | |||
|
672 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS} | |||
|
673 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS} | |||
|
674 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS} | |||
|
675 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS} | |||
|
676 | # Write partition tables | |||
|
677 | sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" <<EOM | |||
|
678 | unit: sectors | |||
|
679 | ||||
|
680 | 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable | |||
|
681 | 2 : start= 0, size= 0, Id= 0 | |||
|
682 | 3 : start= 0, size= 0, Id= 0 | |||
|
683 | 4 : start= 0, size= 0, Id= 0 | |||
|
684 | EOM | |||
|
685 | sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" <<EOM | |||
|
686 | unit: sectors | |||
|
687 | ||||
|
688 | 1 : start= ${TABLE_SECTORS}, size= ${ROOT_SECTORS}, Id=83 | |||
|
689 | 2 : start= 0, size= 0, Id= 0 | |||
|
690 | 3 : start= 0, size= 0, Id= 0 | |||
|
691 | 4 : start= 0, size= 0, Id= 0 | |||
|
692 | EOM | |||
|
693 | # Set up temporary loop devices and build filesystems | |||
|
694 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)" | |||
|
695 | ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)" | |||
|
696 | else | |||
663 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} |
|
697 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} | |
664 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} |
|
698 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} | |
665 |
|
||||
666 | # Write partition table |
|
699 | # Write partition table | |
667 | sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM |
|
700 | sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM | |
668 | unit: sectors |
|
701 | unit: sectors | |
669 |
|
702 | |||
670 |
1 : start= ${TABLE_SECTORS}, size= ${ |
|
703 | 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable | |
671 | 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83 |
|
704 | 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83 | |
672 | 3 : start= 0, size= 0, Id= 0 |
|
705 | 3 : start= 0, size= 0, Id= 0 | |
673 | 4 : start= 0, size= 0, Id= 0 |
|
706 | 4 : start= 0, size= 0, Id= 0 | |
674 | EOM |
|
707 | EOM | |
675 |
|
||||
676 | # Set up temporary loop devices and build filesystems |
|
708 | # Set up temporary loop devices and build filesystems | |
677 |
|
|
709 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" | |
678 |
|
|
710 | ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" | |
679 | mkfs.vfat "$VFAT_LOOP" |
|
711 | fi | |
680 | mkfs.ext4 "$EXT4_LOOP" |
|
712 | ||
|
713 | mkfs.vfat "$FRMW_LOOP" | |||
|
714 | mkfs.ext4 "$ROOT_LOOP" | |||
681 |
|
715 | |||
682 | # Mount the temporary loop devices |
|
716 | # Mount the temporary loop devices | |
683 | mkdir -p "$BUILDDIR/mount" |
|
717 | mkdir -p "$BUILDDIR/mount" | |
684 |
mount "$ |
|
718 | mount "$ROOT_LOOP" "$BUILDDIR/mount" | |
685 |
|
719 | |||
686 | mkdir -p "$BUILDDIR/mount/boot/firmware" |
|
720 | mkdir -p "$BUILDDIR/mount/boot/firmware" | |
687 |
mount "$ |
|
721 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" | |
688 |
|
722 | |||
689 | # Copy all files from the chroot to the loop device mount point directory |
|
723 | # Copy all files from the chroot to the loop device mount point directory | |
690 | rsync -a "$R/" "$BUILDDIR/mount/" |
|
724 | rsync -a "$R/" "$BUILDDIR/mount/" | |
@@ -692,8 +726,18 rsync -a "$R/" "$BUILDDIR/mount/" | |||||
692 | # Unmount all temporary loop devices and mount points |
|
726 | # Unmount all temporary loop devices and mount points | |
693 | cleanup |
|
727 | cleanup | |
694 |
|
728 | |||
695 | # (optinal) create block map file for "bmaptool" |
|
729 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
|
730 | # (optional) create block map file for "bmaptool" | |||
|
731 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" | |||
|
732 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" | |||
|
733 | ||||
|
734 | # Image was successfully created | |||
|
735 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} \* 512 \/ 1024)M)" ": successfully created" | |||
|
736 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr ${TABLE_SECTORS} + ${ROOT_SECTORS} \* 512 \/ 1024)M)" ": successfully created" | |||
|
737 | else | |||
|
738 | # (optional) create block map file for "bmaptool" | |||
696 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img" |
|
739 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img" | |
697 |
|
740 | |||
698 | # Image was successfully created |
|
741 | # Image was successfully created | |
699 |
echo "$BASEDIR/${DATE}-debian-${RELEASE}.img (${ |
|
742 | echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \* 512 \/ 1024)M)" ": successfully created" | |
|
743 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant