I have an USB thumb stick with the following partition scheme:

  sdb1  -> root partition '/'
  sdb2  -> /home partition 

If I boot from a live CD, or just from my current Ubuntu OS located on my computer's hardware, I am able to chroot this way:

mount /dev/sdb1 /mnt
mount /dev/sdb2 /mnt/home
chroot /mnt /bin/bash

In this instance, my prompt is something like [root@archiso]. The thing is I would like to log in my user account which is in /mnt/home/me, but I don't know how to do it? A further goal would be to launch X (and any dektop manager) from this user session.

So the questions that I need to be addressed are the following:

1) How do I log into my user session once I am chrooted?

2) Once I am logged in, would it be possible to start X startx, even if I am initially logged in my computer Ubunu OS, with a gnome session already running?

  • 1
    I don't know the answer to (2) but the answer to (1) is... same way you would usually "become" your user if you were logged in as root: su - yourusername. – Celada May 2 '15 at 1:17
  • su user_name works fine :) – kaligne May 2 '15 at 9:23
  • 1
    Well, su user_name is similar, but if you really want to log into your user as you requested then it's su - user_name you want. – Celada May 2 '15 at 12:00
  1. Do the chroot, as described in the question, and then do su - fred (or whatever your name is) or exec su - fred.
  2. Do chroot /mnt /bin/su - fred, so that the su will be the first thing that runs in the chroot environment.

Note that both of the above assume that your fred user is defined in /mnt/etc/passwd.


  1. Do chroot --userspec=fred:bedrock --groups=group1,group2 /mnt /bin/bash, to set your user identity from the inception of the chroot. The chroot invocation manual says,

    The user and group name look-up performed by the --userspec and --groups options, is done both outside and inside the chroot, with successful look-ups inside the chroot taking precedence.

    Consider adding -l (or --login) to tell bash to act as if it had been invoked as a login shell; i.e., to tell it to read /etc/profile and ~/.bash_profile, etc.

  2. The question asks, “How do I log into my user session once I am chrooted?”  Quite possibly the literal answer, chroot /mnt /bin/login, would work.  If this works, it would be the most like an ordinary login, in that it would ask for a user name and a password.  It is (probably) the only answer (of these four, anyway) that would cause the who command in the chroot environment to report your user name (and time of login, etc.) and might be the best bet to use some of the more esoteric features of the environment.  (I’m thinking [speculating] about cron /crontab / at, the passwd command, file system quotas, the accounting system, etc.  I don’t know whether or why these, or any other software, might not be satisfied with just looking at your real UID.)  Of course this, like the first two answers, would operate on users and passwords defined in the chrooted environment.

    This might not work. I vaguely seem to recall something about some versions of login detecting that it is being run in a non-standard way (like this) and refusing to play along.  But I can’t recall specifics and I can’t find anything in two minutes’ worth of searching.

  • It works, however I am never asked to enter any password, neither the root's nor the user's. Isn't that a terrible security flaw? – kaligne May 2 '15 at 14:21
  • You're already root (superuser) when you run the mount and chroot commands, aren't you?  Root is all-powerful; it can do anything, including access any file in any way (with a few special cases).  So letting root change to a less privileged user is not a security problem. – G-Man Says 'Reinstate Monica' May 2 '15 at 15:07
  • So one has just to boot from a live cd, the live-root has more power than any partition's root.. I wont start a debate on that matter but one can see pros regarding usefulness, and cons for security. Or am I missing something here? – kaligne May 2 '15 at 15:38
  • @user3298319: I don't know about root privilege from a Live CD having more power than an ordinary root login (or su) from the installed operating system.  But it has been widely known for years that physical access to a computer is equivalent to complete and absolute access — see Law 3 here (and millions of other places). – G-Man Says 'Reinstate Monica' May 2 '15 at 15:55
  • @user3298319: I added a fourth answer, and an additional consideration paragraph to answer #3. – G-Man Says 'Reinstate Monica' May 2 '15 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.