QEMU / VirtManager in combination with btrfs and Timeshift

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.

Thank you, now I can mount it correctly, but moving is not possible, I get the message:

udo mv /mnt/timeshift-btrfs/snapshots/2022-12-15_18-16-50/@/var/lib/libvirt /mnt/@/var/lib/libvirt
mv: das Verschieben von '/mnt/timeshift-btrfs/snapshots/2022-12-15_18-16-50/@/var/lib/libvirt' nach '/mnt/@/var/lib/libvirt/libvirt' ist nicht möglich: Die Operation ist nicht erlaubt

What could be the problem? What could be the solution?

Thanks in advance!!

Try this:

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

That was the solution! Thank you so much!! You saved my weekend. (or even more…) I already was afraid to have to reinstall all machines…

1 Like