[wiki] HowTo - Permanent mount for partition

Make a permanent mountpoint.

http://www.pathname.com/fhs/pub/fhs-2.3.html#INTRODUCTION states

The FHS document has a limited scope:
Local placement of local files is a local issue, so FHS does not attempt to usurp system administrators.
FHS addresses issues where file placements need to be coordinated between multiple parties such as local sites, distributions, applications, documentation, etc.

So for the sake of this HowTo there is no standard as we are talking about

Local placement of local files is a local issue.

Locate the device and partition(s).

$ lsblk
sda      8:0    0 223,6G  0 disk 
├─sda1   8:1    0   512M  0 part 
├─sda2   8:2    0    60G  0 part 
├─sda3   8:3    0   130G  0 part 
└─sda4   8:4    0  33,1G  0 part [SWAP]
sdb      8:16   0   477G  0 disk 
└─sdb1   8:17   0 419,1G

Depending on your computers hardware you might get other device names and partition numbers. Modify the following according to your output.

The /media folder

Manjaro used a media folder located under /run to mount removable medias on the fly.
The root folder /media is a folder used for mounting removable media on a defined structure. It is normally not in use in Manjaro so you need to create it. Ubuntu and other distros used it and certain automount utilities use the folder.

$ sudo mkdir /media

Permissions

You must define the access control list for the folder. ACL is a topic on its own so to keep it simple we will change the owner to your username. A lot can be said about this approach but lets keep it simple.

$ sudo chown $USER /media

Make a permanent mountpoint.

Create a folder for the purpose (change all references to mydisk as you would want a more descriptive name).
If you have several partitions you should name the folders with decriptive names - what ever you feel appropriate :slight_smile:

$ mkdir /media/mydisk

Mount the partition.

Replace the Xy with the device and the partition number you found.

$ sudo mount /dev/sdXy /media/mydisk

Mount partition on boot.

To mount it permanently on boot modify your /etc/fstab to include the partition on boot.

$ su -
# echo "UUID=$(lsblk -no UUID /dev/sdXy) /media/mydisk $(lsblk -no FSTYPE /dev/sdXy) defaults,noatime 0 2" >> /etc/fstab
# mount -a

If your drive has more than one partition repeat above steps as needed adjusting for each partition.

The echo command looks cryptic right?

It is not - try this

$ lsblk -no UUID /dev/sdb1                                                 
08264f2e-4e9e-403d-bbd0-72e62301e07c

This outputs the unique identifier of your partition. This is used in fstab to ensure the same partition is always mounted the right places. Now try this

$ echo $(lsblk -no UUID /dev/sdb1)                                         
08264f2e-4e9e-403d-bbd0-72e62301e07c

You see? We got the exact same result but with this approach we include it in a command which writes a lot more info. Note that we can use a similar construction to get the filesystem type for the partition.

$ echo $(lsblk -no FSTYPE /dev/sdb1)
ext4

To write this to a file we use a pipe - an arrow pointing to a file name.

$ echo "UUID=$(lsblk -no UUID /dev/sdb1) /media/mydisk $(lsblk -no FSTYPE /dev/sdXy) defaults,noatime 0 2" > test.txt

To avoid deleting the contents of a file we append to it with double arrow

$ echo "UUID=$(lsblk -no UUID /dev/sda2) /media/myhome $(lsblk -no FSTYPE /dev/sdXy) defaults,noatime 0 2" >> test.txt

Have a look at the file

$ cat test.txt
UUID=08264f2e-4e9e-403d-bbd0-72e62301e07c /media/mydisk ext4 defaults,noatime 0 2
UUID=8b830a57-314f-40a9-b82f-a8fcfabbccb4 /media/myhome ext4 defaults,noatime 0 2
32 Likes
[wiki] HowTo - Access my second harddrive
Mount location for cifs shares in Manjaro
[wiki] HowTo - Unlock my Windows partition
Change mounted partition
How to make partition table manually
thunar dies at least once a day
Scary message from gparted
Change mounted partition
Just Changed Second HDD To Ext4, Now I Can't Write Anything To It
How do I automatically mount an external harddrive?
Automatically Mount a partition
Moving Dropbox Folder to Second Hard Drive
Split Trash for disc parts
Architect change mounted data partition
How do I use a HDD to store media files
How does Dolphin mount drives when I click on them?
Want to completely switch from windows and don't want to lose any data from my hdd.
Synology Cloud Station Drive doesn't find my second hard drive
How to keep hard drives from being locked upon start up?
Disk doesn't automount at startup.
Can't write to second hard disk
Moving an automatically mounted filesystem
Using USB flash drive as second hard drive?
Can't write to Second drive (Game Drive)
How do I become linux master? ;)
Wine cannot find /run/media/username
How do I allow Steam to see library on second drive after startup?
Setting up second storage drive.
Automount Drives
[SOLVED] Mount --bind in fstab
How to take ownership/mount drive and change Steam library location?
[SOLVED] Auto mount Data partition
Partitioning with mutiple SSD's
RE: [wiki] HowTo - Permanent mount for partition
Is there way to install an app in a specific folder in a specific hard disk from pacman?
Second hard drive changes name on boot

Nice guide, however consider using /mnt instead of /media. Filesystem Hierarchy Standard states:

/mnt : Mount point for a temporarily mounted filesystem

Purpose

This directory is provided so that the system administrator may temporarily mount a filesystem as needed. The content of this directory is a local issue and should not affect the manner in which any program is run.

This directory must not be used by installation programs: a suitable temporary directory not in use by the system must be used instead.

As oposed to:

/media : Mount point for removeable media

Purpose

This directory contains subdirectories which are used as mount points for removeable media such as floppy disks, cdroms and zip disks.

 Rationale

Historically there have been a number of other different places used to mount removeable media such as /cdrom, /mnt or /mnt/cdrom. Placing the mount points for all removeable media directly in the root directory would potentially result in a large number of extra directories in /. Although the use of subdirectories in /mnt as a mount point has recently been common, it conflicts with a much older tradition of using /mnt directly as a temporary mount point.

It's nitpicking, sure, but might as well do it "the right way".

3 Likes

It is - as you can do it exactly the way you like.

In Arch Linux and therefore Manjaro removable media (usb etc) and media not mounted in fstab is mounted in /run/media/<user>/<label>or<uuid>.

/mnt is for temporary mounts.

/media is not used in Arch and derivatives so a folder structure under /media is a reasonable choice for permanent mountpoints.

But you can do as you please - that's the beauty.

3 Likes

In Arch udisks2 does the mounting, Archwiki even provides an example how to mount removable media to /media

/media isn't any more permanent.

It's as reasonable choice as any if you follow this logic. Archiwiki uses /mnt in example on how to mount a filesystem.

I agree, it's a flexible system, not everything has to be done by the standards. Our discussion here should suffice for the curious new users to learn how to mount drives. Hopefully my nitpicking also gives them an idea about existnce of a standard way to do it.

Just don't go create a piece of software that creates 5 random mountpoints and lets user pick one :wink:

1 Like

http://www.pathname.com/fhs/pub/fhs-2.3.html#INTRODUCTION clearly states

The FHS document has a limited scope:
Local placement of local files is a local issue, so FHS does not attempt to usurp system administrators.
FHS addresses issues where file placements need to be coordinated between multiple parties such as local sites, distributions, applications, documentation, etc.

So for the sake of this HowTo there is no standard as we are talking about

Local placement of local files is a local issue.

I have always wondered - when everyone is so fond of standards - and when you use them - there is always some with another opinion.

/media and /mnt is good examples.

We have /mnt as for absolute temporary mounts as specified by FHS and /media is for removable media.

The FHS allows us to mount system folders on different partitions eg. /var and /home everything can be mounted to different partitions - even different drives.

But when it comes to a partition which is outside the defined system folders, there is no clear definition - according to FHS where do you mount extra partitions?

Some says mount /mnt but if you create a folder structure there and mount your extra partitions there you are in for trouble if a program uses the FHS standard to temporary mount something in /mnt which will cause havoc for the files depending on your mount tree in /mnt

But in fact the extra partitions you have which is temporarily mounted in /run/media are removable - just not in the sense of physical removal but removable in the sense of ejecting aka umounting them on the fly.

But why is using /media with a defined and structured set of mountpoints against FHS?

Where is the standard to mount extra partitions you choose for data etc?

2 Likes

If something gets mounted automatically, it's supposed to be doing so using udev rules. See udisks2 argument above.

Sure. Place local files wherever you want.

I'm done.

It's not. Your wiki is as correct as it could ever be. Straight out of the "FHS book".

And for the life of me I cannot understand the /run/media folder in Arch no matter how hard I try. And I never used it as a mount point and relocate any mount points off of it, if I find them.

I was around the distro back in 2011 or 2012 when I think I remember /run was first adopted. The logic was NOT to create a mountable area in addition to to /mnt and /media. It was instead to make /var/run a top level folder and with this fix some abuse that was being made of it. The move on Arch came after Fedora's who implemented it for the first time after a discussion between devs of Fedora and other distros to sanitize /var/run.

1 Like

Wow, all this quibbling over the location of the mount point.???

Really guys? You want to go back and second guess THAT stuff again? That battle has been fought and lost (or won) a long time ago.

@linux-aarhus's solution is a great way to have a permanent (as in unchanging) mount point for plugable devices.** so that they show up in the same place every time and can be scripted, or have permissions set consistently regardless of who is logged in when that backup drive is plugged into the system.

Sure you can move that to /mnt or anywhere else. But if it is a pluggable device its going to get automunted in /media anyway. Why not use that mount instead of having to undo it?

** I might quibble about the "0 0" options, and perhaps show examples of setting mount permissions, but these are mere details.

4 Likes

I would perhaps just suggest changing the last field from 0 to 2.

0 should probably only be used in conjunction with nofail and x-systemd.device-timeout and at the same time you don't care about fsck checking your device during boot.

But if your partition/device is always present, you should probably set it to 2 to be mounted after the main 1 devices and let fsck check this partition too during boot.

So:
[...] -no FSTYPE /dev/sdXy) defaults,noatime 0 2" >> /etc/fstab

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by