How to hide mounts from the sidebar?
How to Hide Mounts from the Sidebar in Ubuntu: A Comprehensive Guide
Ubuntu’s default behavior is to display mounted drives and removable media on the sidebar of the file manager, Nautilus (also known as Files). While this is convenient for many users, it can be undesirable for those who prefer a cleaner interface or have security concerns. This guide, brought to you by revWhiteShadow’s personal blog site, provides a detailed, step-by-step approach to hiding these mounts without resorting to complex scripting. We aim to empower you to customize your Ubuntu experience to your exact preferences.
Understanding the Ubuntu Desktop Environment and Mount Handling
Before diving into the solutions, it’s crucial to understand how Ubuntu manages mounts and presents them in the graphical user interface. Ubuntu primarily uses udisks2
and gvfs
for managing storage devices. udisks2
handles the underlying mount operations, while gvfs
provides a virtual file system layer that allows applications like Nautilus to access remote and local filesystems. Understanding this interaction helps you grasp why certain configuration changes affect the visibility of mounts. Nautilus reads its configuration settings from GSettings.
Method 1: Using GNOME Tweaks to Manage Desktop Icons and Mounts
GNOME Tweaks (formerly known as Unity Tweak Tool) is a powerful utility for customizing various aspects of the GNOME desktop environment, including the visibility of desktop icons and mounted volumes. It provides a user-friendly interface for modifying GSettings without using the command line.
Installing GNOME Tweaks
If you don’t already have GNOME Tweaks installed, you can easily install it from the terminal:
sudo apt update
sudo apt install gnome-tweaks
After installation, you can launch GNOME Tweaks from the application menu by searching for “Tweaks.”
Hiding Mounted Volumes with GNOME Tweaks
Open GNOME Tweaks: Launch the application from the applications menu.
Navigate to the “Desktop” Section: In the left sidebar of GNOME Tweaks, click on the “Desktop” option.
Toggle “Mounted Volumes” Off: You will find a switch labeled “Mounted Volumes.” Turning this switch off will prevent mounted drives from appearing on the desktop. However, this setting primarily affects the desktop icons, not the Nautilus sidebar directly. It’s still a beneficial step for decluttering the desktop itself.
Examine Nautilus Behavior: After disabling “Mounted Volumes” on the desktop, open Nautilus (Files). Observe whether this change has indirectly affected the visibility of mounts in the sidebar. In some Ubuntu versions, this action might influence sidebar behavior, although it’s not the primary control for it.
Alternative Tweaks: Explore other options within GNOME Tweaks’ “Desktop” section. Adjust settings related to icons, trash visibility, and other desktop elements, which may indirectly contribute to a cleaner sidebar experience.
Method 2: Modifying GSettings Directly Using gsettings
Command
GSettings is the configuration system used by GNOME and many applications that rely on its libraries. It allows you to directly modify settings that control various aspects of the desktop environment, including Nautilus’ behavior. The gsettings
command provides a command-line interface for interacting with GSettings.
Identifying the Relevant GSettings Key
To hide mounts from the Nautilus sidebar, you need to identify the correct GSettings key that controls this behavior. Unfortunately, there isn’t a single, direct GSettings key to completely hide all mounts from the sidebar easily. Instead, we will configure Nautilus to manage bookmarks and side panes more effectively.
Configure Nautilus Bookmarks
Nautilus allows you to create bookmarks to frequently accessed folders. By selectively bookmarking only the directories you regularly use, you can reduce the visual clutter in the sidebar. To create a bookmark, navigate to a directory in Nautilus, then press Ctrl+D
or right-click and select “Add Bookmark.”
Removing Default Bookmarks: Remove the default bookmarks that are cluttering the sidebar. Right-click on the undesired bookmark and choose “Remove.”
Configure Side Pane Settings via dconf-editor
For finer-grained control, install dconf-editor
:
sudo apt update
sudo apt install dconf-editor
Open dconf-editor
. Navigate to:
/org/gnome/nautilus/preferences/
Here, examine settings like show-image-thumbnails
, show-memory-usage
, show-create-date
, and show-type-column
. While these don’t directly hide mounted drives, tailoring these settings can streamline your Nautilus experience.
Fine Tuning Mount Options through /etc/fstab
The /etc/fstab
file (file system table) controls how file systems are mounted at boot time. While primarily for configuring mount points, it can influence how Nautilus displays mounted volumes.
Understanding /etc/fstab
Entries
Each line in /etc/fstab
represents a file system and its mount options. The format is:
<file system> <mount point> <type> <options> <dump> <pass>
Using the noauto
Option to Prevent Automatic Mounting
The noauto
option prevents a file system from being automatically mounted at boot. This won’t hide the drive entirely from Nautilus, but it will prevent it from being mounted and appearing in the sidebar until manually mounted.
Example /etc/fstab
Entry with noauto
:
UUID=YOUR_DRIVE_UUID /media/your_mount_point ext4 noauto,users,rw 0 0
Replace YOUR_DRIVE_UUID
with the actual UUID of your drive and /media/your_mount_point
with your desired mount point. The users
option allows regular users to mount the drive, and rw
allows read-write access. The 0 0
values control backup and filesystem checks.
Finding the UUID of a Drive
You can find the UUID of a drive using the blkid
command:
sudo blkid
This command will list all block devices and their UUIDs.
Applying Changes to /etc/fstab
After modifying /etc/fstab
, you need to either reboot your system or manually mount the file system to apply the changes:
sudo mount -a
Leveraging udev Rules for Customized Device Handling
udev is the device manager for the Linux kernel. It allows you to dynamically manage device nodes in /dev
and handle device events. You can create udev rules to customize how devices are handled when they are connected to your system.
Creating a udev Rule to Prevent Automatic Mounting
You can create a udev rule to prevent a specific device from being automatically mounted when it is connected. This rule will effectively hide the device from the Nautilus sidebar until manually mounted.
Steps to Create a udev Rule:
Create a new udev rule file: Create a file in the
/etc/udev/rules.d/
directory with a.rules
extension. For example, you can create a file named99-hide-mounts.rules
:sudo nano /etc/udev/rules.d/99-hide-mounts.rules
Add the rule to the file: Add a rule that matches the device you want to hide and sets the
UDISKS_IGNORE
environment variable to1
. This variable tellsudisks2
to ignore the device.KERNEL=="sdX1", ENV{UDISKS_IGNORE}="1"
Replace
sdX1
with the actual device name of your partition. You can find the device name using thelsblk
command.Reload udev rules: After creating the rule, you need to reload the udev rules for the changes to take effect:
sudo udevadm control --reload-rules sudo udevadm trigger
Finding the Correct Device Name
Use the lsblk
command to list all block devices and their mount points. Identify the device name of the partition you want to hide.
Example:
lsblk
The output will show a list of devices and their partitions. For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1.9G 0 part /boot
└─sda3 8:3 0 236.1G 0 part /
sdb 8:16 1 7.5G 0 disk
└─sdb1 8:17 1 7.5G 0 part /media/user/USBDRIVE
In this example, sdb1
is the device name of the USB drive.
Modifying the udev Rule for Specific Devices
You can modify the udev rule to target specific devices based on other attributes, such as the device’s serial number or vendor ID. This allows you to create more precise rules that only affect certain devices.
Using udevadm info
to Gather Device Information
The udevadm info
command can be used to gather detailed information about a device, including its attributes and environment variables. This information can be used to create more specific udev rules.
Example:
udevadm info --attribute-walk --name=/dev/sdX1
Replace sdX1
with the device name of the partition you want to gather information about. The output will show a list of attributes and environment variables that you can use in your udev rule.
Example udev Rule Using Vendor ID and Product ID:
ATTRS{idVendor}=="0781", ATTRS{idProduct}=="5571", ENV{UDISKS_IGNORE}="1"
This rule will only affect devices with the specified vendor ID and product ID.
Method 3: Utilizing the Removable Medium’s Automount Settings
This method focuses on preventing automounting for removable media, thereby keeping them hidden from the sidebar until explicitly mounted.
Accessing Removable Media Settings
Open Settings: Launch the Settings application from the applications menu.
Navigate to “Removable Media”: In the left sidebar, locate and click on the “Removable Media” option.
Configure Automount Options: Under the “Storage” section, you will find options related to automounting removable media.
Disabling Automounting
Set “Automatic Mount Options” to “Never”: This will prevent removable media from being automatically mounted when connected to your system.
Configure Specific Settings: Adjust the settings related to removable drives. The options available here might vary depending on your Ubuntu version and the installed desktop environment. Disable “Mount removable media when inserted.” You might also find settings related to autorunning software from removable media; it’s generally recommended to disable these settings for security reasons.
Consequences of Disabling Automounting
Disabling automounting means that when you connect a USB drive or other removable medium, it will not automatically appear in Nautilus. You will need to manually mount it to access its contents.
Manually Mounting Devices
To manually mount a device, you can use the mount
command in the terminal. First, identify the device name using lsblk
:
lsblk
Then, create a mount point:
sudo mkdir /mnt/usb
Finally, mount the device:
sudo mount /dev/sdX1 /mnt/usb
Replace /dev/sdX1
with the actual device name and /mnt/usb
with your desired mount point.
Caveats and Considerations
- Systemd Mount Units: Ubuntu uses systemd mount units to manage mounts. Modifying these units directly requires advanced knowledge and can potentially destabilize your system. We recommend avoiding direct manipulation of systemd mount units unless you are an experienced user.
- User Permissions: Ensure that the user account you are using has the necessary permissions to mount and unmount devices. Incorrect permissions can lead to errors and prevent you from accessing your storage devices.
- Testing Changes: Always test any configuration changes in a non-critical environment before applying them to your main system. This will help you avoid potential problems and ensure that the changes meet your needs.
- Backup: Before making any significant changes to your system configuration, it’s always a good idea to create a backup of your important data. This will allow you to restore your system to a previous state if something goes wrong.
Conclusion
Hiding mounts from the Nautilus sidebar in Ubuntu involves a combination of techniques, including using GNOME Tweaks, modifying GSettings, adjusting /etc/fstab
, and leveraging udev rules. Each method offers different levels of control and complexity. By understanding these methods and their limitations, you can customize your Ubuntu experience to your exact preferences and create a cleaner, more secure desktop environment. Remember to test any changes carefully and back up your data before making significant modifications to your system configuration. At revWhiteShadow’s, we strive to offer comprehensive solutions to elevate your Linux experience.