Clean rootfs in switch_root

This commit is contained in:
topjohnwu
2020-04-01 23:37:11 -07:00
parent b28668e18d
commit dbfde74c1e
6 changed files with 27 additions and 35 deletions

View File

@ -121,6 +121,7 @@ if (!is_lnk("/" #name) && read_dt_fstab(cmd, #name)) { \
static void switch_root(const string &path) {
LOGD("Switch root to %s\n", path.data());
int root = xopen("/", O_RDONLY);
vector<string> mounts;
parse_mnt("/proc/mounts", [&](mntent *me) {
// Skip root and self
@ -142,6 +143,9 @@ static void switch_root(const string &path) {
chdir(path.data());
xmount(path.data(), "/", nullptr, MS_MOVE, nullptr);
chroot(".");
LOGD("Cleaning rootfs\n");
frm_rf(root);
}
static void mount_persist(const char *dev_base, const char *mnt_base) {
@ -219,11 +223,6 @@ void SARInit::early_mount() {
backup_files();
LOGD("Cleaning rootfs\n");
int root = xopen("/", O_RDONLY | O_CLOEXEC);
frm_rf(root, { "proc", "sys", "dev" });
close(root);
mount_system_root();
switch_root("/system_root");