When I last installed Ubuntu, I made an ext4 partition of around 80 Gb in notebook’s HDD.
The problem arouse when I tried to copy something on this partition. I was simply not able to copy anything in it or create a new file.
Apparently, I did not have ‘write permission’ on the said partition.
In this tutorial I’ll show you how to set write permission on ext4 partition in Ubuntu, in the correct way. Let’ssee how to do it.
How to set write permission on ext4 partition in Ubuntu:
The tutorial is performed in Ubuntu and uses extensively command line. A little knowledge about file ownership in Linux system would be a plus. Even if you do not know, no worries. You can still follow the tutorial with ease. Just follow the steps below:
Step 1:
First this, you need to know the UUID of the ext4 partition. But before that it will be better to know the name of partition.
The name, in Ubuntu, would be like sdaX or something. To find that, use the following command in terminal (Ctrl+Alt+T):
sudo fdisk -l
Output of the command will look like this:
You can find the name of the partition from its size, given under the Blocks field (in bytes). So in the picture above 78123008 roughly amounts to 78 Gb and thus it tells me that the partition name is sda7.
Now when you have the name, you can find the UUID by using the following command:
sudo blkid
Output of the command looks like this:
As you can see, with the partition name, you can easily identify the UUID.
Step 2:
Once you have the UUID, the next step is to find out where is the partition mounted.
Usually the location of the ext4 mount is /media/<user_name>. Where user_name is your own username.
You can also use $USER variable. It automatically takes your username.
You can display the mounted partitions in the following manner:
ll /media/$USER
The output of the command for me was this:
Now you see why I took the trouble of finding the UUID. If you have several partition mounted, you need to distinguish between them.
You can also see that only root has write on the mounted ext4 partition. You need to change the write permission for this partition here.
Step 3:
Now the easiest option is to give the write access to everyone using the infamous chmod 777.
But again, you won’t want to do that as it will give write access to anyone. Avoid using chmod 777 as far as it is possible.
Now, if not chmod 777, then what else? The file has root as owner and root as the group. Even ‘admin’ comes under ‘other’ group here.
What you can do do here is to change the group ownership of the mounted drive to admin. The admin group is generally named adm. You can use the following command to change the group owner:
sudo chgrp adm /media/itsfoss/56d0c0ab-60a0-48bf-955d-bc2f283009b6
Once you have changed the group, change the write permission for the group in the following manner:
sudo chmod g+w /media/itsfoss/56d0c0ab-60a0-48bf-955d-bc2f283009b6
Voila! Now you can copy-paste and create new files in the ext4 partition without any hindrance. And with added security, non-admin users will not be able to do so.
This tutorial is similar to what you need to do in order to auto mount Windows partition in Ubuntu. Any questions or suggestions are always welcomed. :)
Thanks boss!
Sorry to bother you with this, but I solved my own problem. Instead of the UUID being under /media/myuser, it was under /mnt/…. made the chgrp and chmod both work. Now, I don’t know if this is a misstake, but you may have a comment to this.
Hi, I’ve set up a new PC using Ubuntu 20.04 I added two hard drives, one ntfs (so I can pull it easily and use it in a windows machine). No problems there.
The second drive has two ext4 partitions. I am confident that I understand and have used all commands properly. But, the sudo chgrp adm /media/…(long uuid)… gets a response of ‘no such file or directory’. I’ve tried copy/paste, typing it in, triple checking. Nothing works. The drive is mounted and does display in the ‘ll /media/…’ command. I have worked on tasks to set up this PC and occasionally I find I need to install package. I have also verified the uuid in ‘DISK’ mount options.
Hi, why did you create two other directories besides the one you showed how to write to in this tutorial? Why the strange names for those? Why not say videos or music. Also a question related to /media partition in general. When I installed linux mint 20 it created the / partition which contains my home directory with 45 GB and the /media/ partition with 54 GB where I also have timeshift setup. I don’t understand why my home partition is smaller the the media partition. Can you enlighten me.
Those strange names are UUID and that is important for clearly identifying the partition you are trying to mount.
What you did was something unusual. Your home directory is kept under root but you created an additional partition for media. It wasn’t required.
Why home is smaller? Because you didn’t specify a dedicated partition for it. So it went under root partition.
Thanks for the reply. The default install of mint 20 is awful – I should have created all those partitions you showed in one of your articles. Can I boot up with an iso with gparted and resize the partitions and create new ones for swap, etc. or should I just do a reinstall? I don’t think I created the partition for media. could the default install have done that on its own?
Default installation keeps only one partition and that is root. Everything else is under this root partition. No separate swap partitions because a swapfile under root is used for swap.
If you are going to play with partitions, again, please make a back up of your important files on an external disk.