0

I have en ext4 file system with a program that I run off of it. However, every time I boot my computer I have to remount the drive with the exec flag in order to run the application. How would I go about editing /etc/fstab to mount the drive with the exec flag by default instead?

1

Common permissions with Microsoft file systems in Linux

When mounting Microsoft file systems (NTFS and FAT) you set the permissions of all files and directories.

Individual permissions with Linux file systems

But with linux file systems (you have an ext4 file system) you can set and should set the permissions of files and directories individually.

When you create files in a directory they will inherit the permissions from the directory. So I suggest that you modify a directory, where you have your program(s) and shellscripts,

sudo chmod ugo+x /path-to/directory-name

This time, you have already your program file, so modify its permissions

sudo chmod ugo+x /path-to/program-name

Edit 1: You may also want to change the ownership of some directories and files individually, which is also possible and recommended in linux file systems.

sudo chown user:group /path-to/directory-name

and

sudo chown user:group /path-to/file-name

where user and group should be replaced by the actual user-ID and group-ID, that you want to own the file (the group-ID can be skipped, or set to the same as the user-ID).

Edit 2:

A line with mount option exec in fstab for a USB drive with ext4

It works for me (in Ubuntu 16.04 LTS as well as in Artful to become 17.10) to run executable files in ext4 file systems, when automounted as well as when mounted via /etc/fstab without the mount option exec.

But it is not the case for you. So I tested to add a line into /etc/fstab, with mount option exec (in Artful to become 17.10), and it works for me. I hope this will solve your problem.

  • Create a mountpoint

    sudo mkdir -p /mnt/usb-ext4
    
  • Identify the UUID of the partition in the USB drive to be mounted

    sudo blkid
    

    Use the string without quotes.

  • Edit /etc/fstab

    sudo nano /etc/fstab
    

    I added the following lines in my test

    # external drive with ext4 partition
    UUID=984666a5-594c-4edc-93a9-8923e6f52c80 /mnt/usb-ext4   ext4    defaults,exec,errors=remount-ro 0 2
    

Edit 3:

Another line with mount options user,noauto,exec in fstab

When you add the line in the previous paragraph into fstab, the system wants the USB drive to be inserted. If you want to boot without it, you can get along if you add the mount options user,noauto to the option list in that line of fstab.

UUID=984666a5-594c-4edc-93a9-8923e6f52c80 /mnt/usb-ext4   ext4    user,noauto,exec,errors=remount-ro 0 2

But you have to initiate mounting afterwards, for example with

mount -L <label>

or

mount <mountpoint>

in my example

mount -L test-exec

or

mount /mnt/usb-ext4

The same user can unmount it

umount /mnt/usb-ext4

Test output

After rebooting I ran the following commands.

mtab:

$ grep /mnt/usb-ext4 ext4 /etc/mtab
/dev/sdb1 /mnt/usb-ext4 ext4 rw,relatime,errors=remount-ro,data=ordered 0 0

fstab:

$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=10880524-3839-4142-b7db-f65845d87825 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=E556-B809  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
# external drive with ext4 partition
UUID=984666a5-594c-4edc-93a9-8923e6f52c80 /mnt/usb-ext4   ext4    defaults,exec,errors=remount-ro 0 2

I created a directory and changed ownership:

cd /mnt/usb-ext4
sudo mkdir bin
sudo chown $USER:$USER bin

Then I created a small shellscript and made it executable:

cd bin
echo 'echo Hello World'>hello
chmod ugo+x hello

Long list to check the permissions and ownership:

$ ls -l
totalt 4
-rwxrwxr-x 1 tester tester 17 okt  6 07:51 hello

and it can be run

$ ./hello
Hello World

General commands identifying the system

lsb_release:

tester@tester-SATELLITE-PRO-C850-19W:/mnt/usb-ext4/bin$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu Artful Aardvark (development branch)
Release:    17.10
Codename:   artful

uname:

tester@tester-SATELLITE-PRO-C850-19W:/mnt/usb-ext4/bin$ uname -a
Linux tester-SATELLITE-PRO-C850-19W 4.13.0-12-generic #13-Ubuntu SMP Sat Sep 23 03:40:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

blkid:

tester@tester-SATELLITE-PRO-C850-19W:/mnt/usb-ext4/bin$ sudo blkid
/dev/sda1: UUID="E556-B809" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="b3276a58-ea15-4cea-8c74-095b13ea7aa6"
/dev/sda2: UUID="10880524-3839-4142-b7db-f65845d87825" TYPE="ext4" PARTUUID="d399063d-1c12-4a62-86d9-0112b15a3e40"
/dev/sdb1: LABEL="test-exec" UUID="984666a5-594c-4edc-93a9-8923e6f52c80" TYPE="ext4" PARTUUID="4b07dce4-4bde-4fe9-9b2f-2442a62b0b87"

lsblk:

tester@tester-SATELLITE-PRO-C850-19W:~$ sudo lsblk -fm
[sudo] lösenord för tester: 
NAME   FSTYPE LABEL     UUID                                 MOUNTPOINT     SIZE OWNER GROUP MODE
sda                                                                        55,9G root  disk  brw-rw----
├─sda1 vfat             E556-B809                            /boot/efi      480M root  disk  brw-rw----
└─sda2 ext4             10880524-3839-4142-b7db-f65845d87825 /             55,4G root  disk  brw-rw----
sdb                                                                        30,2G root  disk  brw-rw----
└─sdb1 ext4   test-exec 984666a5-594c-4edc-93a9-8923e6f52c80 /mnt/usb-ext4 30,2G root  disk  brw-rw----
sr0                                                                        1024M root  cdrom brw-rw----
5
  • Didn't seem to work. My problem is that I need the exec flag. The files on the drive already have the correct permissions and the program file is marked as executable. (For example, when I try to run the program at first without the exec flag, I get the error "permission denied." After I run "sudo mount -o remount,exec" on the drive, the program runs.)
    – ETPOF
    Oct 5 '17 at 23:14
  • @ETPOF, Strange, I tested with a USB drive with an ext4 partition in an installed and up to date 16.04 LTS. And it automounted so that executable binary programs as well as a shellscript, that I created for the test could be run. Anyway, I will modify the answer to include a line for /etc/fstab with the relevant mount option. Please let me know, if it will work for you.
    – sudodus
    Oct 6 '17 at 4:45
  • @ETPOF, Are you sure that you have an ext4 file system in a partition in the USB drive? In that case it should definitely work according to my answer. But if you have some other file system, or if the file system is directly in the drive (without any partition, like in the old floppy disks, there might be problems (I have not tested those cases)). If there is a FAT or NTFS file system, you have better luck along the path of waltinator's answer.
    – sudodus
    Oct 6 '17 at 7:16
  • I actually ended up solving my own problem. I'm definitely sure it is ext4 (shows up in gparted and such as that). All I really needed to do was add the remount command I mentioned to /etc/rc.local. Since I don't often take my USB out of my computer, this works well temporarily. I won't accept any answers until I try your solution though. It is actually more relevant to what I asked so it might be a better solution if it works.
    – ETPOF
    Oct 6 '17 at 18:08
  • @ETPOF, I'm glad you found a solution :-) If you add the line I suggest into fstab, the system wants the USB drive to be inserted. If you want to boot without it, you can get along if you add the mount options user,noauto to the option list in that line of fstab. But you have to initiate mounting afterwards, for example with mount -L <label>, or mount <mountpoint>, in my example mount -L test-exec, or mount /mnt/usb-ext4 and then your current method with remount might be as good. (I will edit the answer to add this information.)
    – sudodus
    Oct 6 '17 at 21:38
0

Here's how I forced my Ubuntu 16.04.3 system to mount a thing with the default options, read man mount, especially the parts about "FILESYSTEM INDEPENDENT MOUNT OPTIONS" and "Mount options for fat".
I did

w3@aardvark:~(0)$ sudo lsblk --output "NAME,UUID,PARTUUID,SIZE,STATE"
NAME           UUID                                 PARTUUID                               SIZE STATE
sda                                                                                      465.8G running
├─sda1         362254e8-2b99-442d-8ad9-4a348bc08032 ab519d4e-b282-4ca4-87a4-c3e5b143291f 111.3G 
└─sda2         191289bd-73e0-4935-8f17-700559c83570 0109ac9a-7539-4323-9f1a-b24c59066e46 354.5G 
sdb                                                                                      465.8G running
├─sdb1                                              000a3a79-01                            7.5G 
│ └─cryptswap1 022bb8c1-4a34-444c-a359-b0aef01e3191                                        7.5G running
├─sdb2                                              000a3a79-02                              1K 
├─sdb5         83a64b80-5a37-4659-b797-221b88ef41f8 000a3a79-05                          165.2G 
└─sdb6         12817b99-9d2b-4357-a4ca-c11eab672a20 000a3a79-06                            293G 
sdc            0123-4567                                                                   3.7G running
sdd            0123-4567                                                                   7.4G running
sdf                                                                                      931.5G running
└─sdf1         ff359af0-d996-4949-b27e-f24ce453c48c 00051704-01                          931.5G 
sdi            F440-F7F4                                                                   3.7G running

I picked sdi for this example, YMMV

w3@aardvark:~(0)$ mount | grep /dev/sdi
/dev/sdi on /home/w3/mnt/mp3/OTHER type vfat (rw,nosuid,nodev,relatime,uid=1003,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro)  

echo -e to force interpretating of \t, \n, select the options you like

w3@aardvark:~(0)$ echo -e "# Added by $USER $(date)\nUUID=F440-F7F4 /home/w3/mnt/mp3/OTHER\tvfat rw,exec,nosuid,nodev,relatime,uid=1003,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro 0 0" 
# Added by w3 Fri Oct  6 00:35:20 EDT 2017
UUID=F440-F7F4 /home/w3/mnt/mp3/OTHER   vfat rw,exec,nosuid,nodev,relatime,uid=1003,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro 0 0
w3@aardvark:~(0)$ !! | sudo tee -a /etc/fstab
echo -e "# Added by $USER $(date)\nUUID=F440-F7F4 /home/w3/mnt/mp3/OTHER\tvfat rw,exec,nosuid,nodev,relatime,uid=1003,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,flush,errors=remount-ro 0 0"  | sudo tee -a /etc/fstab
# Added by w3 Fri Oct  6 00:35:40 EDT 2017
UUID=F440-F7F4 /home/w3/mnt/mp3/OTHER   vfat rw,nosuid,nodev,relatime,uid=1003,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro 0 0

This is good for the FIRST time. Subsequently, you can edit /etc/fstab with

sudoedit /etc/fstab

Be very careful, keep a backup copy of the last working fstab. If you break fstab your system will not work.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.