1

I am very new to Linux, and thus have very noob questions. I currently have Ubuntu 14.04 LTS installed on my hard disk. However, my biggest issue is with flash drives. I have all of my .cpp files on my flash drive, but when I go to compile them in the terminal, I am presented with:

bash./ permission denied

And through some research, I have found out that this is because my flash drive has not been manually mounted, leaving me without permission to access these files. Now I have a few questions:

1) What is the purpose of manually mounting a flash drive

2) And how can I go about mounting my flash drive so that I have the permission to write new .cpp files, and also compile them.

Thank you!

  • How is your flash drive formated ? Is it vfat or ext4 ? – Harris May 19 '16 at 17:31
  • @Harris it is FAT32 –  May 19 '16 at 17:33
  • Try to give the output file a .exe extension. This should solve your problem. For example: g++ test.cpp -o test.exe where test.cpp is your C++ file. – Harris May 19 '16 at 17:39
  • @Harris That doesn't work. The computer needs to know it is a .cpp file in order to compile. My issue would be solved if I properly mounted my flash drive. Could you please help me in doing so? –  May 19 '16 at 17:45
  • Have your tried to compile using a terminal and the instruction above ? Which compiler or IDE are you using ? I tried a simple program on a FAT32 and I was getting the same error as you have but compiling the file to .exe seems to run ok. – Harris May 19 '16 at 17:49
  • @Harris I am using Code::Blocks. I want to be able to press f9 inside the IDE and just compile the program right there. However, since I have not properly mounted my flash drive, I am denied access to compile my files. –  May 19 '16 at 17:56
  • I've just tested it in Code::Blocks and it works if you use a Project. Under Projects Properties click the Build targets tab, change the output filename to .exe and un-tick the Auto-generate filename extension . – Harris May 19 '16 at 18:22
  • @Harris Thank you, but this is just a quick fix for Code::Blocks. I really need to figure out how to gain permission to my flash drive (through mounting) so I can access all of my files via terminal, other IDE's, etc. –  May 19 '16 at 18:27
  • 2

1 Answers1

1

Read this article if you are unfamiliar with mounting filesytems in linux.

In Linux, if you, or any other program (CodeBlocks in this case) has to run a file, the file should have executable permissions. These functionalities are not supported by the fat32 filesystem. Normally if it was a filesystem that supports this feature, you could have give the file executable permission by using chmod (do a man chmod to know more about it).

But in your case, since it is FAT32, you will have mount the partition manually allowing programs to be run from the flash drives.

We need to first unmount the partition:

sudo umount /path/to/mount/point

Then we remount the partition again:

sudo mount -t vfat -o rw,auto,user,fmask=0022,dmask=0000 /dev/sdx1 /path/to/mount/point

where /dev/sdx1 refers to the partition you want to mount and /path/to/mount/point refers to the folder to which you want to mount it.

You can get information about the devices that are currently mounted by typing mount in the terminal. The mount command will give you the path/to/mount/point and also the partition you now have to mount (/dev/sdx1).

In the output of mount, a line starting with /dev/sdb1 on /boot ... indicates that the partition /dev/sdb1 is mounted at /boot (mount point).

daltonfury42
  • 5,499
  • I did everything you said, but just received this error:

    mount: special device /dev/sbd1 does not exist

    –  May 19 '16 at 18:31
  • You got the device wrong, it should probably be /dev/sdb1 not /dev/sbd1 – daltonfury42 May 19 '16 at 18:33
  • Ok, I just fixed it and it seems like it worked because I can't see the flash drive name in files any more. Did it eject itself? And also, if I insert flash drive again, with it just automount itself and I have to do this step every time I use this flash drive? And when you say "folder to which you want to mount it" do you mean we are going to mount my flash drive to a local folder? Like Documents, Pictures, etc. ? –  May 19 '16 at 18:36
  • So now you are able to compile and run your code from codeblocks? It has not been ejected. You can get the contents of the flash drive by going to the mount point that you gave when you manually remounted it(path/to/mount/point). – daltonfury42 May 19 '16 at 18:41
  • I never gave a mount point, I didn't know I had to do so. And by mount point, do you mean a local folder like Documents? –  May 19 '16 at 18:45
  • @dhaneku.b Any empty folder in which you wish the contents of your flash drive to appear. – daltonfury42 May 19 '16 at 18:46