How to change the hard drive and directory of installation of Gnome Boxes Virtual Machines?

Hi,
due to the nature of the Flatpak Sandbox, this is more difficult than one might think

Prepare the Drive for Usage

The first step is to partition/format/mount the 2nd Drive. I assume for this, that your 2nd Drive is called /dev/sdb (verify!).

Make yourself root

Run sudo bash then enter your password.

Partitioning

Run sgdisk --zap-all /dev/sdb to remove everything on the drive, then run gdisk /dev/sdb and create a new partition with Code 8300. Write the changes to the disk and exit.

Formatting

Run mkfs.ext4 -L scratch /dev/sdb1 to create a new Filesystem on the newly created partition and give it a name.

Automatically mount

Create a mountpoint like /var/scratch with mkdir /var/scratch. Now edit /etc/fstab and insert the following line:

LABEL=scratch /var/scratch ext4 defaults 0 0

This will make the OS mount the disk automatically at boot. Now mount the filesystem manually with mount -a

Create a personal directory on it

I strongly advise you to create a personal directory on the filesystem with the proper permisssions:

mkdir /var/scratch/myname
chown myname:users /var/scratch/myname
chmod -R 700 /var/scratch/myname

(replace myname with your actual username)

Link to it from your Home Directory

To make access to the filesystem more convenient, run:

ln -s /var/scratch/myname ~/scratch

This will create a symbolic link in your homedirectory to the filesystem on the 2nd drive

Allow Flatpak applications access to this location

Flatpak per default does not allow you to access this location. You have to manually override the permission to explicitly allow it:

flatpak override --user --filesystem=/var/scratch org.gnome.Boxes

This will allow Gnome Boxes access to the 2nd Drive

Move your Boxes

Gnome Boxes stores it’s files per default under:
~/.var/app/org.gnome.Boxes/data/gnome-boxes/images

You need to move this directory to your 2nd-Drive, e.g. to
/var/scratch/myname/images

Now the more complex part - we need to modify the configuration for two parts:

  1. The default storage location for creating new Boxes
  2. The storage location for already existing Boxes

Run:

flatpak run --command=sh org.gnome.Boxes

This will put you inside the Flatpak Sandbox for Gnome Boxes, but in a Shell. We have to use the virsh Tool to modify the necessary files, but unfortunately they rely on the Vi Editor, which is not available in the Sandbox, so we have to make a Quickhack. Run:

cp /bin/nano vi
export PATH=$PATH:.

This will copy the Nano-Editor which is available in the Sandbox to Vi and set the path to it. virsh is now happy and will let us edit the configuration files.
Run:

virsh pool-edit gnome-boxes

Modify the following line to set the default location for new images:

<path>/var/scratch/egon/Boxes</path>

Now save and exit (ctrl-X). Next, run the following command to list the names of all your currently created boxes:

virsh list --all

will give you something like:

 -    eos3.7-en   shut off
 -    win10       shut off

To edit the configuration for the Box, run: (replace the name)

virsh edit eos3.7-en

and edit the Line:

<source file='/var/scratch/egon/Boxes/eos3.7-en'/>

To point to the new location. Save and exit with Ctrl-X.

When everything has been done, you can run your Boxes again.

1 Like