0

About a month ago I have run some regular updates on my Kubuntu 16.10 machine (unfortunately I can't remember the names of the packages). Now, a month later, I tried to write some data on my USB stick and it suddenly doesn't work.

The USB disk is recognized and I am able to connect it simply using the GUI, for example by clicking the "connect drive" icon in Dolphin or Konqueror. I am able to read data from the USB stick, but when I try to copy a file to the stick, i get following errors (waran is my username, A874-2FAD is the name of the USB stick):

Konqueror:

Access denied. Could not write to '/media/waran/A874-2FAD'

Copying using command line (cp testfile.jpg /media/waran/A874-2FAD/):

cp: cannot create regular file '/media/waran/A874-2FAD/testfile.jpg': Permission denied

I have tried it (unsuccessfully) with 4 different USB sticks, 2 SD cards (directly through the card reader on my notebook or using an external card reader) and a CF card (using an external card reader). I have dual boot on this computer, writing to sticks from Windows 10 worked just fine. If it helps narrowing the problem, I am able to print from Kubuntu using an USB cable.

Also I noticed, that I have some new folders in the /media directory. Previously /media/ contained one folder called waran/, in this folder were only the currently connected USBs.

Now it looks like this (ls -aRl):

.:
total 44
drwxr-xr-x  11 root  root  4096 Oct 22 20:36 .
drwxr-xr-x  25 root  root  4096 Dec 20 21:47 ..
lrwxrwxrwx   1 root  root    45 Oct 15 13:46 .directory -> /etc/kubuntu-default-settings/directory-media
lrwxrwxrwx   1 root  root    42 Oct 15 13:46 .hidden -> /etc/kubuntu-default-settings/hidden-media
lrwxrwxrwx   1 root  root     4 Oct 22 20:36 usb -> usb0
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb0
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb1
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb2
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb3
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb4
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb5
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb6
drwxr-xr-x   2 root  root  4096 Oct 22 20:36 usb7
drwxr-x---+  4 waran waran 4096 Jan  5 21:27 waran

./usb0:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb1:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb2:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb3:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb4:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb5:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb6:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./usb7:
total 8
drwxr-xr-x  2 root root 4096 Oct 22 20:36 .
drwxr-xr-x 11 root root 4096 Oct 22 20:36 ..

./waran:
total 20
drwxr-x---+  4 waran waran 4096 Jan  5 21:27 .
drwxr-xr-x  11 root  root  4096 Oct 22 20:36 ..
drwxr-xr-x   2 root  root  8192 Jan  1  1970 A874-2FAD
drwxr-xr-x   2 waran waran 4096 Oct 22 22:19 System\x20Reserved

./waran/A874-2FAD:
total 12
drwxr-xr-x  2 root  root  8192 Jan  1  1970 .
drwxr-x---+ 4 waran waran 4096 Jan  5 21:27 ..

./waran/System\x20Reserved:
total 8
drwxr-xr-x  2 waran waran 4096 Oct 22 22:19 .
drwxr-x---+ 4 waran waran 4096 Jan  5 21:27 ..

Any advice? Why did the structure suddenly change? How can I write to my USB sticks directly from Kubuntu?

Edit: Thanks to sudodus's answer I realized, that as root I have the write permissions and I am able to write on the pendrive. Changing /media/waran permissions didn't work, mounting the drive manually through command-line didn't change the permission issue either.

Edit: Result of df after unmounting the USB stick:

Filesystem     1K-blocks      Used Available Use% Mounted on
udev             1948092         0   1948092   0% /dev
tmpfs             394580     26256    368324   7% /run
/dev/sda5       23706164  15941220   6537672  71% /
tmpfs            1972892     40900   1931992   3% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            1972892         0   1972892   0% /sys/fs/cgroup
/dev/sda6      780771600 450109520 290978140  61% /home
tmpfs             394576         0    394576   0% /run/user/119
tmpfs             394576        24    394552   1% /run/user/1000

Result of df after mounting the USB stick:

Filesystem     1K-blocks      Used Available Use% Mounted on
udev             1948092         0   1948092   0% /dev
tmpfs             394580     26256    368324   7% /run
/dev/sda5       23706164  15941248   6537644  71% /
tmpfs            1972892     41156   1931736   3% /dev/shm
tmpfs               5120         4      5116   1% /run/lock
tmpfs            1972892         0   1972892   0% /sys/fs/cgroup
/dev/sda6      780771600 450109520 290978140  61% /home
tmpfs             394576         0    394576   0% /run/user/119
tmpfs             394576        24    394552   1% /run/user/1000
/dev/sdb1        7849228    263772   7585456   4% /mnt/sd1

So it seems the pendrive was successfully unmounted and mounted, still I am not able to edit the contents without root permissions.

2

After not getting any new ideas here anymore, I reposted the question to Ubuntu Forums. https://ubuntuforums.org/showthread.php?t=2348773

Coffeecat advised me to uninstall the usbmount package (apt-get remove usbmount). Now I am able to change the content of a pendrive without root permissions.

  • This worked for me. usbmount caused a number of obscure USB errors on my system (Ubuntu 18.04). USB flash drives were always mounted as read only even when I manually mount from terminal and I could not mount USB HDDs (resulted in mounting errors). Uninstalling this immediately fixed all issues. Also, copying files with sudo while usbmount was installed (the only way) was an order of magnitude slower than normal. – RTbecard Dec 19 '18 at 16:43
0

root owns /media/waran and what gets mounted there with the automatic method. Can you create or copy files to the USB drive as root? Try

sudo bash -c "echo 'Hello World' > /media/waran/A874-2FAD/hello.txt"

One alternative would be to change the permissions of /media/waran

sudo chmod ugo+rwx /media/waran

Another alternative to change ownership

sudo chown waran /media/waran

Reboot. If this does not work, or you don't want such a solution, you can have a command line method (maybe contained in a shellscript or alias).

Assumption: the pendrive is seen as /dev/sdx, and that there is one partition with FAT32 or NTFS, replace x with the actual drive letter, for example b: /dev/sdx1 ---> /dev/sdb1

sudo mkdir -p /mnt/sd1  # only if you want a new mountpoint
sudo umount /dev/sdx1   # only if already mounted (but with bad permissions)

sudo mount -o rw,users,umask=000 /dev/sdx1 /mnt/sd1  # mount

ls -ld /mnt/sd1                          # check permissions

sudo bash -c "echo 'Hello World' > /mnt/sd1/hello.txt"  # test writing with sudo
cat /mnt/sd1/hello.txt                   # test reading (as user)
ls -l /mnt/sd1                           # check permissions of the content
rm /mnt/sd1/hello.txt                    # test removing (as user)
echo 'I am a user' > /mnt/sd1/user.txt   # test writing (as user)

Modify the mount option 'umask' to fit what you want. umask=000 means that everybody has full access to the mounted partition.

  • Thanks to your answer I realized, that I am able to write / remove files as root. I have tried to change ownership, but it doesn't help. Your assumption about the pendrive being seen as /dev/sdx was correct and it is indeed formatted as FAT32. But even using the shell method, only root is able to edit the content. (The file hello.txt is owned by root and I am not able to remove it. I am also not able to create the file user.txt: bash: /mnt/sd1/user.txt: Permission denied.) Any Ideas? – janjaromirhorak Jan 6 '17 at 12:58
  • Have you unmounted the partition, and then tried to mount it with sudo mount -o rw,users,umask=000 /dev/sdx1 /mnt/sd1 (should be one line)? – sudodus Jan 6 '17 at 13:07
  • I did sudo umount /dev/sdx1, then sudo mount -o rw,users,umask=000 /dev/sdx1 /mnt/sd1 (I substituted the x in sdx1 with the current drive letter). Then I tried to create a file using echo "test" > /mnt/sd1/testfile.txt and got this following error: bash: /mnt/sd1/testfile.txt: Permission denied. – janjaromirhorak Jan 6 '17 at 13:15
  • This works for me in Lubuntu 16.04.1 LTS. I must admit that I don't understand why it does not work for you. What is the output of ls -ld /mnt/sd1 ? – sudodus Jan 6 '17 at 13:20
  • ls -ld /mnt/sd1 returns this: drwxr-xr-x 3 root root 4096 Jan 1 1970 /mnt/sd1 – janjaromirhorak Jan 6 '17 at 13:50

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.