0

How to automount a partition of a USB stick at /media/lubuntu/name every time the stick is plugged into the PC when the /etc/fstab file is empty on every new boot? I assume this is because I'm running a persistent live lubuntu 22.04 made with mkusb (dus method) and /etc/fstab is not a part of persistence

What I've tried and did not work:

  1. edit /etc/fstab with UUID=0123 /media/lubuntu/name ntfs defaults 0 0
  2. edit ~/.bashrc with sudo mount -o rw,users,umask=000,exec UUID=0123 /media/lubuntu/name
  3. according to this question, making a custom /etc/fstab in a custom distro and burning that to the stick also won't work, because mkusb makes its own /etc/fstab

What 'kind of' works:

  1. If I edit the label of the partition to name the system automounts it to /media/lubuntu/name1, yet if I do this with a mmc card, it automounts to /media/lubuntu/name which I find confusing and would simply like to set this up myself
  2. if there is no label to the partition, the system automounts it to its UUID, a very long number, resulting in many confusing folders at /media/lubuntu/

Any help appreciated

andrej
  • 59
  • Please tell us a little more: 1. Which version of Lubuntu are you running (22.04.3 LTS or some other version)? 2. Has your USB pendrive been 'touched' by Windows? and in that case did you unmount it properly and if still connected when Windows was turned off, did you turn off Fast Startup in Windows? It is a kind of semi-hibernation and leaves the file system in a 'dirty' state. See this link. -- Mounting to .../name1 makes me think that it is mounted automatically before you mount it. – sudodus Feb 16 '24 at 15:36
  • Yes, I'm running Lubuntu 22.04.3 LTS and the USB drive has not been used in Windows yet. indeed it is mounted automatically when I insert it. I can manually unmount and then mount where I want, but then after reboot it will automount elsewhere again. Edit: The problem is that I'm not able to automount it where I would like and that is /media/lubuntu/name – andrej Feb 16 '24 at 17:57
  • I made a persistent live drive with Lubuntu 22.04.3 LTS using mkusb, the iso2usb method. After booting in a Dell Precision M4800 laptop I plugged in another USB with an MSDOS partition table and an NTFS file system (brand new, made using gparted in another computer). After plugging in, I ran lsblk -e7 -f in a wide terminal window, and the NTFS file system was automounted at /media/lubuntu/name, which matches what you want. This should work as long as you have not another file system mounted at that mountpoint. In that case it will use /media/lubuntu/name1. – sudodus Feb 16 '24 at 19:20
  • I 'ejected' the USB drive (with the file browser), unplugged it and the plugged it in again. And the NTFS file system was automounted at /media/lubuntu/name again. In other words, I cannot make Lubuntu act like you describe (unless I mount another file system with the same label). – sudodus Feb 16 '24 at 19:22
  • for me Lubuntu automounts ntfs partitions that do not have a label using their UUID at /media/lubuntu/[the UUID of the partition], e.g.: /media/lubuntu/1BDB2C441334A27. If the label of the partition is set to 'name' it will automount to /media/kubuntu/name but after reboot it will automount to /media/lubuntu/name1 and I assume this is because the folder /media/lubuntu/name is created in the filesystem and so THE SAME partition gets automounted on a different path because it wrongly assumes that a device is mounted at /media/lubuntu/name but it isn't, only the folder remains from previous boot – andrej Feb 16 '24 at 19:47
  • that is why I was trying to edit the /etc/fstab and thereby automount the ntfs partition to the desired path based on its unique UUID instead of its label. The label is not necessarily unique, especially if you have 2 drives of the same type, e.g. DataTraveller 3.0 or some other generic manufacturer name or you decide to chage the label in the future just for naming convenience – andrej Feb 16 '24 at 20:13
  • 1
    Please run the following commands and post the results by editing the original question (indent 4 spaces to render it as code): ls -l /media/lubuntu/; lsblk -e7 -o model,name,size,fstype,label,mountpoints -- You can do it before connecting the USB stick and after unplugging and after connecting it again. This may help understanding what is happening. – sudodus Feb 16 '24 at 20:38
  • perhaps I did not explain myself clear enough, but by automounting a ntfs partition to /media/lubuntu/name I mean automounting it to a path that I specify myself, e.g. /media/lubuntu/usbdatabackup or /media/lubuntu/tempbackup... and set Lubuntu up in a way it recognizes the partition when the device is plugged in and mounts the partition to that specified path. – andrej Feb 16 '24 at 20:39
  • 2
    I think the following link (that I found a few minutes ago) at LinuxQuestions.org may help you: [SOLVED] Auto mount usb drive – sudodus Feb 16 '24 at 21:28
  • 1
    I ran ls -l /media/lubuntu/ and found I have many empty (non-mounted) folders with root permissions in /media/lubuntu, so I've cleaned those with sudo rm -r. Honestly I do not know why this was heppening. Example: for a device with label PROJ, I would have /media/lubuntu/PROJ, /media/lubuntu/PROJ1, media/LUBUNTU/PROJ2, ... up to media/lubuntu/PROJ32, so every time the PROJ device automounted when inserted into the PC a folder with a number n+1 would be added. All those were owned by root, e.g.: => drwxr-xr-x 6 root root 4096 Feb 19 19:38 PROJ32 – andrej Feb 19 '24 at 20:24
  • 1
    then I followed the link from sudodus and did sudo nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla And add # at the start of line 2 Identity=unix-group:admin;unix-group:sudo changing it to #Identity=unix-group:admin;unix-group:sudo now the USB drive auto-mounts only with user permissions and ls -l /media/lubuntu/ outputs drwxrwxrwx 1 lubuntu lubuntu 4096 Feb 18 18:45 PROJ and so when it is unplugged, the folder /media/lubuntu/PROJ where it mounts is eleted and on succesivce mounts, it automounts to /media/lubuntu/PROJ again... so solved. – andrej Feb 19 '24 at 20:29
  • 1
    thank you sudodus, basically your link solved what I needed for now. Being unable to edit fstab file is quite limiting, but I'm grateful you helped find a workaround. You can post is as an aswer and I'll accept it. – andrej Feb 19 '24 at 20:33
  • I'm glad I could help you find a workaround :-) You have explained rather well how you solved the problem, and I suggest that you convert it to an answer (yes, answer your own question) and after a couple of days return to it and click the tick icon to accept it. That way other people with a similar problem can find it. – sudodus Feb 20 '24 at 10:04
  • By the way, there is an alternative that lets you use /etc/fstab. Use a portable installed system in the USB drive. This works particularly well, if you use an SSD (connected via USB), because it is not as sensitive to wear and corruption of the file system as a cheap USB pendrive. See this link, which describes how you can start with a compressed image of Ubuntu Server 'Jammy' (22.04.x LTS) and install lubuntu-desktop into it. – sudodus Feb 20 '24 at 10:18

0 Answers0