Antynea / grub-btrfs

Include btrfs snapshots at boot options. (Grub menu)
GNU General Public License v3.0
780 stars 78 forks source link

Snapshot description is wrong #40

Closed ckotte closed 6 years ago

ckotte commented 6 years ago

The description of some snapshots is wrong. In this specific example, the description of all snapshots is just timeline. Sometimes just a few snapshots aren't named correctly.

$ sudo snapper ls
Type   | # | Pre # | Date                          | User | Cleanup  | Description                                                                 | Userdata
-------+---+-------+-------------------------------+------+----------+-----------------------------------------------------------------------------+---------
single | 0 |       |                               | root |          | current                                                                     |         
single | 1 |       | Fri 30 Mar 2018 23:31:44 CEST | root |          | test123                                                                     |         
pre    | 2 |       | Fri 30 Mar 2018 23:46:15 CEST | root | number   | pacman -Ud /home/vagrant/.cache/pacaur/grub-btrfs/grub-btrfs-2.0.1-1-any... |         
post   | 3 | 2     | Fri 30 Mar 2018 23:46:17 CEST | root | number   | grub-btrfs                                                                  |         
single | 4 |       | Sat 31 Mar 2018 00:00:27 CEST | root | timeline | timeline                                                                    |         
single | 5 |       | Sat 31 Mar 2018 13:10:45 CEST | root | timeline | timeline                                                                    |         
pre    | 6 |       | Sun 01 Apr 2018 13:14:23 CEST | root | number   | pacman -Syu                                                                 |         
post   | 7 | 6     | Sun 01 Apr 2018 13:15:22 CEST | root | number   | gtk-update-icon-cache gtk3 linux linux-headers mpg123 openssl srt unrar ... |     
$ sudo grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found theme: /boot/grub/themes/Vimix/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Auto-detect Start - ######
# Found snapshot: 2018-04-01 13:15:22 | @/.snapshots/7/snapshot      | single | timeline
# Found snapshot: 2018-04-01 13:14:23 | @/.snapshots/6/snapshot      | single | timeline
# Found snapshot: 2018-03-31 13:10:45 | @/.snapshots/5/snapshot      | single | timeline
# Found snapshot: 2018-03-31 00:00:27 | @/.snapshots/4/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:46:17 | @/.snapshots/3/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:46:15 | @/.snapshots/2/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:31:44 | @/.snapshots/1/snapshot      | single | timeline
# Found 7 snapshot(s)
###### - Grub-btrfs: Auto-detect End   - ######
done

However, the assignment of the snapshots is correct. If I boot into snapshot #6 for example, the old kernel is loaded.

maximbaz commented 6 years ago

Attach please also the output of the following commands, it will help the investigation.

  1. $ sudo snapper -t 0 list -a | tail -n +3
  2. $ sudo btrfs subvolume list -sa --sort=-rootid /

If you want to debug yourself, these variables are getting the wrong values, need to understand why:

https://github.com/Antynea/grub-btrfs/blob/1b40cfee20ffb434f037ed171886947bc9241c52/41_snapshots-btrfs#L314-L315

ckotte commented 6 years ago

sudo snapper -t 0 list -a | tail -n +3 prints out all lines except the first line !?

It looks like the description is taken from the snapshots of /home or /var instead of /.

$ sudo snapper -t 0 list -a
Config: home, subvolume: /home
Type   | #  | Pre # | Date                          | User | Cleanup  | Description                                                                 | Userdata
-------+----+-------+-------------------------------+------+----------+-----------------------------------------------------------------------------+---------
single | 0  |       |                               | root |          | current                                                                     |         
single | 1  |       | Sat 31 Mar 2018 00:00:27 CEST | root | timeline | timeline                                                                    |         
single | 3  |       | Sat 31 Mar 2018 14:00:25 CEST | root | timeline | timeline                                                                    |         
single | 4  |       | Sat 31 Mar 2018 15:00:25 CEST | root | timeline | timeline                                                                    |         
single | 5  |       | Sat 31 Mar 2018 16:00:25 CEST | root | timeline | timeline                                                                    |         
single | 6  |       | Sat 31 Mar 2018 17:00:25 CEST | root | timeline | timeline                                                                    |         
single | 7  |       | Sat 31 Mar 2018 18:00:25 CEST | root | timeline | timeline                                                                    |         
single | 8  |       | Sat 31 Mar 2018 19:00:25 CEST | root | timeline | timeline                                                                    |         
single | 9  |       | Sun 01 Apr 2018 01:02:01 CEST | root | timeline | timeline                                                                    |         
single | 10 |       | Sun 01 Apr 2018 12:37:49 CEST | root | timeline | timeline                                                                    |         
pre    | 11 |       | Sun 01 Apr 2018 12:55:14 CEST | root | number   | pacman -Ud /home/vagrant/.cache/pacaur/snap-pac-grub/snap-pac-grub-1.0.2... |         
post   | 12 | 11    | Sun 01 Apr 2018 12:55:16 CEST | root | number   | snap-pac-grub                                                               |         
single | 13 |       | Sun 01 Apr 2018 13:00:10 CEST | root | timeline | timeline                                                                    |         
single | 16 |       | Sun 01 Apr 2018 14:00:39 CEST | root | timeline | timeline                                                                    |         

Config: root, subvolume: /
Type   | #  | Pre # | Date                          | User | Cleanup  | Description                                                                 | Userdata     
-------+----+-------+-------------------------------+------+----------+-----------------------------------------------------------------------------+--------------
single | 0  |       |                               | root |          | current                                                                     |              
single | 1  |       | Fri 30 Mar 2018 23:31:44 CEST | root |          | test123                                                                     |              
pre    | 2  |       | Fri 30 Mar 2018 23:46:15 CEST | root | number   | pacman -Ud /home/vagrant/.cache/pacaur/grub-btrfs/grub-btrfs-2.0.1-1-any... |              
post   | 3  | 2     | Fri 30 Mar 2018 23:46:17 CEST | root | number   | grub-btrfs                                                                  |              
single | 4  |       | Sat 31 Mar 2018 00:00:27 CEST | root | timeline | timeline                                                                    |              
single | 5  |       | Sat 31 Mar 2018 13:10:45 CEST | root | timeline | timeline                                                                    |              
pre    | 6  |       | Sun 01 Apr 2018 13:14:23 CEST | root | number   | pacman -Syu                                                                 |              
post   | 7  | 6     | Sun 01 Apr 2018 13:15:22 CEST | root | number   | gtk-update-icon-cache gtk3 linux linux-headers mpg123 openssl srt unrar ... |              
single | 8  |       | Sun 01 Apr 2018 14:00:39 CEST | root | timeline | timeline                                                                    |              
single | 9  |       | Sun 01 Apr 2018 14:06:52 CEST | root | number   | rollback backup                                                             | important=yes
single | 10 |       | Sun 01 Apr 2018 14:06:52 CEST | root |          |                                                                             |              

Config: var, subvolume: /var
Type   | #  | Pre # | Date                          | User | Cleanup  | Description                                                                 | Userdata
-------+----+-------+-------------------------------+------+----------+-----------------------------------------------------------------------------+---------
single | 0  |       |                               | root |          | current                                                                     |         
single | 1  |       | Sat 31 Mar 2018 00:00:28 CEST | root | timeline | timeline                                                                    |         
single | 3  |       | Sat 31 Mar 2018 14:00:25 CEST | root | timeline | timeline                                                                    |         
single | 4  |       | Sat 31 Mar 2018 15:00:25 CEST | root | timeline | timeline                                                                    |         
single | 5  |       | Sat 31 Mar 2018 16:00:25 CEST | root | timeline | timeline                                                                    |         
single | 6  |       | Sat 31 Mar 2018 17:00:25 CEST | root | timeline | timeline                                                                    |         
single | 7  |       | Sat 31 Mar 2018 18:00:25 CEST | root | timeline | timeline                                                                    |         
single | 8  |       | Sat 31 Mar 2018 19:00:25 CEST | root | timeline | timeline                                                                    |         
single | 9  |       | Sun 01 Apr 2018 01:02:01 CEST | root | timeline | timeline                                                                    |         
single | 10 |       | Sun 01 Apr 2018 12:37:49 CEST | root | timeline | timeline                                                                    |         
pre    | 11 |       | Sun 01 Apr 2018 12:55:14 CEST | root | number   | pacman -Ud /home/vagrant/.cache/pacaur/snap-pac-grub/snap-pac-grub-1.0.2... |         
post   | 12 | 11    | Sun 01 Apr 2018 12:55:16 CEST | root | number   | snap-pac-grub                                                               |         
single | 13 |       | Sun 01 Apr 2018 13:00:10 CEST | root | timeline | timeline                                                                    |         
pre    | 14 |       | Sun 01 Apr 2018 13:14:23 CEST | root | number   | pacman -Syu                                                                 |         
post   | 15 | 14    | Sun 01 Apr 2018 13:15:23 CEST | root | number   | gtk-update-icon-cache gtk3 linux linux-headers mpg123 openssl srt unrar ... |         
single | 16 |       | Sun 01 Apr 2018 14:00:39 CEST | root | timeline | timeline                                                                    |         
[vagrant@genesis ansible-linux]$ sudo btrfs subvolume list -sa --sort=-rootid /
ID 342 gen 1207 cgen 1203 top level 277 otime 2018-04-01 14:06:52 path <FS_TREE>/@/.snapshots/10/snapshot
ID 341 gen 1202 cgen 1202 top level 277 otime 2018-04-01 14:06:52 path <FS_TREE>/@/.snapshots/9/snapshot
ID 340 gen 1195 cgen 1194 top level 274 otime 2018-04-01 14:00:39 path <FS_TREE>/@var/.snapshots/16/snapshot
ID 339 gen 1193 cgen 1193 top level 277 otime 2018-04-01 14:00:39 path <FS_TREE>/@/.snapshots/8/snapshot
ID 338 gen 1192 cgen 1192 top level 273 otime 2018-04-01 14:00:39 path <FS_TREE>/@home/.snapshots/16/snapshot
ID 336 gen 1137 cgen 1136 top level 274 otime 2018-04-01 13:15:23 path <FS_TREE>/@var/.snapshots/15/snapshot
ID 335 gen 1135 cgen 1134 top level 277 otime 2018-04-01 13:15:22 path <FS_TREE>/@/.snapshots/7/snapshot
ID 333 gen 1132 cgen 1131 top level 274 otime 2018-04-01 13:14:23 path <FS_TREE>/@var/.snapshots/14/snapshot
ID 332 gen 1203 cgen 1130 top level 277 otime 2018-04-01 13:14:23 path <FS_TREE>/@/.snapshots/6/snapshot
ID 331 gen 1122 cgen 1121 top level 274 otime 2018-04-01 13:00:10 path <FS_TREE>/@var/.snapshots/13/snapshot
ID 329 gen 1119 cgen 1119 top level 273 otime 2018-04-01 13:00:10 path <FS_TREE>/@home/.snapshots/13/snapshot
ID 328 gen 1112 cgen 1112 top level 273 otime 2018-04-01 12:55:16 path <FS_TREE>/@home/.snapshots/12/snapshot
ID 327 gen 1112 cgen 1111 top level 274 otime 2018-04-01 12:55:16 path <FS_TREE>/@var/.snapshots/12/snapshot
ID 325 gen 1109 cgen 1109 top level 273 otime 2018-04-01 12:55:14 path <FS_TREE>/@home/.snapshots/11/snapshot
ID 324 gen 1109 cgen 1108 top level 274 otime 2018-04-01 12:55:14 path <FS_TREE>/@var/.snapshots/11/snapshot
ID 322 gen 1095 cgen 1094 top level 274 otime 2018-04-01 12:37:49 path <FS_TREE>/@var/.snapshots/10/snapshot
ID 320 gen 1092 cgen 1092 top level 273 otime 2018-04-01 12:37:49 path <FS_TREE>/@home/.snapshots/10/snapshot
ID 319 gen 1058 cgen 1057 top level 274 otime 2018-04-01 01:02:01 path <FS_TREE>/@var/.snapshots/9/snapshot
ID 317 gen 1055 cgen 1055 top level 273 otime 2018-04-01 01:02:01 path <FS_TREE>/@home/.snapshots/9/snapshot
ID 316 gen 1034 cgen 1033 top level 274 otime 2018-03-31 19:00:25 path <FS_TREE>/@var/.snapshots/8/snapshot
ID 314 gen 1031 cgen 1031 top level 273 otime 2018-03-31 19:00:25 path <FS_TREE>/@home/.snapshots/8/snapshot
ID 313 gen 1026 cgen 1025 top level 274 otime 2018-03-31 18:00:25 path <FS_TREE>/@var/.snapshots/7/snapshot
ID 311 gen 1023 cgen 1023 top level 273 otime 2018-03-31 18:00:25 path <FS_TREE>/@home/.snapshots/7/snapshot
ID 308 gen 1011 cgen 1010 top level 274 otime 2018-03-31 17:00:25 path <FS_TREE>/@var/.snapshots/6/snapshot
ID 306 gen 1008 cgen 1008 top level 273 otime 2018-03-31 17:00:25 path <FS_TREE>/@home/.snapshots/6/snapshot
ID 305 gen 993 cgen 992 top level 274 otime 2018-03-31 16:00:25 path <FS_TREE>/@var/.snapshots/5/snapshot
ID 303 gen 990 cgen 990 top level 273 otime 2018-03-31 16:00:25 path <FS_TREE>/@home/.snapshots/5/snapshot
ID 302 gen 971 cgen 970 top level 274 otime 2018-03-31 15:00:25 path <FS_TREE>/@var/.snapshots/4/snapshot
ID 300 gen 968 cgen 968 top level 273 otime 2018-03-31 15:00:25 path <FS_TREE>/@home/.snapshots/4/snapshot
ID 297 gen 950 cgen 949 top level 274 otime 2018-03-31 14:00:25 path <FS_TREE>/@var/.snapshots/3/snapshot
ID 295 gen 947 cgen 947 top level 273 otime 2018-03-31 14:00:25 path <FS_TREE>/@home/.snapshots/3/snapshot
ID 289 gen 921 cgen 920 top level 277 otime 2018-03-31 13:10:45 path <FS_TREE>/@/.snapshots/5/snapshot
ID 285 gen 914 cgen 913 top level 274 otime 2018-03-31 00:00:28 path <FS_TREE>/@var/.snapshots/1/snapshot
ID 284 gen 913 cgen 912 top level 277 otime 2018-03-31 00:00:27 path <FS_TREE>/@/.snapshots/4/snapshot
ID 283 gen 912 cgen 911 top level 273 otime 2018-03-31 00:00:27 path <FS_TREE>/@home/.snapshots/1/snapshot
ID 282 gen 906 cgen 905 top level 277 otime 2018-03-30 23:46:17 path <FS_TREE>/@/.snapshots/3/snapshot
ID 281 gen 905 cgen 904 top level 277 otime 2018-03-30 23:46:15 path <FS_TREE>/@/.snapshots/2/snapshot
ID 280 gen 896 cgen 895 top level 277 otime 2018-03-30 23:31:44 path <FS_TREE>/@/.snapshots/1/snapshot
maximbaz commented 6 years ago

sudo snapper -t 0 list -a | tail -n +3 prints out all lines except the first line !?

That's to skip the table header, that part is fine. However what's interesting is that in your configuration you have multiple tables, you have multiple directories where snapshots reside, and that is currently unsupported.

However, the fix is quite easy, I'll make a PR and ping you, you can do the same modifications locally to test if it solves the issue.

ckotte commented 6 years ago

Yes, I have three subvolumes with snapshots. Ok, thanks. I will wait for your response.

maximbaz commented 6 years ago

And ready 🙂

ckotte commented 6 years ago

that was fast :) Dumb question. Why do you added the fix to a branch in a fork of your own repo instead of creating a branch in this repo?

maximbaz commented 6 years ago

I implemented the support for snapper in this project, so I know the relevant parts of the code, but I'm not the owner of this repo so I can't actually create branches or push to master in this repo directly 🙂 We would need @Antynea to review and merge the PR.

Could you confirm that the change in PR fixes your issue?

ckotte commented 6 years ago

Yeah, right. I tested your fix and it works!

$ sudo snapper ls
Type   | #  | Pre # | Date                          | User | Cleanup  | Description                                                                 | Userdata     
-------+----+-------+-------------------------------+------+----------+-----------------------------------------------------------------------------+--------------
single | 0  |       |                               | root |          | current                                                                     |              
single | 1  |       | Fri 30 Mar 2018 23:31:44 CEST | root |          | test123                                                                     |              
pre    | 2  |       | Fri 30 Mar 2018 23:46:15 CEST | root | number   | pacman -Ud /home/vagrant/.cache/pacaur/grub-btrfs/grub-btrfs-2.0.1-1-any... |              
post   | 3  | 2     | Fri 30 Mar 2018 23:46:17 CEST | root | number   | grub-btrfs                                                                  |              
single | 4  |       | Sat 31 Mar 2018 00:00:27 CEST | root | timeline | timeline                                                                    |              
single | 5  |       | Sat 31 Mar 2018 13:10:45 CEST | root | timeline | timeline                                                                    |              
pre    | 6  |       | Sun 01 Apr 2018 13:14:23 CEST | root | number   | pacman -Syu                                                                 |              
post   | 7  | 6     | Sun 01 Apr 2018 13:15:22 CEST | root | number   | gtk-update-icon-cache gtk3 linux linux-headers mpg123 openssl srt unrar ... |              
single | 8  |       | Sun 01 Apr 2018 14:00:39 CEST | root | timeline | timeline                                                                    |              
single | 9  |       | Sun 01 Apr 2018 14:06:52 CEST | root | number   | rollback backup                                                             | important=yes
single | 10 |       | Sun 01 Apr 2018 14:06:52 CEST | root |          |                                                                             |              
single | 11 |       | Sun 01 Apr 2018 15:00:33 CEST | root | timeline | timeline                                                                    |              
pre    | 12 |       | Sun 01 Apr 2018 15:32:39 CEST | root | number   | pacman -S tree                                                              |              
post   | 13 | 12    | Sun 01 Apr 2018 15:32:42 CEST | root | number   | tree                                                                        |              
single | 14 |       | Sun 01 Apr 2018 16:00:33 CEST | root | timeline | timeline                                                                    |              
$ sudo grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found theme: /boot/grub/themes/Vimix/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Auto-detect Start - ######
# Found snapshot: 2018-04-01 16:00:33 | @/.snapshots/14/snapshot     | single | timeline
# Found snapshot: 2018-04-01 15:32:42 | @/.snapshots/13/snapshot     | post   | tree
# Found snapshot: 2018-04-01 15:32:39 | @/.snapshots/12/snapshot     | pre    | pacman -S tree
# Found snapshot: 2018-04-01 15:00:33 | @/.snapshots/11/snapshot     | single | timeline
# Found snapshot: 2018-04-01 14:06:52 | @/.snapshots/10/snapshot     | single | 
# Found snapshot: 2018-04-01 14:06:52 | @/.snapshots/9/snapshot      | single | rollback backup
# Found snapshot: 2018-04-01 14:00:39 | @/.snapshots/8/snapshot      | single | timeline
# Found snapshot: 2018-04-01 13:15:22 | @/.snapshots/7/snapshot      | post   | gtk-update-icon-cache gtk3 linux linux-headers mpg123 openssl srt unrar ...
# Found snapshot: 2018-04-01 13:14:23 | @/.snapshots/6/snapshot      | pre    | pacman -Syu
# Found snapshot: 2018-03-31 13:10:45 | @/.snapshots/5/snapshot      | single | timeline
# Found snapshot: 2018-03-31 00:00:27 | @/.snapshots/4/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:46:17 | @/.snapshots/3/snapshot      | post   | grub-btrfs
# Found snapshot: 2018-03-30 23:46:15 | @/.snapshots/2/snapshot      | pre    | pacman -Ud /home/vagrant/.cache/pacaur/grub-btrfs/grub-btrfs-2.0.1-1-any...
# Found snapshot: 2018-03-30 23:31:44 | @/.snapshots/1/snapshot      | single | test123
# Found 14 snapshot(s)
###### - Grub-btrfs: Auto-detect End   - ######