patch_appvm_initramfs.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. #
  21. #
  22. #
  23. # This script can be used to patch the initramfs of the Qubes AppVM
  24. # It inserts an additional script that is responsible for setting up
  25. # COW-based root fs and VM private fs
  26. #
  27. INITRAMFS=$1
  28. INITRAMFS_QUBES=$2
  29. QUBES_COW_SETUP_FILE=$3
  30. TMP_DIR=`mktemp -d /tmp/qubes-initramfs-patching-XXXXXXX`
  31. if [ $# != 3 ] ; then
  32. echo "usage: $0 <original initramfs to patch> <patched initramfs file> <qubes_cow_setup_file>"
  33. exit 0
  34. fi
  35. if [ x$INITRAMFS = x ] ; then
  36. echo "INITRAMFS missing!"
  37. exit 1
  38. fi
  39. if [ x$INITRAMFS_QUBES = x ] ; then
  40. echo "INITRAMFS_QUBES missing!"
  41. exit 1
  42. fi
  43. if [ x$QUBES_COW_SETUP_FILE = x ] ; then
  44. echo "$QUBES_COW_SETUP_FILE missing!"
  45. exit 1
  46. fi
  47. ID=$(id -ur)
  48. if [ $ID != 0 ] ; then
  49. echo "This script should be run as root user. Apparently the initramfs files must have root.root owener..."
  50. exit 1
  51. fi
  52. mkdir $TMP_DIR/initramfs.qubes || exit 1
  53. cp $INITRAMFS $TMP_DIR/initramfs.cpio.gz
  54. pushd $TMP_DIR/initramfs.qubes
  55. gunzip < ../initramfs.cpio.gz | cpio -i --quiet || exit 1
  56. cp $QUBES_COW_SETUP_FILE pre-trigger/90_qubes_cow_setup.sh || exit 1
  57. find ./ | cpio -H newc -o --quiet > $TMP_DIR/initramfs.qubes.cpio || exit 1
  58. popd
  59. gzip $TMP_DIR/initramfs.qubes.cpio || exit 1
  60. mv $TMP_DIR/initramfs.qubes.cpio.gz $INITRAMFS_QUBES || exit 1
  61. rm -fr $TMP_DIR || exit 1