Need more detail about "sudo & chown"

how to achieve the following…?

  • create a new folder /var/mongodb/db/ and allow mongod to write files to this directory
    • create this directory with sudo, because /var is owned by root
    • use chown to change the owner of this directory to vagrant:vagrant

thanks in advance

do i need to specify “vagrant:vagrant” while changing the user, or simply “vagrant” is enough…?

i just googled it, and got to know, the following should be helpful in changing the user of the folder.
command executed:
/vagrant>sudo chown vagrant var (while i was in home dir)
/var>sudo chown vagrant mongodb (while cd - change dir to var)
/var/mongodb>sudo chown vagrant db (while cd - change dir to var/mongodb)

after doing the above, when i execute the mongod with the config file, i got the following error.

and please check the user access to the folder…


please help me out with this…
thanks in advance

This should help. (They asked for vagrant to be the owner and group of /var/mongodb/db)

https://ss64.com/osx/chown.html

Assign Ursula as the owner, and staff as the group for everything in the “tmp” folder

$ sudo chown -R Ursula:staff /Users/Shared/tmp/

try with

sudo chown vagrant:vagrant /var/mongodb/db

Hi Pawan,

it is in course-0 Lecture: Setting Up the Vagrant Environment and if you go to minute between 3.34 and 3.45 you will see provision-mongod file has this command already, just you have to change /data to /var/mongodb/db/ . Basically when you run “vagrant up --provision” command on your command prompt run provision-mongod file and what ever command inside this file. so this is the way create /data folder when you start up vagrant. so when you creating new folder like var, you can use sudo command like above.

I hope this help.

Hi Hakan_27844,

I’ve tried changing the default dbpath through the config(yaml) file like below.
image

but, when i tried to load this file by running the following command,
mongod -f /shared/config_file.yaml

i’ve got the following error


it’s the one which i’ve posted earlier.
the specific error is marked below.

i’m not sure where i was missing…
even i’ve tried googling and tried couple of ways, but nothing seems to be working.

Hi Pawan_16823,

After looking at the error, I will make sure the directory `/var/mongodb/db exists.

Try:

ls /var/mongodb/db

If it shows something like this:

ls: cannot access /var/mongodb/db: No such file or directory

Then, you need to create directory like:

mkdir /var/mongodb/db

Kanika

Well, that will only change /home/vagrant/var… which shouldn’t exist.

My advice to everybody use “ls -al” command to discover what directories and folders around ubuntu box and then you will figure out what to create… i hope this help.

1 Like

ACK.

Unfortunately the fine folks at MongoU are faced with the very real possibility that people taking these courses lack basic Windows and Linux experience. Not everybody coming here will know how to administer a server, let alone use the command line. So while I agree with you that most folks would benefit greatly from Linux-101, it’s an unfortunate reality that most folks haven’t or can’t tackle that just yet.

Of course, if anybody wants to invest the time to learn Linux basics -> https://itsfoss.com/free-linux-training-courses/

3 Likes

i think exact path is /./var/mongodb/db/

That is literally the same as /var/mongodb/db :slight_smile:

“.” in a Unix path means “this directory” and “/” at the very start means “start at the root directory”. So “/./var” is “var from the root dir”, which is “/var”.

Hello,

In case this may help anyone in the future…

We cannot create a new /var directory because it already exists.

Once you cd into the existing /var directory, you should be able to create the child directories /mongodb/db

I hope that this helps:-)

2 Likes

I don’t tend to use unix a lot, being from a windows background. So I hope this isn’t too much help. Delete if you feel it is. However if basic unix is required (An indication of age saying unix not linux :wink: ), maybe make it a prerequisite of the course, and point to a online resource you feel is appropriate.

  1. Make the directory mongodb/db using from with /var (so beforehand cd /var )

sudo mkdir -p mongodb/db

This creates the subdirectory mongodb and db in one pass.

  1. Change permissions so vagrant owns it, both as the owner and group. You should still be in /var

sudo chown -R vagrant:vagrant mongodb

The -R recursively applies those permissions to the directory mongodb and its subdirectory db .
Entering ls -l will confirm this.

6 Likes