QEMU / VirtManager in combination with btrfs and Timeshift

Hi!

I recently switched to Fedora. (Fedora 36 GNOME). I manually partitioned my ssd: btrfs with @/ and @/home.
To backup my system I use Timeshift. Only @/ is backuped.

Now I installed QEMU and VirtManager and saw, that all the files are on @/. (Formerly I used Virtualbox and there was a folder in $HOME for that…)

I moved the qcow2-images in my $HOME folder. But the other things are still in @/.

The snapshots I do with VirtManager are stored in this qcow2-files, so the snapshots itself are in my $HOME-folder, is that right?

I’m afraid, that a rollback with timeshift could make problems to the configuration of the virtual machines or the snapshots (I saw xml-snapshot-files in a subfolder of /var/lib/libvirt. That is necessary to know which snapshots are done in the qcow2-image, am I right?)

What should I do further, to avoid problems with a timeshift-rollback?

Thank you very much in advance!

IMO, the easiest solution is to create a subvolume where the VMs are stored by default. That will exclude that location from your snapshots since it will be in a separate subvol.

1 Like

I already considered that. But I already moved the qcow2 files to a separate folder in $HOME. So it wouldn’t make a difference I think.

But my question is, if there are any other files, where changes could break the VM.

If I would do a rollback with timeshift, all data except the qcow2 files would set to a former state. And I am afraid, that there could be problems.

E.g. when I did a VM-snapshot and do a timeshift-rollback to a timeshift-snapshot from before the VM-snapshot was done, the VM-snapshot is in the qcow2 file but the VM-snapshot-xml-file in /var/lib/libvirt/qemu/snapshot/VMNAME is removed. That would be a problem, or not? Are there other files which could make problems?

Thank you in advance!

I don’t know which exact files matter for VMs. I have /var/lib/libvirt in a different subvolume so I don’t have to worry about it.

How can I do this retrospectively?

Not tested but something like:

  • Shutdown libvirt and all VMs
  • mv /var/lib/libvirt /var/lib/libvirt-old
  • btrfs subvolume create /var/lib/libvirt
  • mv /var/lib/libvirt-old/* /var/lib/libvirt/.
  • rmdir /var/lib/libvirt-old

Thank you very much. Your commands have worked!

After executing them, I have run sudo btrfs subvolume list / and the result was:

ID 256 gen 5964 top level 5 path @home
ID 257 gen 5964 top level 5 path @
ID 258 gen 5935 top level 257 path var/lib/machines
ID 263 gen 5957 top level 257 path var/lib/libvirt
ID 264 gen 5940 top level 5 path timeshift-btrfs/snapshots/2022-08-15_12-47-40/@

It seems that var/lib/machines was already created automatically. But there are only the qcow2 images in it. Now the whole libvirt is excluded from changes by timeshift.

Timeshift does only snapshots of root, right? All other subvolumes are excluded except of home, when you set the checkbox “Include @home” (I didn’t set it…)
I wonder only because there is no other checkbox except for the inclusion of home subvolume.

1 Like

Yes. Specifically, it only takes a snapshot of the subvolume named @ and optionally @home

Ok, that’s good, thank you!

But now I have another problem: the libvirtd.service doesn’t start anymore at startup. I did a sudo systemctl enable libvirtd and sudo systemctl start libvirtd but after restart it’s again inactive (dead):

[XXX@YYY ~]$ sudo systemctl status libvirtd
[sudo] Passwort für XXX: 
○ libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)
     Active: inactive (dead)
TriggeredBy: ○ libvirtd-ro.socket
             ○ libvirtd-tcp.socket
             ○ libvirtd.socket
             ○ libvirtd-admin.socket
             ○ libvirtd-tls.socket
       Docs: man:libvirtd(8)
             https://libvirt.org

The VMs doesn’t start anymore, because the default network hasn’t started.

After a sudo systemctl start libvirtd it’s:

[XXX@YYY ~]$ sudo systemctl status libvirtd
● libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2022-08-15 14:22:13 CEST; 2s ago
TriggeredBy: ● libvirtd-ro.socket
             ○ libvirtd-tcp.socket
             ● libvirtd.socket
             ● libvirtd-admin.socket
             ○ libvirtd-tls.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
   Main PID: 3523 (libvirtd)
      Tasks: 19 (limit: 32768)
     Memory: 50.4M
        CPU: 757ms
     CGroup: /system.slice/libvirtd.service
             └─ 3523 /usr/sbin/libvirtd --timeout 120

And the default Network isn’t active, VMs doesn’t start.

How can I repair that? Before the creation of subvolume it worked…

There are some other interesting things:

Aug 15 14:22:12 YYY systemd[1]: Starting libvirtd.service - Virtualization daemon...
Aug 15 14:22:13 YYY systemd[1]: Started libvirtd.service - Virtualization daemon.
Aug 15 14:22:13 YYY libvirtd[3523]: libvirt version: 8.1.0, package: 2.fc36 (Fedora Project, 2022-03-13-01:12:58, )
Aug 15 14:22:13 YYY libvirtd[3523]: hostname: YYY
Aug 15 14:22:13 YYY libvirtd[3523]: Interner Fehler: Untergeordneter Prozess (VIR_BRIDGE_NAME=virbr0 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper) unerwartet Ende Status 3:
                                           dnsmasq: cannot read /var/lib/libvirt/dnsmasq/default.conf: Permission denied

Maybe SELinux?

Try:

sudo restorecon -R /var/lib/libvirt
1 Like

Are you as an user in the group libvirt ?

This could cause the “Permission denied” ?!

1 Like

Thank you for the advices! I already found a post in a forum and that was the solution for me:

Just as an addition, if you really want a stress free bridge to use with libvirt:

1 Like

Thank you, but now it works and you know: Never touch a running system!

1 Like

Nothing is more constant than changes, especially on a fast growing project as Fedora Linux.

Bookmark the link, just in case :grin:

2 Likes

Hi!

I have a big problem! I had to restore a Timeshift-Snapshot because of problems with the video-driver and now my whole /var/lib/libvirt folder is empty!

Timeshift had only to change @, not @home or @vm.
But @vm does not appear anymore in the subvolumes list:

sudo btrfs subvolume list /

results in:

ID 256 gen 83183 top level 5 path @home
ID 257 gen 83178 top level 5 path timeshift-btrfs/snapshots/2022-12-15_18-16-50/@
ID 258 gen 82703 top level 257 path timeshift-btrfs/snapshots/2022-12-15_18-16-50/@/var/lib/machines
ID 263 gen 82703 top level 257 path timeshift-btrfs/snapshots/2022-12-15_18-16-50/@/var/lib/libvirt
ID 265 gen 82674 top level 5 path timeshift-btrfs/snapshots/2022-08-16_12-40-58/@
ID 270 gen 82674 top level 5 path timeshift-btrfs/snapshots/2022-09-08_10-12-19/@
ID 277 gen 82674 top level 5 path timeshift-btrfs/snapshots/2022-10-16_13-00-02/@
ID 282 gen 82674 top level 5 path timeshift-btrfs/snapshots/2022-11-16_19-00-01/@
ID 285 gen 82674 top level 5 path timeshift-btrfs/snapshots/2022-12-02_18-00-02/@
ID 286 gen 83178 top level 5 path timeshift-btrfs/snapshots/2022-12-09_20-00-01/@
ID 287 gen 83183 top level 5 path @

And the commands as seen result in:

$ sudo systemctl start libvirtd
$ sudo systemctl status libvirtd
○ libvirtd.service - Virtualization daemon
     Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)
     Active: inactive (dead) since Thu 2022-12-15 22:21:10 CET; 4s ago
TriggeredBy: ○ libvirtd-tcp.socket
             ● libvirtd-admin.socket
             ● libvirtd.socket
             ● libvirtd-ro.socket
             ○ libvirtd-tls.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
    Process: 5907 ExecStart=/usr/sbin/libvirtd $LIBVIRTD_ARGS (code=exited, status=0/SUCCESS)
   Main PID: 5907 (code=exited, status=0/SUCCESS)
        CPU: 86ms

Dez 15 22:21:10 pc systemd[1]: Starting libvirtd.service - Virtualization daemon...
Dez 15 22:21:10 pc systemd[1]: Started libvirtd.service - Virtualization daemon.
Dez 15 22:21:10 pc libvirtd[5907]: libvirt version: 8.1.0, package: 2.fc36 (Fedora Project, 2022-03-13-01:12:58, )
Dez 15 22:21:10 pc libvirtd[5907]: hostname: pc
Dez 15 22:21:10 pc libvirtd[5907]: Failed to create lib dir /var/lib/libvirt/qemu: Die Operation ist nicht erlaubt
Dez 15 22:21:10 pc libvirtd[5907]: Initialisierung des QEMU Status-Treibers fehlgeschlagen: Failed to create lib dir /var/lib/libvirt/qemu: Die Operation ist nicht erlaubt
Dez 15 22:21:10 pc libvirtd[5907]: Treiber Status Initialisierung fehlgeschlagen
Dez 15 22:21:10 pc systemd[1]: libvirtd.service: Deactivated successfully.

Please help!! I need my virtual machines…

Thank you very much in advance!

Mount the root of your btrfs partition. It will be something like this.

sudo mount /dev/<mydevice> /mnt -o subvolid=5

Then move the nested subvol out of the snapshot.

sudo mv /mnt/timeshift-btrfs/snapshots/2022-12-15_18-16-50/@/var/lib/libvirt /mnt/@/var/lib/libvirt

Hi dalto!

Thanks for your response!

Can you please explain, what to write instead of " <mydevice> "?

If I run lsblk the relevant part is:

nvme0n1     259:0    0 476,9G  0 disk 
├─nvme0n1p1 259:1    0 476,8M  0 part /boot/efi
└─nvme0n1p2 259:2    0 476,5G  0 part /run/timeshift/backup
                                      /home
                                      /

I tried sudo mount /dev/nvme0n1p2 /mnt -o subvolid=257 but then in /mnt is the whole content of the snapshot, it looks like /. (There is libvirt NOT empty, what is a good news…)
So I can’t execute sudo mv /mnt/timeshift-btrfs/snapshots/2022-12-15_18-16-50/@/var/lib/libvirt /mnt/@/var/lib/libvirt because “there is no such file or directory…”

I tried sudo mount /dev/nvme0n1 /mnt -o subvolid=257 too, but that didn’t work…

Thank you in advance!!

It should be subvolid=5. You want to mount the root of the filesystem which will have all the subvolumes in it.

You want to ensure the OS treats the mv command as being within a single filesystem.