You are not logged in.

#1 2021-03-15 18:59:11

mikethe1wheelnut
Member
Registered: 2021-03-12
Posts: 17

[SOLVED]How to cd into /root from / (root) in linux Live

..it may seem like there are a lot of questions in here, but I think they are essential to getting a grasp on the "problem", so please bear with me..  If nothing else, if the answer is "yes, you have understood the system correctly", then at least others following after me will be able to use it to check -their- understanding.

Part 1:

It is well documented (https://tldp.org/LDP/Linux-Filesystem-H … /root.html, http://www.linfo.org/slash_root.html#:~ … rectories....) that the root directory (/) is (now) distinct from the home directory of the root user.  It is less clear how to actually reach it.  Specifically, when booting into the live system from usb, you start out in ~.  You can cd to / (so what is ~ if it isn't root?  ..mostly off-topic..), but if you try to cd to /root, it won't work.  If you do ls, it'll show you the root directory in the list of directories.  But if you try to cd to it from ~ it won't work, and if you try to cd to it from / it'll actually go in the other direction, back to ~.

I'm asking this because I'm trying to track down solutions to other problems, and some of the instructions involve gaining access to this directory: https://wiki.archlinux.org/index.php/ke … ng_cmdline, but the question stands on it's own.

Part 2:

Further testing seems to reveal further complication.  I explored whether the behavior was the same when I chroot'ed into the new system from the live system.  It put me in /.  from there, ls shows me the expected,

bin, boot, dev, etc.

  Trying to cd into root from here, as before brings me back to ~.  when I ls from ~ this time though, (in the live system, ls from ~ gives nothing), I get

Desktop, Documents, Downloads, ...

  What I would expect from a users home folder. 

[cd / gets me back up (same as cd ../ apparently..) and I can then cd into home, and from there into any of the other users home directories.  So that part makes sense.]

Where it gets confusing is that.. say you start out in ~.  you've put in cd and it brought you to ~.  ls (not in linux live) tells you the directories are

Desktop, Documents..

there is no /.  now, cd into /.  in / you have

bin, boot, etc, and root

  you cd into root.  now instead of your being in /root, you're in ~.  ls from ~? 

Desktop, Documents, etc.

  From here, if you cd into / (not listed), you get back to /, as before. 

Part 3:

So, conclusion, this is a -circular- file structure.  And -that- is confusing.  (When you aren't expecting it).  I (and others?) was expecting a tree.  I thought there was a top (/), and branches all the way down to.. as far as you care to keep on defining sub-directories.  I thought it was linear.  But it isn't.  cd / gets you to /, but all four of cd, cd ~ , cd root and cd /root get you to ~.

Back in the Live system, it doesn't work the same way.  ls from ~, as observed above, gives nothing.  you can cd from there to /, which contains what you expect, but when you cd to root, while it brings you back to ~ (as expected), ls tells you there isn't anything there.  Previously, before I had done this comprehensive mapping for the sake of this question, I had grown frustrated that I couldn't get into /root.  Now my understanding is that I can get into /root perfectly fine, there just isn't anything there.  (Because I guess, for the Live system, nothing -needs- to be there..)  Except an invisible link to / that I can access through cd.

Now, back to hijacking the command line:  https://wiki.archlinux.org/index.php/ke … ng_cmdline:  I have to create the file /root/cmdline.  So what this will do is create a file -alongside- the folders Desktop, Downloads, etc, in the home directory of the root user.

So.. if my understanding is correct, all that needs to be done is to confirm that, and I'll mark this as solved. smile

Last edited by mikethe1wheelnut (2021-03-15 21:09:21)

Offline

#2 2021-03-15 19:15:04

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED]How to cd into /root from / (root) in linux Live

In Linux the word root has two different meanings - the root of the filesystem or the user called root.

/ means the root filesystem.

~ is an alias for the home directory of the current user.

When booting from the live USB you are logged in as the user root who's home directory is /root.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2021-03-15 19:31:41

mikethe1wheelnut
Member
Registered: 2021-03-12
Posts: 17

Re: [SOLVED]How to cd into /root from / (root) in linux Live

Slithery wrote:

In Linux the word root has two different meanings - the root of the filesystem or the user called root.

/ means the root filesystem.

~ is an alias for the home directory of the current user.

When booting from the live USB you are logged in as the user root who's home directory is /root.

..so it sounds like my understanding is correct smile

Offline

#4 2021-03-15 19:45:59

loqs
Member
Registered: 2014-03-06
Posts: 19,016

Re: [SOLVED]How to cd into /root from / (root) in linux Live

mikethe1wheelnut wrote:
Slithery wrote:

In Linux the word root has two different meanings - the root of the filesystem or the user called root.

/ means the root filesystem.

~ is an alias for the home directory of the current user.

When booting from the live USB you are logged in as the user root who's home directory is /root.

..so it sounds like my understanding is correct smile

Apart from this section.

mikethe1wheelnut wrote:

So, conclusion, this is a -circular- file structure.  And -that- is confusing.  (When you aren't expecting it).  I (and others?) was expecting a tree.  I thought there was a top (/), and branches all the way down to.. as far as you care to keep on defining sub-directories.  I thought it was linear.  But it isn't.  cd / gets you to /, but all four of cd, cd ~ , cd root and cd /root get you to ~.

You can create loops in a filesystem using links.  This is not what you are encountering with your use of cd.  The four invocations of cd all resulted in moving to the same directory see cd.1p, only cd root was following the filesystem's layout the other three invocations used absolute paths.
Edit:
You can use `pwd` to show the current working directory and unlike the output in the prompt does not use ~.

Last edited by loqs (2021-03-15 19:54:57)

Offline

#5 2021-03-15 21:08:44

mikethe1wheelnut
Member
Registered: 2021-03-12
Posts: 17

Re: [SOLVED]How to cd into /root from / (root) in linux Live

loqs wrote:

You can use `pwd` to show the current working directory and unlike the output in the prompt does not use ~.

Sweet!  Well, you're whole response is awesome :-)

Between the two of you, I'm satisfied :-)  ..and anybody else happening along has extra information they can use to continue their charge to full understanding, asking their own questions if need be. 

Marking this as solved smile

Last edited by mikethe1wheelnut (2021-03-15 21:09:40)

Offline

Board footer

Powered by FluxBB