Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2fsck to the initrd and use it when mounting stowaways #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ endif

# Command used to make the image
BB_STATIC := $(PRODUCT_OUT)/utilities/busybox
E2FSCK_STATIC := $(PRODUCT_OUT)/utilities/e2fsck

ifneq ($(strip $(TARGET_NO_KERNEL)),true)
INSTALLED_KERNEL_TARGET := $(PRODUCT_OUT)/kernel
Expand Down Expand Up @@ -142,7 +143,7 @@ else
@mkbootimg --ramdisk $(BOOT_RAMDISK) $(HYBRIS_BOOTIMAGE_ARGS) $(BOARD_MKBOOTIMG_ARGS) --output $@
endif

$(BOOT_RAMDISK): $(BOOT_RAMDISK_FILES) $(BB_STATIC)
$(BOOT_RAMDISK): $(BOOT_RAMDISK_FILES) $(BB_STATIC) $(E2FSCK_STATIC)
@echo "Making initramfs : $@"
@rm -rf $(BOOT_INTERMEDIATE)/initramfs
@mkdir -p $(BOOT_INTERMEDIATE)/initramfs
Expand All @@ -151,6 +152,7 @@ $(BOOT_RAMDISK): $(BOOT_RAMDISK_FILES) $(BB_STATIC)
# really hard to depend on things which may affect init.
@mv $(BOOT_RAMDISK_INIT) $(BOOT_INTERMEDIATE)/initramfs/init
@cp $(BB_STATIC) $(BOOT_INTERMEDIATE)/initramfs/bin/
@cp $(E2FSCK_STATIC) $(BOOT_INTERMEDIATE)/initramfs/bin/
ifeq ($(BOARD_CUSTOM_MKBOOTIMG),pack_intel)
@(cd $(BOOT_INTERMEDIATE)/initramfs && find . | cpio -H newc -o ) | $(MINIGZIP) > $(BOOT_RAMDISK)
else
Expand Down Expand Up @@ -193,13 +195,14 @@ else
$(hide)$(MKBOOTIMG) --ramdisk $(RECOVERY_RAMDISK) $(HYBRIS_RECOVERYIMAGE_ARGS) $(BOARD_MKRECOVERYIMG_ARGS) --output $@
endif

$(RECOVERY_RAMDISK): $(RECOVERY_RAMDISK_FILES) $(BB_STATIC)
$(RECOVERY_RAMDISK): $(RECOVERY_RAMDISK_FILES) $(BB_STATIC) $(E2FSCK_STATIC)
@echo "Making initramfs : $@"
@rm -rf $(RECOVERY_INTERMEDIATE)/initramfs
@mkdir -p $(RECOVERY_INTERMEDIATE)/initramfs
@cp -a $(RECOVERY_RAMDISK_SRC)/* $(RECOVERY_INTERMEDIATE)/initramfs
@mv $(RECOVERY_RAMDISK_INIT) $(RECOVERY_INTERMEDIATE)/initramfs/init
@cp $(BB_STATIC) $(RECOVERY_INTERMEDIATE)/initramfs/bin/
@cp $(E2FSCK_STATIC) $(RECOVERY_INTERMEDIATE)/initramfs/bin/
ifeq ($(BOARD_CUSTOM_MKBOOTIMG),pack_intel)
@(cd $(RECOVERY_INTERMEDIATE)/initramfs && find . | cpio -H newc -o ) | $(MINIGZIP) > $(RECOVERY_RAMDISK)
else
Expand Down
36 changes: 28 additions & 8 deletions init-script
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,42 @@ bootsplash() {


mount_stowaways() {
echo "########################## mounting stowaways"
if [ ! -z $DATA_PARTITION ]; then
data_subdir="$(get_opt data_subdir)"
echo "########################## mounting stowaways"
if [ ! -z $DATA_PARTITION ]; then
data_subdir="$(get_opt data_subdir)"

mkdir /data
mkdir /target

mount $DATA_PARTITION /data
echo "Checking filesystem integrity for the userdata partition"
fsck_start=`date +%s`

# Mounting and unmounting /data means the kernel will handle the
# journal/orphans, this is faster than e2fsck doing everything
mkdir /tmpmnt
mount $DATA_PARTITION /tmpmnt -o errors=remount-ro
umount /tmpmnt
rmdir /tmpmnt
e2fsck -y $DATA_PARTITION

fsck_end=`date +%s`
echo "Finished checking, took $((fsck_end-fsck_start)) second(s)"
mount -o discard,data=journal $DATA_PARTITION /data

echo "Checking rootfs filesystem integrity"
fsck_start=`date +%s`
e2fsck -y /data/rootfs.img
fsck_end=`date +%s`
echo "Finished checking, took $((fsck_end-fsck_start)) second(s)"

mount /data/rootfs.img /target

mkdir -p /target/data # in new fs
mount --bind /data/${data_subdir} /target/data
else
echo "Failed to mount /target, device node '$DATA_PARTITION' not found!" >> /diagnosis.log
fi
mount
else
echo "Failed to mount /target, device node '$DATA_PARTITION' not found!" >> /diagnosis.log
fi
mount
}

umount_stowaways() {
Expand Down