LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   change permissions on subdirectory (https://www.linuxquestions.org/questions/slackware-14/change-permissions-on-subdirectory-4175668823/)

deretsigernu 02-01-2020 01:44 PM

change permissions on subdirectory
 
Hi,

My computer dual boots Slackware 14.2-64-current and Windows 10. Along with partitions for the two OSes, I have another partition that has the file system ntfs-3g. I use this to store data that are used in both OSes, such as data spreadsheets or GIS files.

I installed PostgreSQL-12.1 on Slackware and I am working with the post-installation set up. From the documentation, these are the main steps:
Code:

./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

I created a new directory on the data partition as
/fat-d/projects_and_data/data/linux/pgsql/data

For step 7, "chown postgres /usr/local/pgsql/data", I modified the command to
Code:

bash-5.0# chown postgres /fat-d/projects_and_data/data/linux/pgsql/data
but when I check the directory, the ownership doesn't change.

Code:

bash-5.0# ls -la /fat-d/projects_and_data/data/linux/pgsql/data
total 0
drwxrwxrwx 1 root root  0 Feb  1 11:23 .
drwxrwxrwx 1 root root 144 Feb  1 11:23 ..

I'm not sure what exactly is causing this problem. I suspect it has something to do with the configuration somewhere, but not sure of that. I was wondering if it has something to do with fstab? Here is my /etc/fstab:

Code:

/dev/sda7        swap            swap        defaults        0  0
/dev/sda5        /                ext4        defaults        1  1
/dev/sda2        /boot/efi        vfat        defaults        1  0
/dev/sda4        /fat-c          ntfs-3g    fmask=133,dmask=022 1  0
/dev/sda6        /fat-d          ntfs-3g    fmask=111,dmask=000 1  0
#/dev/cdrom      /mnt/cdrom      auto        noauto,owner,ro,comment=x-gvfs-show 0  0
/dev/fd0        /mnt/floppy      auto        noauto,owner    0  0
devpts          /dev/pts        devpts      gid=5,mode=620  0  0
proc            /proc            proc        defaults        0  0
tmpfs            /dev/shm        tmpfs      nosuid,nodev,noexec 0  0

That's just a guess though. How would I get the new directory I created for PostgreSQL to be owned by user postgres? I don't want to create the ...pgsql/data directory on the linux partition because that partition is pretty small and could fill up quickly with data files.

captain_sensible 02-01-2020 03:05 PM

i'm slightly surprised that you would approach installing any software the "old fashioned way" .

Slackbuilds.org is usually my first port of call to read up on packages dependencies . So example

You need a "postgres" user and group prior to building postgresql.
Something like this will suffice for most systems:
groupadd -g 209 postgres
useradd -u 209 -g 209 -d /var/lib/pgsql postgres

but that package is for stable and your on current; so i am . I use slpkg for "diligent" use to install .

bash-5.0# slpkg -F postgresql

Packages with name matching [ postgresql ]

+==============================================================================
| Repository Package Size
+==============================================================================
sbo postgresql-10.10 0 K
conrad postgresql-12.1-x86_64-2cf.txz 9240 K

deretsigernu 02-01-2020 04:10 PM

I tried the sbopkg repository. It supplies 10.x and I keep getting an error message. Like

Code:

psql: could not connect to server: No such file or directoryIs the server running locally and acceptingconnections on Unix domain socket "/tmp/.s.PGSQL.5432"?
or

Code:

postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

I ran
Code:

groupadd -g 209 postgres
useradd -u 209 -g 209 -d /var/lib/pgsql postgres

as instructed prior to installation and it seems like certain directories or other configurations were missing anyway. I even ran the installation a 2nd time through sbopkg. I was getting tired of trying to hunt down them down, so I figured I'd just get the app straightaway.

An Infamous Historian 02-01-2020 08:59 PM

I don't think that's the issue re: changing permissions.

Is /fat-d your NTFS partition? How have you mounted it? NTFS partitions CAN be used w/Unix permissions, although it requires a specific mount option that iirc may break Windows compatibility (I may be wrong about that, and even if I'm right there may be a new way that doesn't break it--it's been a while).

captain_sensible 02-02-2020 09:34 AM

conrad repo has the x12 conrad postgresql-12.1-x86_64-2cf.txz 9240 K

ehartman 02-02-2020 04:01 PM

Quote:

Originally Posted by deretsigernu (Post 6085234)
How would I get the new directory I created for PostgreSQL to be owned by user postgres?.

On a ntfs partition: you do not. The ntfs file system doesn't have the concept of "file owner", so Linux handles it with all of the files (and directories) having the same owner. It is just a fake ID as no owner can be stored and the owner/group is specified by the mounting process.
Real file owners (and groups) are only supported on Linux(Unix) file systems.

An Infamous Historian 02-02-2020 04:55 PM

Quote:

Originally Posted by ehartman (Post 6085532)
On a ntfs partition: you do not. The ntfs file system doesn't have the concept of "file owner", so Linux handles it with all of the files (and directories) having the same owner. It is just a fake ID as no owner can be stored and the owner/group is specified by the mounting process.
Real file owners (and groups) are only supported on Linux(Unix) file systems.

As I explained above, there is a way to do it, by mounting with the "permissions" option. My understanding is that this might break Windows compatibility, but it can be done--and there might be another, compatible way to do it too.

vtel57 02-02-2020 05:06 PM

Everyone else here is helping the OP, so I'd just like to inject one thing. If you're wanting to have partitions with common access from Win and Lin, then you should always format these partitions as FAT. Makes life much easier. A copy of my /etc/fstab with a win-lin common partition (vfat):

Code:

/dev/sda4        swap            swap        defaults        0  0
/dev/sdb4        swap            swap        defaults        0  0
/dev/sda1        /                ext4        defaults        1  1
/dev/sda2        /home            ext4        defaults        1  2
/dev/sda3        /home/vtel57/vtel57_storage ext4        defaults        1  2
/dev/sdc2        /home/vtel57/vtel57_common vfat        fmask=111,dmask=000 1  0
#/dev/cdrom      /mnt/cdrom      auto        noauto,owner,ro,comment=x-gvfs-show 0  0
/dev/fd0        /mnt/floppy      auto        noauto,owner    0  0
/dev/sdj4        /mnt/zip          vfat              noauto,rw,user,nosuid,sync,mode=0777       
devpts          /dev/pts        devpts      gid=5,mode=620  0  0
proc            /proc            proc        defaults        0  0
tmpfs            /dev/shm        tmpfs      defaults        0  0

Anyway, carry on...

deretsigernu 02-02-2020 07:46 PM

@captain sensible
Thanks for the suggestion. I'll look at adding the repo.

@ehartman
Thank you for answering my specific question. I realize that An Infamous Historian's answer contradicts your answer and I suppose I can try to look into that answer, but if doing as suggested messes up the Windows access to the partition, it kind of defeats the purpose of being able to access the partition from either OS.

@vtel57
I used VFAT on one of my earlier laptops that was dual boot. I don't remember what made me switch to NTFS. I think something at the time (years ago now) indicated that NTFS was more reliable. Maybe faster? That might have been when I was using Red Hat as my linux partition. Now, I don't know the exact advantages and disadvantages of using VFAT or NTFS, but so far, NTFS has worked fine on my last 2 dual boots. If VFAT lets me have the mixed linux permissions more easily though, it might be a better option for me. That's going to take some time to figure out. Thanks for mentioning it and giving me some food for thought.

vtel57 02-02-2020 08:10 PM

Well, a FAT32 partition definitely has its drawbacks (file size limits, etc.), but I've always found it easier to work with in Linux.

Anyway, glad you got some help here. Hopefully, you'll get your system all squared away as you need it to be.

Cheers!

~Eric

montagdude 02-05-2020 09:25 PM

Quote:

Originally Posted by deretsigernu (Post 6085262)
I tried the sbopkg repository. It supplies 10.x and I keep getting an error message. Like

Code:

psql: could not connect to server: No such file or directoryIs the server running locally and acceptingconnections on Unix domain socket "/tmp/.s.PGSQL.5432"?
or

Code:

postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

I ran
Code:

groupadd -g 209 postgres
useradd -u 209 -g 209 -d /var/lib/pgsql postgres

as instructed prior to installation and it seems like certain directories or other configurations were missing anyway. I even ran the installation a 2nd time through sbopkg. I was getting tired of trying to hunt down them down, so I figured I'd just get the app straightaway.

When using the build from SBo, you can start it by doing:

Code:

chmod +x /etc/rc.d/rc.postgresql
/etc/rc.d/rc.postgresql start

The first time you run it, you may get an error like this:
Quote:

You should initialize the PostgreSQL database at location /var/lib/pgsql/10.10/data
e.g. su postgres -c "initdb -D /var/lib/pgsql/10.10/data --locale=en_US.UTF-8 -A md5 -W"
Just follow that instruction, start it again, and you should be good to go.

enorbet 02-06-2020 03:19 AM

Maybe I'm just being dense but in some 20 years of using Slackware as my main I've never had difficulty with NTFS in Linux or in Windows, though I rarely ever even boot an ancient Win7 partition. Point being I find no compulsion or value in reverting to FAT of any kind though the new exFat may be a decent change... I wouldn't know.

All I have ever done is use the fmask and dmask entries just as vtel57 does but on NTFS like this

Code:

###excerpt from /etc/fstab###
/dev/sdb2        /mnt/Win7-64        ntfs-3g    fmask=111,dmask=000    1  0
/dev/sdb5        /mnt/ntfs5          ntfs-3g    fmask=111,dmask=000    1  0

... works perfectly

##NOTE : As applies to installation, although I sometimes just build from source and don't bother with a Slackbuild when no new dependencies are involved (not that Slackbuilds are any bother at all... prolly just habit) still I avoid "make install" simply because it makes uninstall difficult and lacks support data. I either make my own slackbuild or at the very least just "makepkg" so it appears in /var/log/packages/ and is easily uninstalled or upgraded....

... and speaking of which, why in Hell have some devs in other "more mainstream" distros chosen to cease using the oh so obvious and useful /var/log/packages? Do these people have nothing better to do than make Linux unnecessarily complex?

deretsigernu 02-10-2020 09:12 AM

@enorbet, do you mean that you have an NTFS partition that has multiple ownerships on it, like what I'm trying to do? My fmask and dmask settings are the same as yours, but I can't create a folder while I'm logged into Slackware that is owned by anyone but root.

Regarding package installation, your description is helpful. I did not know about makepkg or skipping make install. To be clear, if I skip the "make install", I have to either make a custom slackpkg or or use makepkg to finish the install?

mumahendras3 02-16-2020 02:29 PM

Hi @deretsigernu,

In NTFS-3G FAQ: https://www.tuxera.com/community/ntf...q/#permissions

Quote:

Why have chmod and chown no effect?

By default files on NTFS are owned by root with full access to everyone. To get standard per-file protection you should mount with the “permissions” option. Moreover, if you want the permissions to be interoperable with a specific Windows configuration, you have to map the users.
I haven't tried that myself though, maybe worth to try.

Cheers

deretsigernu 02-17-2020 07:25 PM

@mumahendras3, that link provides a lot of useful information. I will read the material and try to make sense of it. Thanks for pointing to the documentation. I didn't think it was an issue with NTFS-3G, but mount, so getting through NTFS-3G may do the trick for me.

deretsigernu 05-16-2020 06:51 PM

I did read up some on NTFS-3G. Looked at most of the software author's site. I tried to get on the forum to ask my question, but like this LQ user indicated, I couldn't find how to register.

As mumahendras3 pointed out, sounds like I need to map the users, Windows and Slackware, on /fat-d. This gets to my question. If I do the mapping (haven't actually tried it yet), do I need to then designate each file with an user/owner? It's unclear to me how NTFS-3G will know which user has permissions on which file. There are thousands of files on that drive and I'm fine with leaving everything as is. I'd rather not have to map users to all the files. I just need to get that one data directory I mentioned above mapped, I guess, to the Slackware postgres user, so that PostgreSQL will function with that directory.

deretsigernu 07-24-2020 03:34 PM

I finally got my partition configured. Using the definitions found here, I didn't map the users. Instead I changed my fstab file. The line for my "data" partition in fstab, called "/fat-d", was originally:

Quote:

UUID=82CC1BFECC1BEAE5 /fat-d ntfs-3g fmask=111,dmask=000 1 0
I changed "fmask=111,dmask=000" to "permissions". Now the ownership of a directory file depends on the user that created that file.

For example, if I

Quote:

bash-5.0$ mkdir /fat-d/data/linux/pgsql (as the user postgres)
I get
Quote:

bash-5.0$ ls -la /fat-d/projects_and_data/data/linux/pgsql
total 4
drwxrwxrwx 1 root root 0 Jul 19 12:15 .
drwxrwxrwx 1 root root 0 Feb 1 14:23 ..
drwx------ 1 postgres users 4096 Jul 24 14:53 data
I needed a couple more steps to configure postrgresql and now I can use psql with the data directory I created for the app.

I don't know if it's the most secure set up ever. I've got back-ups and nothing sensitive here. Anyway, I'm glad I got this pulled off.


All times are GMT -5. The time now is 07:13 AM.