SELinux Disable 하기
보안 상의 이유로 부팅 때 특정 shell 스크립트가 동작하게 하려면 SELinux 예외 처리를 해야하는 작업이 필요합니다. 저는 단순히 SELinux를 부팅 때 disable 시키는 방법으로 shell 스크립트를 실행하였습니다. 부팅 command line에 아래와 같은 옵션을 추가하여 주면 SELinux를 disable할 수가 있습니다.
androidboot.selinux=disabled
임베디드 보드의 경우 제조사 마다 BoardConfig.mk 파일이 있습니다. 마시멜로 소스 기준으로 LG의 hammerhead 소스를 보면 아래와 같은 설정이 있습니다.
device/lge/hammerhead/BoardConfig.mk
BOARD_KERNEL_CMDLINE := console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1 androidboot.selinux=disabled
위와 같이 command line에 selinux를 disable 하는 설정을 추가합니다.
부팅 시 shell 스크립트 실행
일반적으로 시스템이 부팅 될 때 init.rc에 있는 작업들을 차례대로 수행해줍니다. 여기서 원하는 위치에 실행할 script를 넣으면 됩니다.
system/core/rootdir/init.rc
service test_shell /system/bin/sh /system/etc/test.sh class main user root group root console oneshot
부팅이 완료 된 시점에 맞춰 스크립트 동작
Android 부팅이 완료된 시점에 스크립트를 동작하고 싶은 경우 아래와 같은 property를 이용하여 스크립트 동작이 가능합니다.
on property:dev.bootcomplete=1 start test_shell service test_shell /system/bin/sh /system/etc/test.sh class main console user root group root oneshot disabled