##// END OF EJS Templates
Added ENABLE_SPLITFS option to create distinct images for firmware and root partitions
Vincent Knecht -
r65:54acc1e70a3e
parent child
Show More
@@ -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 "$EXT4_LOOP" 2> /dev/null
28 losetup -d "$ROOT_LOOP" 2> /dev/null
29 losetup -d "$VFAT_LOOP" 2> /dev/null
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
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"
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
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 BOOT_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
656 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
649 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_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} + ${BOOT_SECTORS} + ${ROOT_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
663 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
671 if [ "$ENABLE_SPLITFS" = true ] ; then
664 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
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
665
679
666 # Write partition table
680 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
667 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
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
668 unit: sectors
686 unit: sectors
669
687
670 1 : start= ${TABLE_SECTORS}, size= ${BOOT_SECTORS}, Id= c, bootable
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
697 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
698 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
699 # Write partition table
700 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
701 unit: sectors
702
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
708 # Set up temporary loop devices and build filesystems
709 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
710 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
711 fi
675
712
676 # Set up temporary loop devices and build filesystems
713 mkfs.vfat "$FRMW_LOOP"
677 VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
714 mkfs.ext4 "$ROOT_LOOP"
678 EXT4_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
679 mkfs.vfat "$VFAT_LOOP"
680 mkfs.ext4 "$EXT4_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 "$EXT4_LOOP" "$BUILDDIR/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 "$VFAT_LOOP" "$BUILDDIR/mount/boot/firmware"
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
696 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
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"
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 (${IMAGE_SIZE})" ": successfully created"
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