Pkg: invalid rootdir

Hi everyone !
I've picked up strange behavior on newly installed FreeBSD.
Downloaded and installed latest distro, FreeBSD-12.1-RELEASE-amd64-disc1.iso, pretty much with default settings since it's just test environment
Then I've tried to install bash, since I love it:
Code:
root@Test1:~ # pkg -r install bash
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly, please wait ...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301 ... done
Installing pkg-1.14.6...
Extracting pkg-1.14.6: 100%
pkg: Invalid rootdir: No such file or directory
Is there some bug or what am I doing wrong ? I've tried two times on different servers, same result
 
Why do you specify the -r (root dir) switch without a directory?
Better remove it from the command line:
pkg install bash

Oh and by the way: Never ever set bash as the roots shell, only use it for regular users. Otherwise bad things will happen.
You can give the toor user (read backwards) the bash(1) shell. For ordinary users, I'd say it does not hurt. Worst that can happen is that the user can not log in; then you can su username from root and reset the shell to default. But to be safe, you can configure the graphical terminal app of your choice to use it, and stay with (t)csh(1) or sh(1) as the login shell.
 
  • Like
Reactions: a6h
Personally I never change the shell of any system user, including root and toor. You should never log in as root anyway (or any other user with UID 0), so the login shell of those users doesn’t matter. It doesn’t even matter for single-user mode because the init(8) process asks you for the shell to execute.

If you repeatedly have tasks that require elevated privileges, install security/sudo or security/super. I prefer the latter because I think the configuration syntax is clearer and less error-prone, and therefore more secure. But YMMV, of course.

And if you really need to execute shell commands interactively with root privileges, my recommendation is to use su -m. That will open a root shell using your own login shell and environment, ignoring root’s login shell. This also means that your usual aliases, shell functions etc. are available in that root shell. To take full advantage of that, you might want to make some changes to your shell’s startup script (.profile, .zshrc or similar, depending on the shell). For example, you can set the shell prompt differently or use a different history file. You can use conditional constructs like if (( EUID == 0 )); then ...; else ...; fi (this syntax works with bash and zsh; tcsh looks a little different).
 
First update: freebsd-update fetch install and pkg update -f , then install.

On shell: there's nothing wrong (not completely, of course!) with changing shell of the root, as long as they reside on /bin. Cating /etc/shells will show you that, there's not much to choose from. /bin/sh, /bin/csh, and /bin/tcsh. Therefore we reach to same old conclusion: don't change the root's shell.

In the past my shell strategy was:
/bin/sh for root (safeguard)
/usr/local/bin/zsh for toor (often)
/usr/local/bin/zsh for Normal user (regular)
/bin/sh for scripting (default)

But now, I believe in unifying principles of shell, aka using POSIX sh everywhere. Hence my current setup is like this:
chsh -s /usr/sbin/nologin toor
/bin/sh for scripting, root and Normal user (both set -o vi)
 
Back
Top