Merge pull request #50 from marcosps/mpdesouza_ezequiel_cwd

run: Add a --cwd command to change the working directory
diff --git a/virtme/commands/run.py b/virtme/commands/run.py
index 52e8de6..ce00154 100644
--- a/virtme/commands/run.py
+++ b/virtme/commands/run.py
@@ -112,6 +112,8 @@
     g = parser.add_argument_group(title='Guest userspace configuration')
     g.add_argument('--pwd', action='store_true',
                    help='Propagate current working directory to the guest')
+    g.add_argument('--cwd', action='store',
+                   help='Change guest working directory')
 
     g = parser.add_argument_group(title='Sharing resources with guest')
     g.add_argument('--rwdir', action='append', default=[],
@@ -490,6 +492,13 @@
             return 1
         kernelargs.append('virtme_chdir=%s' % rel_pwd)
 
+    if args.cwd:
+        rel_cwd = os.path.relpath(args.cwd, args.root)
+        if rel_cwd.startswith('..'):
+            print('specified working directory is not contained in the root')
+            return 1
+        kernelargs.append('virtme_chdir=%s' % rel_cwd)
+
     initrdpath: Optional[str]
 
     if need_initramfs: