#!/bin/sh # # Shell script to copy FreeBSD system from SD Card to eMMC, NVMe, USB, SATA # Warning: This erases the eMMC or NVMe before copying! # Copy system to DISK # Leave one by choice !!!! default SATA # DISK="da0" # USB HDD DISK="nda0" # NVMe SDD DISK="ada0" # SATA HDD # U-Boot source UBOOT="u-boot-helios64" # TPL/SPL U-boot UBOOT="u-boot-helios64-bsp" # U-Boot with rockcip blobs UBOOT_PATH="/usr/local/share/u-boot/${UBOOT}" echo "Warning: This script erases /dev/${DISK}" echo "It then copies your FreeBSD system from /dev/mmcsd0" echo echo 'If you booted from SD:' echo ' /dev/mmcsd0 will refer to the micro-SD card' echo " /dev/${DISK} will refer to the DESTINATION" echo echo 'If you booted from eMMC, it will be the other way around' echo '(Check the boot messages to verify your situation.)' echo echo 'If you are certain you want this script to erase stuff,' echo 'edit the script, remove the "exit 1" command, and run it again.' exit 1 echo echo "Erasing /dev/${DISK}! (Hope you meant this!)" gpart destroy -F ${DISK} 2> /dev/null echo "Copying u-boot to /dev/${DISK}" if [ -f ${UBOOT_PATH}/trust.img ]; then # Rockchip Blobs U-boot dd if=${UBOOT_PATH}/idbloader.img of=/dev/${DISK} conv=sync bs=512 seek=64 > /dev/null 2>&1 dd if=${UBOOT_PATH}/uboot.img of=/dev/${DISK} conv=sync bs=512 seek=16384 > /dev/null 2>&1 dd if=${UBOOT_PATH}/trust.img of=/dev/${DISK} conv=sync bs=512 seek=24576 > /dev/null 2>&1 else # Mainline U-Boot dd if=${UBOOT_PATH}/idbloader.img of=/dev/${DISK} conv=sync bs=512 seek=64 > /dev/null 2>&1 dd if=${UBOOT_PATH}/u-boot.itb of=/dev/${DISK} conv=sync bs=512 seek=16384 > /dev/null 2>&1 fi echo echo "Creating GPT on /dev/${DISK}" gpart create -s GPT ${DISK} gpart add -t efi -l efi -a 512k -s 50m -b 16m ${DISK} echo echo "Creating FreeBSD partition on /dev/${DISK}" gpart add -t freebsd-swap -s 4G -a 64k -l swapfs ${DISK} gpart add -t freebsd-ufs -a 64k -l rootfs ${DISK} echo "Creating MSDOS boot FS on /dev/${DISK}" newfs_msdos -L 'efi' /dev/${DISK}p1 mount_msdosfs /dev/${DISK}p1 /media echo echo "Copying loader efi to /dev/${DISK}" mkdir -p /media/EFI/BOOT cp /boot/loader.efi /media/EFI/BOOT/bootaa64.efi cp -r /boot/dtb /media sync; sync; sync umount /media newfs -L 'rootfs' /dev/${DISK}p3 tunefs -N enable -a enable -t enable -L 'rootfs' /dev/${DISK}p3 mount /dev/${DISK}p3 /media echo echo "Copying the system from SD to /dev/${DISK}" tar -cf - -C / \ --exclude .sujournal \ --exclude .snap \ --exclude media \ --exclude usr/obj \ --exclude usr/src \ --exclude usr/ports \ --exclude var/run \ . \ | tar -xvf - -C /media mkdir -p /media/media /media/var/run echo echo 'Cleaning up the copied system' # Reset permissions, ensure the required directories (cd /media ; mtree -Uief /etc/mtree/BSD.root.dist) (cd /media/usr ; mtree -Uief /etc/mtree/BSD.usr.dist) (cd /media/usr/include ; mtree -Uief /etc/mtree/BSD.include.dist) (cd /media/var ; mtree -Uief /etc/mtree/BSD.var.dist) # Have the copied system generate its own keys # (In particular, if this SD card is used to copy # a system onto a bunch of BBBlacks, we do not want # them to all have the same SSH keys.) rm -f /media/etc/ssh/*key* echo echo "Replacing fstab on /dev/${DISK}" cat <<EOF >/media/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/gpt/efi /boot/efi msdosfs rw,noauto 0 0 /dev/gpt/rootfs / ufs rw,noatime 1 1 /dev/gpt/swapfs none swap sw 0 0 fdesc /dev/fd fdescfs rw 0 0 proc /proc procfs rw 0 0 md /var/log mfs rw,noatime,-s16m 0 0 md /tmp mfs rw,noatime,-s256m 0 0 EOF echo "/media/etc/fstab" cat /media/etc/fstab echo sync; sync; sync echo echo 'System copied.' echo echo "/dev/${DISK} root filesystem is still mounted on /media" echo 'You can make changes there now before rebooting if you wish.' echo echo "To reboot from /dev/${DISK}:" echo ' * Clean shutdown: shutdown -p now' echo ' * Remove power' echo ' * Remove SD card' echo ' * Reapply power (do NOT hold boot switch)'
基本的には今までやってきた方法と同じだが,違うのは
ぐらいか…