1

I ran scalpel to recover files. The input disk is a copy of a failing Windows disk I made using ddrescue. The output directory (from scalpel) is on an exfat partition on my Linux disk. I used exfat because Windows can see and read that partition - and those are from Windows.

I can't change the ownership of the files. They are owned by root.

For example, in the directory /media/me/restored/output/jpg-1-0
-rwxrwxrwx 1 root root 2983 Dec 29 23:14 00003483.jpg

$sudo chown me 00003483.jpg
chown: changing ownership of '00003483.jpg': Operation not permitted

$sudo chattr -i 00003483.jpg
chattr: Function not implemented while reading flags on 00003483.jpg

I can't change the ownership of the directory either.

I also tried this as sudo su -

I can open a recovered .jpg file with eog (command line - image viewer), but I can't open the files with Kria (a linux image editor, GUI).

Why don't the websites on scalpel tell you how to change the file permissions? Is the problem an incompatibility with exfat?

Thanks for any help.

UPDATE

Unmounting the partition, changing the ownership of the "restored" directory to my userid, and then running sudo mount -o rw,user,uid=1000,dmask=007,fmask=117 /dev/sdb4 /media/me/restored doesn't work. The "restored" directory is now owned by root again, and I get the exact same results trying the steps listed above.

UPDATE - adding debug information

lsblk -f


sdb                                                               
├─sdb1 vfat                  xxxx-xxxx                            /boot/efi
├─sdb2 ext4                  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /
├─sdb3 swap                  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [SWAP]
└─sdb4 exfat      SSD-D      xxxx-xxxx                            /media/me/rest  

UPDATE

Regarding the accepted answer, this problem was fixed with the mount command given above under the first update, and something else - exactly what I don't know. When I did that the first time, the ownership of the files was still root. The mount command is identical, as I copied it from the Terminal to here. All the recovered files are now owned by me (not root).

2
  • You can't change ownership of individual files (or directories). The ownerhip and permissions in Microsoft file systems (exFAT, Fat32 and NTFS) is set when mounted, and the only way to change it (for Linux) is to remount the file system (or unmount and mount again). See details at this link. – sudodus Dec 30 '19 at 6:09
  • @sudodus Your comment can as such be posted as the answer to this question. – vanadium Dec 30 '19 at 8:42
3

Original answer

You can't change ownership of individual files (or directories). The ownerhip and permissions in Microsoft file systems (exFAT, Fat32 and NTFS) are set when mounted, and the only way to change it (for Linux) is to remount the file system (or unmount and mount again).

See details at this link.

Edit after feedback

Output fron your computer:

lsblk -f

loop0                                                             
└─cryptswap1
       swap                  cbxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [SWAP]
sda    isw_raid_m                                                 
├─sda1 vfat       SYSTEM_DRV 90xx-xxxx                            
├─sda2 isw_raid_m                                                 
├─sda3 ntfs       Windows    E2xxxxxxxxxxxxxx                     /media/me/Wind
├─sda4 exfat      Restored   B4xx-xxxx                            /media/me/Rest
└─sda5 ntfs       WINRE_DRV  B2xxxxxxxxxxxxxx                     
sdb                                                               
├─sdb1 vfat                  A3xx-xxxx                            /boot/efi
├─sdb2 ext4                  3bxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /
├─sdb3 swap                  3cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx [SWAP]
└─sdb4 exfat      SSD-D      4Cxx-xxxx                            /media/me/rest
sdc                                                               
├─sdc1 vfat       ESP        A2xx-xxxx                            
├─sdc2 vfat       DIAGS      9Exx-xxxx                            
├─sdc3 ntfs       WINRETOOLS 72xxxxxxxxxxxxxx                     
├─sdc4 ntfs       OS         92xxxxxxxxxxxxxx                     
└─sdc5

cat /etc/mtab  # edited to focus on the relevant lines

/dev/sdb4 /media/me/restored fuseblk rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0

You have not changed the user id (0 <---> root) of the exfat partition on the drive with the running operating system

/dev/sdb2 / ext4 rw,relatime,errors=remount-ro,stripe=256 0 0
/dev/sdb1 /boot/efi vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0

For comparison, see the following output from my computer

sudodus@bionic64 ~ $ lsblk -f /dev/sdc
sdc         iso9660 Xubuntu Core 19.10 - amd64 2019-10-17-15-54-31-00               
├─sdc1      iso9660 Xubuntu Core 19.10 - amd64 2019-10-17-15-54-31-00               /media/sudodus/Xubuntu Core 19.10 - amd64
├─sdc2      vfat                               866D-0A62                            
└─sdc3      exfat   USBDATA                    5673-C08D                            /media/sudodus/USBDATA

My exfat file system is in /dev/sdc3, and I inspect the permissions,

sudodus@bionic64 ~ $ grep 'sdc3' /etc/mtab
/dev/sdc3 /media/sudodus/USBDATA fuseblk rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0

unmount the partition,

sudodus@bionic64 ~ $ sudo umount /dev/sdc3
[sudo] lösenord för sudodus: 

mount the partition according to the instructions in the linked answer (modified for the actual device /dev/sdc3.

sudodus@bionic64 ~ $ sudo mount -o rw,user,uid=1000,dmask=007,fmask=117 /dev/sdc3 /mnt/sd1
FUSE exfat 1.2.8

check the ownership (yes it is me) and the permissions with ls -l

sudodus@bionic64 ~ $ sudo ls -l /mnt/sd1
totalt 128
-rw-rw---- 1 sudodus root 29 dec 29 17:49 hej.txt

make a subdirectory

sudodus@bionic64 ~ $ mkdir /mnt/sd1/subdir

create a file (as the normal user),

sudodus@bionic64 ~ $ echo "Hello World" > /mnt/sd1/hello.txt

finally verify that it worked and check the ownership and permissions

sudodus@bionic64 ~ $ sudo ls -l /mnt/sd1
totalt 384
-rw-rw---- 1 sudodus root     29 dec 29 17:49 hej.txt
-rw-rw---- 1 sudodus root     12 dec 30 15:56 hello.txt
drwxrwx--- 1 sudodus root 131072 dec 30 15:54 subdir
sudodus@bionic64 ~ $ 

Suggested command line for your /dev/sdb4 with exfat

I assume that your user ID is 1000 (the first user ID created),

check with

grep "^$USER" /etc/group

and modify uid=1000 if necessary.

sudo umount /dev/sdb4
sudo mkdir /mnt/sd4   # create mount point (only once)
sudo mount -o rw,user,uid=1000,dmask=007,fmask=117 /dev/sdb4 /mnt/sd4

Edit 2

If you have problems, you may need current versions of the exfat tools,

sudo apt update
sudo apt install exfat-utils exfat-fuse

Edit 3

You may want to mount your exfat partition automatically at boot. In that case I suggest the following lines in your file /etc/fstab,

# partition with exfat file system
UUID=4Cxx-xxxx  /mnt/sd4  exfat  defaults,rw,user,uid=1000,dmask=007,fmask=117  0  0

Modify UUID=4Cxx-xxxx to match the actual UUID of the file system.

See man fstab for a detailed description of each of the six fields.

10
  • I will try this in a few hours, and I'll accept the answer if it works. Thanks. – JasonF4 Dec 30 '19 at 11:26
  • I ran: sudo mount -o rw,user,uid=1000,dmask=007,fmask=117 /dev/sdb4 /media/me/restored The files still have the same ownership, and I am getting the same errors trying to modify the directories and files. – JasonF4 Dec 30 '19 at 12:20
  • When I umount the partition, change the ownership of the "restored" directory to me, and remount the partition with the above command, the ownership of the "restored" directory is set back to root. – JasonF4 Dec 30 '19 at 12:37
  • @JasonF4, Plug in the USB drive and mount it. Then please run the following command lines and edit the original question to show the output. Indent each line with 4 space characters to render the output as 'code'. Then I will try to help according to those details: sudo lsblk -f and cat /etc/mtab – sudodus Dec 30 '19 at 13:07
  • I can't unplug the USB drive. It's an SSD that Linux is running on. The "restored" partition is on this drive. I will add the output. – JasonF4 Dec 30 '19 at 13:10

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.