From dc624aecea43e8ae0d997c42c0e98c83ce7ef1b8 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sat, 10 Mar 2018 14:24:16 +0000 Subject: [PATCH] Mount tmpfs in chroot's /dev folders (#1317) --- pmb/chroot/init.py | 5 +---- pmb/chroot/mount.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pmb/chroot/init.py b/pmb/chroot/init.py index a4bfd9d8..4b9b711e 100644 --- a/pmb/chroot/init.py +++ b/pmb/chroot/init.py @@ -46,10 +46,7 @@ def copy_resolv_conf(args, suffix="native"): def create_device_nodes(args, suffix): - error = ("Failed to create nodes in the '" + suffix + "' chroot. Please" - " run 'pmbootstrap init' again and put your work folder on a" - " normal Linux filesystem. (No ntfs, fat, encfs or encfs" - " encrypted home folder, shared folder etc.)") + error = "Failed to create device nodes in the '" + suffix + "' chroot." # Folder sturcture chroot = args.work + "/chroot_" + suffix diff --git a/pmb/chroot/mount.py b/pmb/chroot/mount.py index 55f61f0b..929ebfa0 100644 --- a/pmb/chroot/mount.py +++ b/pmb/chroot/mount.py @@ -22,10 +22,31 @@ import pmb.parse import pmb.helpers.mount +def mount_dev_tmpfs(args, suffix="native"): + """ + Mount tmpfs inside the chroot's dev folder to make sure we can create + device nodes, even if the filesystem of the work folder does not support + it. + """ + # Do nothing when it is already mounted + dev = args.work + "/chroot_" + suffix + "/dev" + if pmb.helpers.mount.ismount(dev): + return + + # Create the folder structure and mount it + if not os.path.exists(dev): + pmb.helpers.run.root(args, ["mkdir", "-p", dev]) + pmb.helpers.run.root(args, ["mount", "-t", "tmpfs", + "-o", "size=1M,noexec,dev", + "tmpfs", dev]) + + def mount(args, suffix="native"): - arch = pmb.parse.arch.from_chroot_suffix(args, suffix) + # Mount tmpfs as the chroot's /dev + mount_dev_tmpfs(args, suffix) # Get all mountpoints + arch = pmb.parse.arch.from_chroot_suffix(args, suffix) mountpoints = {} for source, target in pmb.config.chroot_mount_bind.items(): source = source.replace("$WORK", args.work)