How to define /etc/fstab entries to support rsync backups to external USB drives

Fedora 41, KDE Plasma

$ uname -a
Linux mandolin 6.12.8-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan  2 19:26:03 UTC 2025 x86_64 GNU/Linux
$

I have 2 external Western Digital Elements USB hard drives that I want to use to back up my main system using rsync. I’m having difficulty figuring out how to configure the system to accomplish the following:

Ideally, mount and unmount the file systems from Dolphin file manager.

Mount at boot or from the bash command line (with appropriate entries in /etc/fstab), and unmount from the bash command line.

Eventually, I also want to be able to support multiple system users so that each user can run rsync to back up his or her home directory tree in a private space on the external hard drive file system dedicated for back ups. But for right now I will settle for getting the above two objectives to work.

Here is some information on my current configuration.

$ lsblk -b -i -o name,fstype,fsver,label,ptuuid,partlabel
NAME        FSTYPE FSVER LABEL   PTUUID                               PARTLABEL
sda                              0cf24aeb-39e0-431d-b2dd-a71161dbecaa
|-sda1      ext4   1.0   disk2s1 0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s1
|-sda2      ext4   1.0   disk2s2 0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s2
|-sda3      ext4   1.0   disk2s3 0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s3
`-sda4      ext4   1.0           0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s4
sdb                              d0de6796-7bcd-4aca-81f4-1b7f4376d256
|-sdb1      ext4   1.0   disk1s1 d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s1
|-sdb2      ext4   1.0   disk1s2 d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s2
|-sdb3      ext4   1.0   disk1s3 d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s3
`-sdb4      ext4   1.0           d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s4
zram0
nvme0n1                          7c28784d-bafd-44d6-bdf5-884cc65c35b3
|-nvme0n1p1 vfat   FAT32         7c28784d-bafd-44d6-bdf5-884cc65c35b3 EFI System Partition
|-nvme0n1p2 ext4   1.0           7c28784d-bafd-44d6-bdf5-884cc65c35b3
`-nvme0n1p3 btrfs        fedora  7c28784d-bafd-44d6-bdf5-884cc65c35b3
$

When I click the partition shown in the left pane of Dolphin, it mounts the file system under /run/media/rhimbo:

Before mounting:

$ cd /run/media
$ pwd
/run/media
$ ls -al
total 0
drwxr-xr-x.  3 root root   60 Jan 12 13:32 .
drwxr-xr-x. 54 root root 1420 Jan 12 09:19 ..
drwxr-x---+  2 root root   40 Jan 12 09:40 rhimbo
$

After mounting disk2s1:

$ cd rhimbo/
$ ls -al
total 4
drwxr-x---+ 3 root   root     60 Jan 12 14:07 .
drwxr-xr-x. 3 root   root     60 Jan 12 13:32 ..
drwxr-xr-x. 4 rhimbo rhimbo 4096 Jan  3 13:16 disk2s1
$

I can then successfully run rsync, and the back up of my home directory tree is under disk2s1 :

$ ls -al disk2s1/
total 24
drwxr-xr-x. 4 rhimbo rhimbo  4096 Jan  3 13:16 .
drwxr-x---+ 3 root   root      60 Jan 12 14:07 ..
drwxr-xr-x. 3 rhimbo rhimbo  4096 Nov 22 12:55 home
drwx------. 2 root   root   16384 Dec 21 11:04 lost+found
$

I presume that another user logged in would have the same success. His or her back up would be under /run/media/<username>/disk2s1/ instead of under my tree /run/media/rhimbo/disk2s1/ .

The problem I have is that, if I unmount the external disk file systems via the ‘eject’ icon in Dolphin, I can’t get the system to see the disk again unless I reboot. This is a different issue, and I will post a separate question on the forum for this problem. But it led me to try to add entries to /etc/fstab to mount the external drive file systems. The problem is that I don’t know how to define the entries to support multiple users.

And what directories under /run/media do I need to create manually? And what ownership and permissions should be on those directories that I create manually?

You could add an entry in /etc/fstab, with mount point /mnt/backup[1] or similar, with appropriate options such asauto,noexec,nosuid,nodev,nofail.

Presuming a Linux native file system (e.g. ext4) of the backup partitions, you could then create a folder/path for each user, with the desired permissions. Different rsync scripts would then point to the users’ specific paths.


  1. Make sure the mount point was previously created. ↩︎

1 Like

Yes, and no.
As long as the device remains connected it cannot be again accessed (It was “ejected” and the config was removed)
However, if you unplug the usb device and reconnect it the device should once again be seen without a reboot.

The eject command dismounts the device and removes its config from /dev.
If you were to use the umount command then it could still be accessed (though possibly not through discover)

Correct but not what you seem to be asking.
the device itself would be the same under disk2s1/ even if the mount path /run/media/$USER/ is different. Thus what you show as /run/media/rhimbo/disk2s1/home would be identical for each user with only the user name changed in that path. The content of disk2s1/home/ would be the same for everyone.

The earlier suggestion of creating a mount point such as /mnt/backup/ then adding an entry in /etc/fstab to mount that device at that location would be ideal.

Then after mounting that device, simply create a directory with proper ownership for each user in /mnt/backup.

As an example, using your user name, (only after the drive is mounted as suggested) that could be done such as sudo mkdir /mnt/backup/rhimbo and set ownership with sudo chown rhimbo:rhimbo /mnt/backup/rhimbo (Do these steps only once)

Now your backups could be done with rsync -av /home/rhimbo/ /mnt/backup/rhimbo/ (Do this as often as desired)

To avoid filling the backup with the temporary files such as caches that no longer exist it would be useful to use one of the --delete… options with rsync.

The steps to create the directory, set ownership, and perform the backup would be identical for each user and the only changes would be the user names in those commands. Of course the creation of the directory and ownership permissions would be only done once but the backup with rsync could be done as often as desired ( as noted above).

1 Like

Yes, the file systems on the partitions are ext4.

If I understood you correctly, I would manually create /mnt/backup/ and then, under that directory, create a directory for each user log in, such as “rhimbo” ?

I guess the permissions on /mnt/backup would have to be at least r-xr-xr-x, so each user would be able to descend into his or her log in directory (such as “rhimbo”) when executing an rsync command under the user account (not as root)?

And, for each user’s directory under /mnt/backup I presume I would want to assign owner:group to be : and permissions rwx------ ?

And, of course, the rsync command could be something like this:
rsync -a -R -C $HOME/ /mnt/backup/$USER

(Ignore the command line options to rsync for the purposes of the discussion at hand; included just so it doesn’t appear ‘naked’ :wink: )

Oh, shoot…! I replied to @tqcharm before reading your post…!

OK, I’m going to read your comment carefully. I think you answered my follow up questions to @tqcharm !

  • Manually create the directory
  • Mount the device on that directory
  • create the users directories on that (now mounted) device.

Without the device mounted the directories would be on the root file system as would the backups.

Those should be the same as the users home directory under /home
For my user with ls -l /home it shows as drwx------.

I think that ls -ld /mnt/backup should show the same as ls -ld /home which for me seems to be

$ ls -ld /home
drwxr-xr-x. 1 root root 10 Jul 16 19:00 /home
Manually create the directory
Mount the device on that directory
create the users directories on that (now mounted) device.

I’m not sure I understand step 2. If I create, for instance, /mnt/backup/rhimbo, in the /etc/fstab file what would be the mount point? Would it be /mnt/backup/rhimbo ? How would that accommodate multiple users of the system each having a reference (mount point) to their own private space under /mnt/backup ?

I know that you can have multiple mounts of the same physical file system, but how does this avoid the problem you described earlier here (that all users would see the same content on disk2s1 ? :

So would /mnt/backup/rhimbo be the mount point accessing the file system (LABEL=disk2s1) on partition/dev/sdx/disk2s1 ?

Sorry, I’m not understanding yet… I’m going to try what you suggest and see if this helps my understanding…

By “having … their own private space”, do you mean that you want limits/quotas on how much space each user can allocate? Or do you simply not want one user to be able to access another user’s data? The former can be accomplished by creating separate partitions (or subvolumes). The latter can be accomplished by setting filesystem permissions. If it’s all on one partition, you would mount that at /mnt/backup. If you create separate partitions then you might mount them at /mnt/backup/rhimbo, etc.

The latter. I want something like this:

User “rhimbo” would back up to /mnt/backup/rhimbo
User “foobar” would back up to /mnt/backup/foobar

Now, a further complication is that I do have multiple partitions on the external hard drives:
disk1s1
disk1s2
disk1s3

I’m currently using disk1s1. But the question I have is what the mount point should look like and whether what I described above is right (/mnt/backup/rhimbo, etc.).

What I mean is that a user could navigate to /mnt/backup/<user login> to access his or her backed up files.
But it seems to me that there should be no reference to any user id in the /etc/fstab file.

But I would like to do this “the right way” so if that is not the “right” directory structure scheme (not the best practice), please let me know…!

It’s one mount point per filesystem (excluding bind mounts, but I’d avoid that complication). So your fstab line would be something like:

PARTLABEL=backup /mnt/backup ext4 auto,noexec,nosuid,nodev,nofail 0 0

Then you would create directories and set permissions as you like under /mnt/backup. (The mount point doesn’t have to be under /mnt BTW, you can create a top-level directory/mount-point for it.)

You can use sgdisk to read or set partition labels (e.g sudo sgdisk -p /dev/sdc to list the partitions and their lables on /dev/sdc; sudo sgdisk -c 1:"backup" /dev/sdc to set partition 1’s label to backup).

(Does ext4 need “auto”? I think that is something new.)

1 Like

You would then mount the specific file system in use as I noted above.

You would

  1. mount drive disk1s1 to the mount point /mnt/backup/
  2. Create discrete directories on that drive
    /mnt/backup/rhimbo
    /mnt/backup/foobar
  3. assign ownership and permissions as I already showed.
    ls -ld /mnt/backup should show the same as ls -ld /home
    ls -ld /mnt/backup/rhimbo should show the same as ls -ld /home/rhimbo

With this then each user would have their own backup space that is the same privacy restrictions as their home directory. Backups would then be done with rsync using something like rsync -av /home/foobar/ /mnt/backup/foobar/ and it will “just work” that way.

Exactly!

Exactly.!
/etc/fstab would have the entry for mounting disk1s1 to mount point /mnt/backup and there would only be one mount command there.

Following this same idea, additional mount points could be created such as /mnt/backup2, /mnt/backup3, etc.
The the additional drive partitions could be mounted similarly with one entry in fstab per drive partition for mounting.
The fstab entry should be created with using the UUID for the file system on each partition, which can easily be found with blkid or lsblk -f and the entry for each would look something like
UUID=(the uuid) /mnt/backup ext4 defaults 0 0
The changes for each discrete partition would be the UUID and the mount point.

From the title and earlier discussion it seem this may be partitions on an external, usb connected drive. If that is the case, then there should be a change to the fstab entry. If there is any chance that the drive may not be connected at boot time, then the options should be changed from defaults to nofail,auto,defaults,users
This change will ensure the system is able to boot even if the drive is not connected

Many sincere thanks, gentlemen…! I think it’s working. I can successfully mount and unmount from the command line. I haven’t tried rebooting yet, but I’m sure that will work.

I did have to run systemctl daemon-reload as instructed in the comment of my /etc/fstab file.

Just FYI, here is my new /etc/fstab file:

#
# /etc/fstab
# Created by anaconda on Fri Nov 22 15:54:29 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#

# fs_spec                                  fs_file      fs_vfstype  fs_mntops                    fs_freq  fs_passno

UUID=4a972d32-b4a0-418e-8f6d-f1aabcbe6b5f  /            btrfs       subvol=root,compress=zstd:1 0 0
UUID=0a70d693-9894-45d2-9668-122dffac9304  /boot        ext4        defaults                    1 2
UUID=EBC8-9DD9                             /boot/efi    vfat        umask=0077,shortname=winnt  0 2
UUID=4a972d32-b4a0-418e-8f6d-f1aabcbe6b5f  /home        btrfs       subvol=home,compress=zstd:1 0 0

# fs_spec            fs_file               fs_vfstype     fs_mntops                              fs_freq  fs_passno
LABEL=disk1s1        /mnt/backup1          ext4           auto,noexec,nosuid,nodev,nofail        0 0
LABEL=disk1s2        /mnt/d1s2             ext4           defaults,nofail                        0 0
LABEL=disk1s3        /mnt/d1s3             ext4           defaults,nofail                        0 0
LABEL=disk1s4        none                  swap           sw,nofail                              0 0

LABEL=disk2s1        /mnt/backup2          ext4           auto,noexec,nosuid,nodev,nofail        0 0
LABEL=disk2s2        /mnt/d2s2             ext4           defaults,nofail                        0 0
LABEL=disk2s3        /mnt/d2s3             ext4           defaults,nofail                        0 0
LABEL=disk2s4        none                  swap           sw,nofail                              0 0

And also for reference, here is the output of lsblk; you can see that I defined file system labels in addition to partition labels.

NAME        FSTYPE FSVER LABEL   PTUUID                               PARTLABEL            PARTUUID                             UUID                                          SIZE
sda                              0cf24aeb-39e0-431d-b2dd-a71161dbecaa                                                                                                2000365289472
|-sda1      ext4   1.0   disk2s1 0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s1              baaed8f5-307f-439a-9df6-1c6943b7a78e c4c592ac-e97a-42a3-8671-a6e8a54f27fc  965998542848
|-sda2      ext4   1.0   disk2s2 0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s2              e63e835d-4bd9-4080-ad7d-0ade6e6881bf ddf57568-9704-4426-9a07-5c4c6d932946  434000363520
|-sda3      ext4   1.0   disk2s3 0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s3              188ca273-2588-414a-89dc-cb4141f84f02 9db4ba26-573c-431e-af61-664330d4ed99  434000363520
`-sda4      ext4   1.0           0cf24aeb-39e0-431d-b2dd-a71161dbecaa disk2s4              b09cc65d-8e56-42ec-be32-b1f266a4bf27 6337d4af-12ea-4235-8311-60a92993a49b  137999941632
sdb                              d0de6796-7bcd-4aca-81f4-1b7f4376d256                                                                                                2000365289472
|-sdb1      ext4   1.0   disk1s1 d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s1              3186c702-fd4c-4386-b9e1-2ada6f2ab457 4ab26b6b-1ca5-4768-8503-ea35a34fcdb7  966366593024
|-sdb2      ext4   1.0   disk1s2 d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s2              bdac9c2f-0e86-4a50-824d-e5dc778efe58 3307a999-d7b6-4560-8068-4b881da82ba7  433632313344
|-sdb3      ext4   1.0   disk1s3 d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s3              6c455fa6-ba46-4de6-aa4e-8c96ded02829 e2331797-3318-4548-88c9-940011a849c4  434000363520
`-sdb4      ext4   1.0           d0de6796-7bcd-4aca-81f4-1b7f4376d256 disk1s4              9475c55b-53ea-46c2-b56a-a00bdaf42c24 1e888d6a-1076-474c-9e60-5c675686ae01  137999941632
zram0                                                                                                                                                                   8589934592
nvme0n1                          7c28784d-bafd-44d6-bdf5-884cc65c35b3                                                                                                1000204886016
|-nvme0n1p1 vfat   FAT32         7c28784d-bafd-44d6-bdf5-884cc65c35b3 EFI System Partition c28ce58b-3e2a-4a35-a872-1e4905900519 EBC8-9DD9                                629145600
|-nvme0n1p2 ext4   1.0           7c28784d-bafd-44d6-bdf5-884cc65c35b3                      031a718e-796b-4987-b6de-dc7e28e8c8f3 0a70d693-9894-45d2-9668-122dffac9304    1073741824
`-nvme0n1p3 btrfs        fedora  7c28784d-bafd-44d6-bdf5-884cc65c35b3                      2ad6e087-4fc8-4836-ba64-15e871be02b4 4a972d32-b4a0-418e-8f6d-f1aabcbe6b5f  998500204544
2 Likes

Something to watch out for:

I am still curious about why I cannot rescan the USB devices from a command line. I researched this, found a ton of topics, but none applied as they were often years old posts and related to different distros.

But I did more research and found the udevadm command. Perhaps I don’t understand the man page. Well, I tried a bunch of udevadm commands but nothing worked to rescan the devices or controllers and result in the OS ‘seeing’ the external drives again.

I’ve never needed it, but apparently there is a way:

A similar concept is possible for devices on the PCI bus:

Thanks; I’ll read the articles. The first one I encountered previously, and I couldn’t get anything to work following that article. But I’ll reread and read the second reference too.

Forgot to say, I tried in vain to use udevadm and partprobe to ‘reread’ the USB devices or to reinitialize the USB controllers, but nothing worked.

I’m going to consider this thread closed as the original question was about mounting file systems. That seems to be working fine so thanks to all of you for your very detailed and helpful guidance.

If I really need to rescan USB devices, I’ll pursue that issue later, and I can always post a separate thread if necessary.

1 Like

It appears that I can only select one comment as ‘the solution’. Many of your comments were great and I would consider them to be part of the solution. It would be great if I could select multiple answers so you gents could get ‘credit’ for a good answer and also so others reading this would understand that there were many accurate details in many of the posts.

2 Likes