How to attach a partition to a qube permanently/on startup

First we’ll use qvm-block to attach the the partition to the the qube in a persistent manner

qvm-block list the partitions

attach the partition to a qube

target qube: the qube you want to attach the partition to.

in dom0:
qvm-block attach --persistent <target-qube> <backend-qube>:<device-partition>

make the directory that you will use to mount the partition ( should be done inside the target qube):

it’s recommended that you do it inside the home directory since that is persistent between reboots

mkdir -p /path/to/directory

go into the template of the target qube and then type
sudo nano /etc/fstab

add the following line

/dev/disk/by-label/MY_LABEL /path/to/directory auto nosuid,nodev,nofail,x-gvfs-show 0 0

replace /dev/disk/by-label/MY_LABEL by the location of the your disk or uuid={your_partitions_uuid} , you can find the partition’s uuid using lsblk -f

https://wiki.archlinux.org/title/Fstab

https://man7.org/linux/man-pages/man5/fstab.5.html

I will probably come back to edit this for better readability when I’m less tired.

any suggestions or improvements welcome, this is just how I did it and I’m pretty new to qubes

I had the same kind of setup, but it broke with 4.3. Now, I don’t think it is a good idea. Qubes seems to use systemd services for this task.

What are the benefits of playing with /etc/fstab over using /rw/config/rc.local?

1 Like

If you use it in /etc/fstab every qube based on that template will have that in /etc and will try to run mount.
If you use /rw/config/rc.local it will try to mount only in that qube in which you do that.

3 Likes

benefits of using /etc/fstab over using /rw/config/rc.local

short answer: it just works, mounting in rc.local had loads of issues and bugs in my experience

long answer: I originally started off using rc.local, I put the same mount command that worked when run on bash, it did not work, no drive mounted.

then I put something something like

for i in $(seq 1 10); do
[ -b /dev/xvdi ] && break
sleep 1
done

before the mount command and then it actually mounted but I got all sort of errors, even though I could see the data in thunar and made sure it all had integrity , qbittorrent still didn’t recognize the files present and tried downloading them all instead of seeding, I didn’t want to re-implement the debian mounting software in rc.local so I just switched to /etc/hosts and it works no problems.

the only thread I could find about automounting partitions in the forum mentioned editing /etc/hosts in the template

I think it would be better to find the issue with the rc.local method, but it’s up to you.

1 Like

There is a combined method with systemd, rc.local and bind-dirs that works in app qubes and disposables and can be done per qube not per template.
If partition is not attached to qube it does nothing and there is no errors and qube starts/works as if nothing happened.

Of course you cannot persistently mount to numbered disposable but it can be done to disposable template or named disposable.

So first, you need to attach persistently block device to said qube.

Open dom0 terminal.

First you need to check list of available block devices:

qvm-block

for my testing it is sys-usb:sda3 partition attached to dvm-untrusted disposable template.

Persistent attachment (qube must not be running):

qvm-block attach --persistent dvm-untrusted sys-usb:sda3

dom0 terminal might be closed - it won’t be needed anymore

Now run said qube terminal (dvm-untrusted here), make mountpoint and bind-dir for systemd:

mkdir -p /home/user/.torrent
sudo mkdir -p /rw/bind-dirs/etc/systemd/system

Check UUID of partition to mount

systemd-mount --list

Now make home-user-.torrent.mount:

sudo geany /rw/bind-dirs/etc/systemd/system/home-user-.torrent.mount

put inside (UUID “F8EF-DD5A” is from systemd-mount --list)

[Unit]
Description=Mount block device to /home/user/.torrent
After=local-fs.target

[Mount]
What=/dev/disk/by-uuid/F8EF-DD5A
Where=/home/user/.torrent
Type=exfat
Options=defaults,uid=1000,gid=1000,sync,iocharset=utf8,errors=remount-ro,nodev,nosuid

[Install]
WantedBy=multi-user.target

Now, most important thing. Selinux will block this file from systemd, so it need to be added to systemd selinux context

sudo restorecon /rw/bind-dirs/etc/systemd/system/home-user-.torrent.mount

Now bind-dirs need to be configured.

sudo mkdir -p /rw/config/qubes-bind-dirs.d

make bind-dirs config

sudo geany /rw/config/qubes-bind-dirs.d/50-user.conf

and put inside

binds+=( '/etc/systemd/system/home-user-.torrent.mount' )

Then you either edit /rw/config/rc.local or make /rw/config/rc.local.d/persistent.rc executable file (I’ll show how to make this file - inside you put same command):

sudo mkdir -p /rw/config/rc.local.d
sudo geany /rw/config/rc.local.d/persistent.rc

inside:

systemctl start home-user-.torrent.mount

and make it executable

sudo chmod 0744 /rw/config/rc.local.d/persistent.rc


Now you might restart qube and have persistent attach auto mount of particular partition into qube.

1 Like

That’s the only error if the partition is not attached:

$ sudo journalctl -u home-user-.torrent.mount
Feb 22 20:42:42 dvm-untrusted systemd[1]: Dependency failed for home-user-.torrent.mount - Mount block device to /home/user/.torrent.
Feb 22 20:42:42 dvm-untrusted systemd[1]: home-user-.torrent.mount: Job home-user-.torrent.mount/start failed with result 'dependency'.

As for pure rc.local mounting, I use rc.local.d script in which I add my samba share to the fstab with echo, restart systemd and then use mount.