
When you plug a USB device into your Ubuntu system, it automatically mounts the device in a default location. This location is typically /media/[username]/
. However, there may be instances when you want to change this default automount location. This article provides a detailed guide on how to do this.
To change the default USB automount location in Ubuntu, you can create a new udev rule or create a symlink. The udev rule method involves adding a line to a udev rule file, while the symlink method involves creating a symbolic link. Both methods allow you to customize the automount location to your preference. Remember to backup your data before making any system changes.
Understanding Automount
Automounting is a process that allows a system to automatically mount filesystems in response to their access and unmount them when they are not busy. In Ubuntu, the udisks2 service is responsible for this automatic mounting.
Preparing to Change Automount Location
Before we begin, it’s important to note that changing system configurations can have unintended consequences. Always ensure you have a backup of any important data before making changes. Also, this guide is applicable to Ubuntu 13.04 and later versions that use udisks2.
Changing the Automount Location
To change the default automount location, we will create a new udev rule. Udev is a device manager for the Linux kernel. It manages device nodes in the /dev directory.
Step 1: Open Terminal
Press Ctrl + Alt + T
to open the Terminal.
Step 2: Create a New Udev Rule File
In the Terminal, type the following command:
sudo nano /etc/udev/rules.d/99-udisks2.rules
This command opens the nano text editor with root permissions (sudo
) and creates a new file (99-udisks2.rules
) in the directory /etc/udev/rules.d/
.
Step 3: Add a New Rule
In the nano editor, add the following line:
ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="1"
This line is a rule that sets the UDISKS_FILESYSTEM_SHARED
environment variable to 1
for all devices that are used as filesystems (ID_FS_USAGE=="filesystem"
). This makes the device mount at a location that is shared among all users, which is /media/
.
Step 4: Save and Exit
Press Ctrl + O
to save the file, then Ctrl + X
to exit nano.
Step 5: Reload Udev Rules
To apply the new rule, you need to reload the udev rules. In the Terminal, type:
sudo udevadm control --reload
This command reloads the rules in udev.
Step 6: Replug the USB Device
Physically remove and plug in the external drive for the new mount location to take effect.
Alternative: Creating a Symlink
If you want to configure the automount location to be /media/
instead of /media/[username]/
, you can create a symlink (symbolic link). This is a file that points to another file or directory.
In the Terminal, type:
sudo rmdir /media/your_username
This command removes the directory /media/your_username
.
Then, type:
sudo ln -s /media /media/your_username
This command creates a symlink that points /media/your_username
to /media/
.
Conclusion
Changing the default USB automount location in Ubuntu involves creating a new udev rule or a symlink. This guide provides step-by-step instructions on how to do both. Remember to always backup your data before making system changes.
Yes, you can change the default automount location to a specific directory of your choice by modifying the udev rule. Instead of setting UDISKS_FILESYSTEM_SHARED
to 1
, you can specify the desired directory path. For example, if you want the automount location to be /mnt/usb
, you can use the rule ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_FILESYSTEM_SHARED}="/mnt/usb"
in the udev rule file.
Yes, you can revert back to the default automount location by either removing the udev rule file (99-udisks2.rules
) or deleting the symlink (/media/your_username
) if you had created one. After removing the udev rule file or deleting the symlink, the system will revert to the default behavior of mounting USB devices in the /media/[username]/
directory.