Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git on SD Card: "insufficient permission for adding an object" #5179

Open
NicoJG opened this issue May 7, 2020 · 6 comments
Open

git on SD Card: "insufficient permission for adding an object" #5179

NicoJG opened this issue May 7, 2020 · 6 comments

Comments

@NicoJG
Copy link

NicoJG commented May 7, 2020

Windows build number: Microsoft Windows [Version 10.0.18363.778]

I'm trying to get Git working on my WSL, but I always get the error

error: insufficient permission for adding an object to repository database ....../.git/objects

I'm working on a Surface Pro 5 in Windows Subsystem for Linux with Ubuntu.
Everything is working fine if I'm working on the internal drive.
The problem starts when I want to work on my micro SD Card.
First it wasn't mounted automatically.
I fixed that by editing the /etc/fstab file:

E:\ /mnt/e drvfs defaults,rw,exec,uid=nico,gid=nico 0 0

and ls -alR shows that permissions should be rw for all users and all files on my SD Card.

I tried git add on an existing repository on this SD Card and it didn't work.
I noticed that it created a tmp file in '.git/objects/54/' which had no write permissions every time I tried it.

Then I tried to clone a Test Repository but it only created the folder for a splitsec and gave me the same error. It is working though on my normal drive C: but not on my SD Card. Even if I add sudo to the command.

nico@DESKTOP-639MEJ9:/mnt/e$ git clone https://github.com/NicoJG/TestGit.git
Cloning into 'TestGit'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
error: insufficient permission for adding an object to repository database /mnt/e/TestGit/.git/objects
fatal: failed to write object
fatal: unpack-objects failed

Somehow git isn't working properly with the permissions in the WSL.
I already tried:

sudo chmod -R ug+rw *
sudo chwn -R nico:nico *

and reinstalling git.

Has anyone any idea how to fix it?

Here is also the output of mount:

nico@DESKTOP-639MEJ9:/mnt/e/$ mount
rootfs on / type lxfs (rw,noatime)
none on /dev type tmpfs (rw,noatime,mode=755)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,gid=5,mode=620)
none on /run type tmpfs (rw,nosuid,noexec,noatime,mode=755)
none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,noatime)
none on /run/shm type tmpfs (rw,nosuid,nodev,noatime)
none on /run/user type tmpfs (rw,nosuid,nodev,noexec,noatime,mode=755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)
cgroup on /sys/fs/cgroup type tmpfs (rw,relatime,mode=755)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,relatime,devices)
E:\ on /mnt/e type drvfs (rw,relatime,uid=1000,gid=1000,case=off)
C:\ on /windir/c type drvfs (rw,noatime,uid=1000,gid=1000,umask=22,fmask=11,metadata,case=off)

I only know what C: (my main drive) and E: (my SD Card) are. The rest seems to be WSL specific I think.

@siphayne
Copy link

I have the same issue with network drives using drvfs to mount.

Is this a problem in WSL 2? I am limited to WSL 1 by Windows versions.

@TobiasDeBruijn
Copy link

Can confirm that this is still a problem in WSL2

@igortas
Copy link

igortas commented Mar 22, 2021

I had issues with executing git commands from VS Code, so this two commands help me. Executed inside the WSL ubuntu

chmod -R g+rws .git/
chmod -R 777 .git/

@jauyzed
Copy link

jauyzed commented Sep 7, 2021

Seeing this issue on WSL1/UBUNTU20.04. The write bit is checked on windows-security and drive is mounted on linux with metadata option(uid,gid,umask,fmask) by giving full directory and file permission on ubuntu 20.04. Git on linux cannot write to a windows NTFS directory by a local ubuntu user. The local ubuntu user owns this directory/drvfs has permission on directory and files.
Following this article: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/
Error:

remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Total 6 (delta 2), reused 2 (delta 2), pack-reused 4
error: insufficient permission for adding an object to repository database .git/objects
fatal: failed to write object
fatal: unpack-objects failed

@GurovSD
Copy link

GurovSD commented Nov 25, 2021

For me the issue was due to strangely changed ownership to root in some of the folders inside .git/objects
I've worked around this with ownership change to the user you've created on WSL setup
On error you should recieve something like this error: insufficient permission for adding an object to repository database .git/objects

Try do the following:

  1. cd to the .git folder on your WSL with root access
  2. enter command # chown -R username:username objects
  3. now all your commit and etc. options should work properly

P.S. Most of the mailfunction i've met in WSL to Windows interaction so far was this ownership issue

@MacroUniverse
Copy link

MacroUniverse commented Jun 12, 2023

None of the above worked for me, I'm using git with WSL1 on a mounted exFat drive, all modes are 777, and owned by current user.
I can create, read, write, delete any file on this drive, but git still gives me that error.
To make sure I can actually write to those file, I even did mv .git .git1 && cp -r .git1 .git with no problem, but git still gives me that error.

Then I ran git gc, it gives me

fatal: Unable to create temporary file '/mnt/e/MacroUniverse/research-Uwe/.git/objects/pack/tmp_pack_XXXXXX': Permission denied

Then I cd .git/objects/pack/; ls -l, it gives me

total 818688
-rwxrwxrwx 1 addis root     24424 Jun 12 00:52 pack-7792ab77d4098f6bd81ab772c5f111b5490848cd.idx
-rwxrwxrwx 1 addis root 523313682 Jun 12 00:52 pack-7792ab77d4098f6bd81ab772c5f111b5490848cd.pack
-rwxrwxrwx 1 addis root     11740 Jun 12 00:52 pack-9a5ad7ebce5a9a0440fa92cb3c54be23f67520c4.idx
-rwxrwxrwx 1 addis root 314029998 Jun 12 00:53 pack-9a5ad7ebce5a9a0440fa92cb3c54be23f67520c4.pack
-rwxrwxrwx 1 addis root         4 Jun 12 00:54 tmp_pack_1vBMl9
-r-xr-xr-x 1 addis root         0 Jun 12 00:55 tmp_pack_5niyVb
-rwxrwxrwx 1 addis root         0 Jun 12 00:53 tmp_pack_Dteyfa
-r-xr-xr-x 1 addis root         0 Jun 12 00:54 tmp_pack_PMftQU
-r-xr-xr-x 1 addis root         0 Jun 12 00:55 tmp_pack_VyMjMb
-rwxrwxrwx 1 addis root         0 Jun 12 00:54 tmp_pack_WR8z8b
-rwxrwxrwx 1 addis root         0 Jun 12 00:54 tmp_pack_mhRbYb
-r-xr-xr-x 1 addis root         0 Jun 12 00:54 tmp_pack_pNmBAU

So it seems that I've found the problem:

the files that git created is missing the w permission to its owner!

I can manually change the permission each time the error happens, but as long as git is creating new files, there will be permission errors.

Note that this happens in all my git repos in mounted exFAT drives, but if I copy those repos to my C drive, then there is no error.

I even wrote a loop...

for ((i=0;i<=100;++i)); do chmod 777 -R .git/objects/; git add .; done

Then .git/objects is filled with hundreds of temporary files.... and still not working.

I wonder if things will improve if I use NTFS as the filesystem for external drive. Unfortunately, exFAT is almost impossible to shrink, and I have so much stuff in it. If anyone find out, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants