anchor.diff:  %% release, then one can move the release to a different directory and
   %% it should still work).
   move_system(Conf) when is_list(Conf) ->
  -    OldCWD = file:get_cwd(),
  +
       DataDir = ?config(data_dir, Conf),
  -    TestRootDir = filename:join(DataDir, "relocatable_release"),
  +    TestRootDir = filename:join(priv_dir(Conf), ?FUNCTION_NAME),
  +    ErtsBinDir = filename:join("erts-" ++ find_vsn_app(erts), "bin"),
  +
       %% Remove old test data
  -    file:set_cwd(TestRootDir),
  -    os:cmd("rm -r system"),
  -    os:cmd("rm -r system_moved"),
  -    os:cmd("rm -r system_moved_again"),
  +    file:del_dir_r(filename:join(TestRootDir,"system")),
  +    file:del_dir_r(filename:join(TestRootDir,"system_moved")),
  +    file:del_dir_r(filename:join(TestRootDir,"system_moved_again")),
  +
       %% Create TAR file for release A
       ReleaseATarFile = create_release_package(DataDir, "hello_server", "A"),
       SystemPath = filename:join(TestRootDir, "system"),
       ok = erl_tar:extract(ReleaseATarFile, [{cwd, SystemPath}, compressed]),
       RelDir = filename:join(SystemPath, "releases"),
       SystemRelFile = filename:join(RelDir, "hello_server-A.rel"),
  -    %% Create a location independent RELEASES file by passing an empty
  -    %% string as the RootDir parameter. Library paths in the releases
  +
  +    %% Create a location independent RELEASES file. Library paths in the releases
       %% file are assumed to be relative to the RootDir.
  -    ok = release_handler:create_RELEASES("", RelDir, SystemRelFile, []),
  +    ok = release_handler:create_RELEASES(RelDir, SystemRelFile, []),
  +
  +    %% Create the bin directory with links (or copies on windows) to the erts directory
  +    file:make_dir(filename:join(SystemPath,"bin")),
  +    case os:type() of
  +        {win32, _} ->
  +            {ok,_} = file:copy(
  +                       filelib:wildcard(filename:join([SystemPath,ErtsBinDir,"erl.exe"])),
  +                       filename:join([SystemPath,"bin","erl.exe"]));
  +        _ ->
  +            ok = file:make_symlink(
  +                   filename:join(["..",ErtsBinDir,"erl"]),
  +                   filename:join([SystemPath,"bin","erl"]))
  +    end,
  +
       %% Test that the location independent system can start and run
  -    file:set_cwd(SystemPath),
  -    SystemErlPath = filename:join(["erts-" ++ find_vsn_app(erts), "bin", "erl"]),
  -    SystemTestCmd = SystemErlPath ++ " -noshell -boot releases/A/start -eval \"global:whereis_name(hello_server) ! self(),erlang:display(receive M -> M end),erlang:halt()\"",
  -    [$h, $e, $l, $l, $o | _] = os:cmd(SystemTestCmd),
  +    {ok, Peer, Node} = start_remote_node(SystemPath, "A"),
  +    hello = erpc:call(Node, app_callback_module, get_response, []),
  +    peer:stop(Peer),
  +
       %% Should still work after copying the system and corrupting the source
  -    os:cmd("rm -r ../system_moved"),
  -    os:cmd("cp -r . ../system_moved"),
  -    os:cmd("rm -r lib/stdlib*"),
  -    os:cmd("rm -r releases"),
       NewSystemPath = filename:join(TestRootDir, "system_moved"),
  -    file:set_cwd(NewSystemPath),
  -    [$h, $e, $l, $l, $o | _] = os:cmd(SystemTestCmd),
  +    copy_r(SystemPath, NewSystemPath),
  +    [file:del_dir_r(F) || F <- filelib:wildcard(filename:join([SystemPath,"lib","stdlib*"]))],
  +    file:del_dir_r(filename:join(SystemPath,"releases")),
  +    {ok, MovedPeer, MovedNode} = start_remote_node(NewSystemPath, "A"),
  +    hello = erpc:call(MovedNode, app_callback_module, get_response, []),
  +    peer:stop(MovedPeer),
  +
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       %% Let us now try if a system upgrade also works with a location independent system %
       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       ReleaseBTarFile = create_release_package(DataDir, "hello_server_new", "B"),
  -    file:set_cwd(NewSystemPath),
  -    BPackDest = filename:join([NewSystemPath,"releases", filename:basename(ReleaseBTarFile)]),
  +
  +    BPackDest = filename:join([NewSystemPath, "releases", filename:basename(ReleaseBTarFile)]),
       {ok, _ } = file:copy(ReleaseBTarFile, BPackDest),
       BTarFileName = filename:basename(ReleaseBTarFile),
       NameToUnpack = filename:rootname(BTarFileName, ".tar.gz"),
       %% Start remote node with release A
  -    Node = start_remote_node("A"),
  -    try
  -        %% Set current working directory to something irrelevant as the
  -        %% current working directory should not affect if a system is
  -        %% location independent or not
  -        ok = rpc:call(Node, file, set_cwd, ["/"]),
  -        {ok, "/"} = rpc:call(Node, file, get_cwd, []),
  -        %% Let us check our app
  -        hello = rpc:call(Node, app_callback_module, get_response, []),
  -        %% Install the next release
  -        {ok, "B"} = rpc:call(Node, release_handler, unpack_release, [NameToUnpack]),
  -        %% We can now create relup file
  -        AppUpSrc = filename:join([TestRootDir, "hello_server_new", "ebin", "hello_server.appup"]),
  -        AppUpDest = filename:join([NewSystemPath, "lib", "hello_server-B", "ebin", "hello_server.appup"]),
  -        {ok, _} = file:copy(AppUpSrc, AppUpDest),
  -        %% Run command to create the relup file
  -        os:cmd("erl -noshell -pa lib/hello_server-A/ebin/ -pa lib/hello_server-B/ebin/ -eval "
  -               "\"systools:make_relup(\\\"releases/B/hello_server-B\\\", [\\\"releases/A/hello_server-A\\\"], [\\\"releases/A/hello_server-A\\\"]),erlang:halt()\""),
  -        %% Copy relup to correct location
  -        {ok, _} = file:copy("relup", filename:join(["releases", "B", "relup"])),
  -        %% Install the B version
  -        {ok, "A", _} = rpc:call(Node, release_handler, install_release, ["B"]),
  -        %% Check that the releases info looks ok
  -        Releases = rpc:call(Node, release_handler, which_releases, []),
  -        true = lists:any(fun({"hello_server", "B", _, current}) ->
  -                                 true;
  -                            (_) ->
  -                                 false
  -                         end,
  -                         Releases),
  -        %% Make sure the old module gets replaced
  -        ok = rpc:call(Node, app_callback_module, update, []),
  -        %% Check that the upgrade worked
  -        hej = rpc:call(Node, app_callback_module, get_response, []),
  -        %% Make the upgrade permanent
  -        ok = rpc:call(Node, release_handler, make_permanent, ["B"]),
  -        %% Check that it still works
  -        hej = rpc:call(Node, app_callback_module, get_response, []),
  -        Releases2 = rpc:call(Node, release_handler, which_releases, []),
  -        true = lists:any(fun({"hello_server", "B", _, permanent}) ->
  -                                 true;
  -                            (_) ->
  -                                 false
  -                         end,
  -                         Releases2)
  -    catch
  -        Class:Reason:Stacktrace ->
  -            erlang:raise(Class, Reason, Stacktrace)
  -    after
  -        %% Try to make sure the node goes down even if we fail the test case
  -        (catch rpc:call(Node, erlang, halt, []))
  -    end,
  +    {ok, PeerA, NodeA} = start_remote_node(NewSystemPath, "A"),
  +
  +    %% Set current working directory to something irrelevant as the
  +    %% current working directory should not affect if a system is
  +    %% location independent or not
  +    ok = erpc:call(NodeA, file, set_cwd, ["/"]),
  +    %% Let us check our app
  +    hello = erpc:call(NodeA, app_callback_module, get_response, []),
  +    %% Install the next release
  +    {ok, "B"} = erpc:call(NodeA, release_handler, unpack_release, [NameToUnpack]),
  +    %% We can now create relup file
  +    AppUpSrc = filename:join([DataDir, "relocatable_release", "hello_server_new",
  +                              "ebin", "hello_server.appup"]),
  +    AppUpDest = filename:join([NewSystemPath, "lib", "hello_server-B", "ebin", "hello_server.appup"]),
  +    {ok, _} = file:copy(AppUpSrc, AppUpDest),
  +    %% Run command to create the relup file
  +    ok = systools:make_relup(
  +           filename:join([NewSystemPath, "releases", "B", "hello_server-B"]),
  +           [filename:join([NewSystemPath, "releases", "A", "hello_server-A"])],
  +           [filename:join([NewSystemPath, "releases", "A", "hello_server-A"])],
  +           [{outdir,filename:join([NewSystemPath, "releases","B"])},
  +            {path,[NewSystemPath ++ "/lib/hello_server-A/ebin/",
  +                   NewSystemPath ++ "/lib/hello_server-B/ebin/"]}]
  +          ),
  +    %% Install the B version
  +    {ok, "A", _} = erpc:call(NodeA, release_handler, install_release, ["B"]),
  +    %% Check that the releases info looks ok
  +    true = lists:any(fun({"hello_server", "B", _, current}) ->
  +                             true;
  +                        (_) ->
  +                             false
  +                     end,
  +                     erpc:call(NodeA, release_handler, which_releases, [])),
  +    %% Make sure the old module gets replaced
  +    ok = erpc:call(NodeA, app_callback_module, update, []),
  +    %% Check that the upgrade worked
  +    hej = erpc:call(NodeA, app_callback_module, get_response, []),
  +
  +    case os:type() of
  +        {win32, _} ->
  +            %% We cannot make release permanent on windows due to
  +            %% not having permissions to edit services.
  +            %% And symlinks to do not on windows, so we don't test
  +            %% anything more there.
  +            peer:stop(PeerA);
  +        _ ->
  +            move_system_unix(NodeA, PeerA, TestRootDir, ErtsBinDir, NewSystemPath)
  +
  +    end.
  +
  +move_system_unix(NodeA, PeerA, TestRootDir, ErtsBinDir, NewSystemPath) ->
  +    %% Make the upgrade permanent
  +    ok = erpc:call(NodeA, release_handler, make_permanent, ["B"]),
  +    %% Check that it still works
  +    hej = erpc:call(NodeA, app_callback_module, get_response, []),
  +    true = lists:any(fun({"hello_server", "B", _, permanent}) ->
  +                             true;
  +                        (_) ->
  +                             false
  +                     end,
  +                     erpc:call(NodeA, release_handler, which_releases, [])),
  +    ok = peer:stop(PeerA),
  +
       %% We will now move the install and check that everything still seems to be working fine
  -    file:set_cwd(TestRootDir),
  -    os:cmd("mv system_moved system_moved_again"),
       NewSystemPath2 = filename:join(TestRootDir, "system_moved_again"),
  -    file:set_cwd(NewSystemPath2),
  -    Node = start_remote_node("B"),
  -    try
  -        %% Change current working directory to something irrelevant
  -        ok = rpc:call(Node, file, set_cwd, ["/"]),
  -        {ok, "/"} = rpc:call(Node, file, get_cwd, []),
  -        %% Check that we are using version B
  -        hej = rpc:call(Node, app_callback_module, get_response, []),
  -        %% Downgrade to version A
  -        {ok, "A", _} = rpc:call(Node, release_handler, install_release, ["A"]),
  -        Releases3 = rpc:call(Node, release_handler, which_releases, []),
  -        true = lists:any(fun({"hello_server", "A", _, current}) ->
  -                                 true;
  -                            (_) ->
  -                                 false
  -                         end,
  -                         Releases3),
  -        %% Make sure that the module is reloaded
  -        ok = rpc:call(Node, app_callback_module, update, []),
  -        %% Make sure that we are on version A
  -        hello = rpc:call(Node, app_callback_module, get_response, []),
  -        %% Make the downgrade permanent
  -        ok = rpc:call(Node, release_handler, make_permanent, ["A"]),
  -        %% Test that remove release works
  -        ok = rpc:call(Node, release_handler, remove_release, ["B"]),
  -        %% B should not exist anymore
  -        Releases4 = rpc:call(Node, release_handler, which_releases, []),
  -        false = lists:any(fun({"hello_server", "B", _, _}) ->
  -                                  true;
  -                             (_) ->
  -                                  false
  -                          end,
  -                          Releases4),
  -        ok = rpc:call(Node, app_callback_module, update, []),
  -        %% We should still get hello
  -        hello = rpc:call(Node, app_callback_module, get_response, [])
  -    catch
  -        Class2:Reason2:Stacktrace2 ->
  -            erlang:raise(Class2, Reason2, Stacktrace2)
  -    after
  -        %% Try to make sure the node goes down even if we fail the test case
  -        (catch rpc:call(Node, erlang, halt, [])),
  -        file:set_cwd(OldCWD)
  -    end,
  -    ok.
  -
  -
  -start_remote_node(RelVsn) ->
  -    SystemErlPath = filename:join(["erts-" ++ find_vsn_app(erts), "bin", "erl"]),
  -    {ok, Host} = inet:gethostname(),
  -    Sname = "relocatable_node",
  -    Node = list_to_atom(lists:concat([Sname,"@",Host])),
  -    RemoteNodeCmd =
  -        lists:flatten(SystemErlPath ++
  -                          " -noshell -boot " ++
  -                          filename:join(["releases", RelVsn, "start"]) ++
  -                          " -name " ++
  -                          atom_to_list(Node) ++
  -                          " &"),
  -    os:cmd(RemoteNodeCmd),
  -    timer:sleep(500),
  -    (fun Repeat("ok", _) -> ok;
  -         Repeat(_, 20) -> erlang:error("Could not start node");
  -         Repeat(_, N) ->
  -             timer:sleep(500),
  -             Repeat((catch rpc:call(Node, erlang, atom_to_list, [ok])), N+1)
  -     end)((catch rpc:call(Node, erlang, atom_to_list, [ok])), 0),
  -    Node.
  +    ok = file:rename(NewSystemPath, NewSystemPath2),
  +
  +    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +    %% Create a symlink to moved system and test that if we set the path to
  +    %% contain the symlink it will work.
  +    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +    ok = file:make_symlink(
  +           filename:join([NewSystemPath2, ErtsBinDir, "erl"]),
  +           filename:join(TestRootDir, "erl")),
  +
  +    Name = peer:random_name(),
  +    LinkNode = list_to_atom(Name++"@"++lists:last(string:split(atom_to_list(node()),"@"))),
  +
  +    %% We cannot use ?CT_PEER here because it uses spawn_executable and that
  +    %% does not search the PATH for which program to run.
  +    Port = open_port(
  +             {spawn,"erl -sname " ++ Name ++ " -boot " ++
  +                  filename:join([NewSystemPath2, "releases", "B", "start"])},
  +             [{env,[{"PATH",TestRootDir ++ ":" ++ os:getenv("PATH")}]}]),
  +
  +    %% Wait for node to start
  +    receive _ -> ok end,
  +
  +    hej = erpc:call(LinkNode, app_callback_module, get_response, []),
  +
  +    true = catch port_close(Port),
  +    ct:log("~p",[(fun F() -> receive M -> [M | F()] after 0 -> [] end end)()]),
  +
  +    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +    %% Test that we can do a downgrade of the moved system
  +    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  +    {ok, PeerB, NodeB} = start_remote_node(NewSystemPath2, "B"),
  +
  +    %% Change current working directory to something irrelevant
  +    ok = erpc:call(NodeB, file, set_cwd, ["/"]),
  +    {ok, "/"} = erpc:call(NodeB, file, get_cwd, []),
  +    %% Check that we are using version B
  +    hej = erpc:call(NodeB, app_callback_module, get_response, []),
  +    %% Downgrade to version A
  +    {ok, "A", _} = erpc:call(NodeB, release_handler, install_release, ["A"]),
  +    true = lists:any(fun({"hello_server", "A", _, current}) ->
  +                             true;
  +                        (_) ->
  +                             false
  +                     end,
  +                     erpc:call(NodeB, release_handler, which_releases, [])),
  +    %% Make sure that the module is reloaded
  +    ok = erpc:call(NodeB, app_callback_module, update, []),
  +    %% Make sure that we are on version A
  +    hello = erpc:call(NodeB, app_callback_module, get_response, []),
  +    %% Make the downgrade permanent
  +    ok = erpc:call(NodeB, release_handler, make_permanent, ["A"]),
  +    %% Test that remove release works
  +    ok = erpc:call(NodeB, release_handler, remove_release, ["B"]),
  +    %% B should not exist anymore
  +    false = lists:any(fun({"hello_server", "B", _, _}) ->
  +                              true;
  +                         (_) ->
  +                              false
  +                      end,
  +                      erpc:call(NodeB, release_handler, which_releases, [])),
  +    ok = erpc:call(NodeB, app_callback_module, update, []),
  +    %% We should still get hello
  +    hello = erpc:call(NodeB, app_callback_module, get_response, []),
  +    ok = peer:stop(PeerB),
  +
  +    ok.
  +
  +start_remote_node(SystemPath, RelVsn) ->
  +    SystemErlPath = filename:join([SystemPath, "bin", "erl"]),
  +    ?CT_PEER(#{ exec => SystemErlPath,
  +                args => ["-boot",filename:join([SystemPath,"releases", RelVsn, "start"])]}).
   
   create_release_package(DataDir, SourceDir, RelVsn) ->
       ReleaseSource = filename:join(DataDir, "relocatable_release"),
  
positive.code:     [otp_9395_check_old_code,
       instructions, eval_appup, eval_appup_with_restart,
       install_release_syntax_check,
       otp_10463_upgrade_script_regexp, no_dot_erlang,
       {group, absolute}, {group, relative}].
  
  groups() ->
  
negative.code: 		true ->  [{group, release}];
  		false -> [no_run_erl]
  	    end,
      [target_system, target_system_unicode] ++ RunErlCases ++ cases().
  
  win32_cases() ->
      [{group,release} | cases()].
  