Ubuntu Pastebin

Paste from oleg at Fri, 31 Jul 2015 16:04:11 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# For kernels linux-generic-lts-vivid and 3.18+, 
# this script fails with error message:
#    "rm: cannot remove ‘mntpt/foo’: Operation not permitted" 
# strace output: 
#    "unlinkat(AT_FDCWD, "mntpt/foodir", AT_REMOVEDIR) = -1 EPERM (Operation 
#     not permitted)"

# Preliminary checks
  [ "$UID" -eq "0" ] && \
  echo "script should be run as a normal user, not as root" && exit 1
  # lxc-usernsexec provides an easy way to enter a user-namespace.  
  # host uid 1000 is mapped to root in the user-namespace.
  [ ! -f "/usr/bin/lxc-usernsexec" ] && \
  echo "lxc-usernsexec not found.  It is part of the lxc package" && exit 1

script='
   testdir="$HOME/testoverlayfs"
   mkdir -m 0775 -p "$testdir"
   mount -t tmpfs tmpfs -o mode=0775 "$testdir" || exit 1
   cd "$testdir" || exit 1
   mkdir -m 0775 -p lowerdir/foo upperdir workdir mntpt
   touch lowerdir/foo/bar.txt
   mount -n -t overlay overlay \
   -o lowerdir=lowerdir,upperdir=upperdir,workdir=workdir mntpt
   echo -e "\nmounted overlayfs"
   echo -e "\nls -RF mntpt \n -------------"
   ls -RF mntpt
   echo -e "\nrm -r mntpt/* \n -------------"
   rm -r mntpt/*
   echo -e "exit code=$?"
   echo -e "\nls -RF mntpt \n -------------"
   ls -RF mntpt
   umount mntpt
   echo -e "\nunmounted overlayfs"
   echo "cleaning up"
   cd "$testdir"/..
   umount "$testdir"
   rmdir "$testdir"
'

lxc-usernsexec -m b:0:1000:1 -- bash -c "$script"
Download as text