install_to_disk.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. ROOTFS_TAR='parabola-systemd-cli-armv7h-tarball-2018-02-06.tar.gz'
  3. KERNEL_BASE_VER="$(cat linux-libre/version | sed 's/\(\..*\)\..*/\1/g')"
  4. PACKED_ZIMG_FILE="linux-libre/linux-$KERNEL_BASE_VER/vmlinux.kpart"
  5. DISK="$1"
  6. KERNEL_PART="$DISK"1
  7. ROOTFS_PART="$DISK"2
  8. ROOTFS_UUID="$(blkid | grep $ROOTFS_PART | awk -F'"' '{print $2}')"
  9. SWAP_PART="$DISK"3
  10. SWAP_UUID="$(blkid | grep $SWAP_PART | awk -F'"' '{print $2}')"
  11. # Make sure only root can run our script
  12. if [ "$(id -u)" != "0" ]; then
  13. echo "This script must be run as root" 1>&2
  14. exit 1
  15. fi
  16. if [ x"$DISK" == 'x' ]; then
  17. echo "This script requires a base block device as its only arguement" 1>&2
  18. echo "example: $0 /dev/sdb"
  19. exit 1
  20. fi
  21. mkdir mnt
  22. mount $ROOTFS_PART mnt
  23. bsdtar -xf $ROOTFS_TAR -C mnt
  24. echo "in another terminal you can run 'watch grep -e Dirty: -e Writeback: /proc/meminfo' to watch the sync progress"
  25. sync
  26. # set root password to root https://unix.stackexchange.com/questions/76313/change-password-of-a-user-in-etc-shadow
  27. perl -pi -e 's|(root):(\$.*?:)|\1:\$6\$SALTsalt\$6cu/5trl4ffmLFSZzTa/g6RJK1ecHq79FXHN448S2EgSUHBv/y0AxNXW4MpJfPEZPNjdvpxZZCzDNRxINCjJ0.:|' mnt/etc/shadow
  28. sed -i 's/^/## /g' mnt/etc/fstab
  29. echo "UUID=$ROOTFS_UUID / ext4 rw,relatime,data=ordered 0 1" >> mnt/etc/fstab
  30. echo "UUID=$SWAP_UUID none swap defaults 0 0" >> mnt/etc/fstab
  31. cp $PACKED_ZIMG_FILE mnt/boot/
  32. dd if=mnt/boot/vmlinux.kpart of=$KERNEL_PART
  33. umount mnt