Overview
systemd-mount leverages systemd's mount management capabilities to mount devices or image files to specific paths, or to create automount units that mount when needed. These are temporary units that disappear upon system reboot, making them useful in dynamic environments.
Key Features
- Create and activate temporary mount units
- Create and activate automount units
- Specify mount options and file system checks
- List and remove created mount units
Key Options
These are the main options used with the systemd-mount command.
Mounting Actions
Mount Configuration
Generated command:
Try combining the commands.
Description:
`systemd-mount` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Practical examples of using the systemd-mount command.
Basic Temporary Mount
sudo systemd-mount --mkdir /dev/sdb1 /mnt/mydata
Mounts the /dev/sdb1 device to the /mnt/mydata path. The mount point will be created automatically if it doesn't exist.
Create Read-Only Automount
sudo systemd-mount --automount --options=ro --mkdir /dev/sdc1 /mnt/readonly
Creates a read-only automount unit for the /dev/sdc1 device at the /mnt/readonly path. It will be mounted automatically when this path is accessed.
Mount by UUID
sudo systemd-mount --mkdir /dev/disk/by-uuid/YOUR_UUID /mnt/usb
Mounts a device with a specific UUID to the /mnt/usb path. You can find the UUID using commands like 'lsblk -f'.
Unmount and Remove Unit
sudo systemd-mount --collect /mnt/mydata
Unmounts the device mounted at /mnt/mydata and removes the associated mount unit created by systemd.
View Active Mount Units
systemd-mount --list
Displays a list of all mount and automount units currently active and created by the systemd-mount command.
Tips & Notes
Useful tips and points to consider when using systemd-mount.
Permanent vs. Temporary Mounts
- systemd-mount: Creates temporary mount units that disappear upon system reboot. Suitable for scripts or one-off tasks.
- /etc/fstab: Used for permanent mount configurations that persist across system reboots.
Unit Naming Convention
systemd-mount automatically generates unit names based on the mount path.
- Example: The path /mnt/data will result in a unit named mnt-data.mount.
Integration with systemctl
Units created by systemd-mount can be managed like regular systemd units using the systemctl command, such as checking status (systemctl status mnt-data.mount) or stopping (systemctl stop mnt-data.mount).
Using the --collect Option
It is recommended to use the --collect option for unmounting and removing associated units, rather than just using umount. Using umount alone may leave systemd units lingering.