4

I have set up 16.04 manually and have now two partitions (ext4). My second (and bigger) partition can be written at only by root. Now when I hit sudo su in the terminal and input my password, I'm still forbidden access to the folder. I actually think I messed up the partition process... My goal was to have two partitions, one for Ubuntu and one for my data. But now everything is on the same (small) partition.

After sudo parted -l, I get:

Festplatte  /dev/sda:  500GB  
Sektorgröße (logisch/physisch): 512B/512B  
Partitionstabelle: msdos  
Disk-Flags:

Nummer  Anfang Ende    Größe   Typ       Dateisystem     Flags
1      1049kB  15,7GB  15,7GB  primary   ext4            boot
3      15,7GB  496GB   480GB   primary   ext4
2      496GB   500GB   4223MB  extended
5      496GB   500GB   4223MB  logical   linux-swap(v1)

3 is the one with the problem.

From mount | grep 'media/johanna/home', I get:

/dev/sda3 on /media/johanna/home type ext4 (rw,nosuid,nodev,relatime,data=ordered,uhelper=udisks2)
Eliah Kagan
  • 119,640

3 Answers3

3

First create a mount-point:

sudo mkdir /media/data

Change the ownership of the mount-point:

sudo chown johanna: /media/data

Set the permissions:

sudo chmod 755 /media/data

Now open the fstab-file:

sudo nano /etc/fstab

Add the following line at the end of the file:

/dev/sda3  /media/data  ext4 defaults  0  2

Press Ctrl+o and then hit Enter

Press Ctrl+x

Close the terminal and reboot. You will be able to write to your mounted partition now without root-privileges.

Note

On german keyboards the Ctrl-key should be the left Strg-key.

Explanation

It looks like you mounted the partition via the desktop-icon or opening the partition in the file-manager. Doing so will automatically create the directory /media/<username>/<partition-name>, the partition-name might be the label of the partition (if one exists) or the UUID of the partition.

This automatically created folder should be owned by and you should have read- and write-permissions, but mysteriously this doesn't seems to be the case. Also, this folder will be removed as soon as the partition is unmounted, if you don't unmount the partition yourself, the partition will be unmounted whenever the system shuts down. This explains that any changes (ownership, permissions) will not survive a reboot.

To ship around this we create a directory which we use as mount-point, adjust ownership and permissions of the directory and at last we add an entry to the fstab-file, so the partition will be auto-mounted at start-up. This directory is not going to be removed when the partition is unmounted.

Addition

I also have the impression that you wanted to set up your installation with a separate /home-partition. It seems you created the partition, but you didn't specify the mount-point (which would be /home) during installation. As the result you got a system with your system-partition and a big, but empty partition. Don't worry, you still can achieve this by copying the contents of the /home-folder to the partition and after doing so changing the mount-point of the partition to /home, here is a nice "How to do that":

https://help.ubuntu.com/community/Partitioning/Home/Moving

mook765
  • 18,644
0

I think I have a much, much easier way to achieve this (for GUI users), and re-mounting it does work with same permissions. I do everything with Nautilus. Normally the new partition will appear in the left side of Nautilus, and one can click it to mount it, right? For this procedure you start Nautilus as root user, I do this with "gksudo nautilus" (Tip; assign a key combination in system settings, keyboard, custom). Type root password in the dialog. Then mount the drive, click properties, and go to the rights tab (don't know the exact term because my system is in dutch), and change to your preferences. That's it.

If this is not working for you I would remove the partition in GParted and re-create it, and try again, since you have applied several operation on it that maybe could interfere.

Marcellus
  • 412
0

That a normal user can't write to a newly created partition is perfectly normal. That root can't access it, though, isn't.

First off: Mount the partition. You will learn why below.

Your mount point should have these permissions, owner, and group:

drwxr-xr-x  25 root root

Navigate to the folder where your mount point is. So if your mount point is /media/john/data, navigate to /media/john in the terminal. Then execute ll. You can get it to have the properties mentioned above by executing these commands:

sudo chown root data
sudo chgrp root data
sudo chmod 751 data

You, however, want access for yourself. So swap root in the first 2 lines out for your own user name:

sudo chown john data
sudo chgrp john data
sudo chmod 751 data

You have to execute these commands when the partition is mounted. When the partition is mounted, these commands modify the properties of the root of the file system of the mounted partition. If nothing is mounted in that folder, the commands modify the properties of the folder on the FS mounted in /media/john (probably the same one as in / on your system). You don't want this.

UTF-8
  • 5,910
  • 10
  • 34
  • 68