From 6860338c4b0d61d56de8755b25b7ba925a93e131 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Mon, 5 Dec 2016 10:02:59 +0100 Subject: [PATCH] Use disk images instead of a rootfs tarball --- scripts/anbox-init.sh | 28 --------------------- scripts/container-manager.sh | 47 ++++++++++++++++++++++++++++-------- snapcraft.yaml | 5 ++-- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/scripts/anbox-init.sh b/scripts/anbox-init.sh index 55baddac..ce61cced 100644 --- a/scripts/anbox-init.sh +++ b/scripts/anbox-init.sh @@ -23,34 +23,6 @@ function prepare_filesystem() { chown system:system /dev/$f chmod 0666 /dev/$f done - - if [ ! -e /.anbox_setup_done ] ; then - echo "Fixing up all permissions ..." - - # Fixup permissions of the android binaries in /system - while read line - do - file=`echo $line | cut -d' ' -f 1` - user=`echo $line | cut -d' ' -f 2` - group=`echo $line | cut -d' ' -f 3` - mode=`echo $line | cut -d' ' -f 4` - # Avoid changing symlinks - if [ ! -h /$file ] ; then - chmod $mode /$file - chown -h $user:$group /$file - fi - done < "/filesystem_config.txt" - - # Additional ones not listed in the config generated from the build - for f in qemu_pipe qemu_trace goldfish_pipe ; do - [ ! -e /dev/$f ] && continue - chown system:system /dev/$f - chmod 0666 /dev/$f - done - - echo "Setup done!" - echo $VERSION > /.anbox_setup_done - fi } prepare_filesystem & diff --git a/scripts/container-manager.sh b/scripts/container-manager.sh index 0c90121f..f9232096 100755 --- a/scripts/container-manager.sh +++ b/scripts/container-manager.sh @@ -5,18 +5,42 @@ # Other than that nothing should ever modify the content of the # rootfs. -ROOTFS_PATH=$SNAP_COMMON/var/lib/anbox/rootfs -ROOTFS_VERSION=1 - -if [ ! -e $ROOTFS_PATH ] || [ "$ROOTFS_VERSION" != "$(cat $ROOTFS_PATH/.version)" ] ; then - rm -rf $ROOTFS_PATH - echo "Copying rootfs into $ROOTFS_PATH .." - mkdir -p $ROOTFS_PATH - tar xf $SNAP/android-rootfs.tar -C $ROOTFS_PATH/ --strip-components=1 - chown -R root:root $ROOTFS_PATH - echo $ROOTFS_VERSION > $ROOTFS_PATH/.version +DATA_PATH=$SNAP_COMMON/var/lib/anbox +ROOTFS_PATH=$DATA_PATH/rootfs +RAMDISK_PATH=$DATA_PATH/ramdisk +INITRD=$SNAP/ramdisk.img +SYSTEM_IMG=$SNAP/system.img +ANDROID_DATA_PATH=$DATA_PATH/android-data + +if [ ! -e $INITRD ]; then + echo "ERROR: boot ramdisk does not exist" + exit 1 +fi + +if [ ! -e $SYSTEM_IMG ]; then + echo "ERROR: system image does not exist" + exit 1 fi +# Extract ramdisk content instead of trying to bind mount the +# cpio image file to allow modifications. +rm -Rf $RAMDISK_PATH +mkdir -p $RAMDISK_PATH +cd $RAMDISK_PATH +cat $INITRD | gzip -d | cpio -i + +# FIXME those things should be fixed in the build process +chmod +x $RAMDISK_PATH/anbox-init.sh + +# Setup the read-only rootfs +mkdir -p $ROOTFS_PATH +mount -o bind,ro $RAMDISK_PATH $ROOTFS_PATH +mount -o loop,ro $SYSTEM_IMG $ROOTFS_PATH/system + +# ... but we keep /data in the read/write space +mkdir -p $ANDROID_DATA_PATH +mount -o bind $ANDROID_DATA_PATH $ROOTFS_PATH/data + # Make sure our setup path for the container rootfs # is present as lxc is statically configured for # this path. @@ -31,3 +55,6 @@ pid=$! waitpid $pid $SNAP/bin/anbox-bridge.sh stop + +umount $ROOTFS_PATH/system +umount $ROOTFS_PATH/data diff --git a/snapcraft.yaml b/snapcraft.yaml index 40352db0..95abac08 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -22,11 +22,12 @@ apps: # daemon: oneshot parts: - android-rootfs: + android: plugin: copy source: . files: - android-rootfs.tar: android-rootfs.tar + system.img: system.img + ramdisk.img: ramdisk.img anbox-common: plugin: copy source: . -- GitLab