0

I have /var/log as a btrfs filesystem in a separate partition from root. I'm using snapshots for update and will later rollback.

# mount
/dev/sda2 on / type btrfs (rw,relatime,ssd,subvol=@)
/dev/sda1 on /boot type ext2 (rw,relatime)
/dev/sda2 on /home type btrfs (rw,relatime,ssd,subvol=@home)
/dev/sda3 on /var/log type btrfs (rw,relatime,ssd)

# fstab
# / was on /dev/sda2 during installation
LABEL=root      /               btrfs   relatime,ssd,subvol=@ 0       1
# /boot was on /dev/sda1 during installation
LABEL=boot      /boot           ext2    relatime        0       2
# /home was on /dev/sda2 during installation
LABEL=root      /home           btrfs   relatime,ssd,subvol=@home 0       2
# /var/log was on /dev/sda3 during installation
LABEL=log       /var/log        btrfs   relatime,ssd    0       2

Everything works fine for my root partition, the problem is with my log partition. Any snapshots I create in /var/log are visible in the /var/log directory and I can't figure out how to rollback the /var/log snapshot. I like the way the root partition hides the subvols and I'd like to do the same for log partition.

Here's my root and log partitions with some snapshots

[~]$ sudo btrfs subvolume list /
ID 257 gen 3165 top level 5 path @
ID 258 gen 3142 top level 5 path @home
ID 262 gen 2086 top level 5 path fr-root
ID 263 gen 2086 top level 5 path fr-home
[~]$ sudo btrfs subvolume list /var/log
ID 257 gen 519 top level 5 path fr-log

Since there is no '@log' to create the fr-log snapshot i had to:

sudo mount -L log /mnt/up
sudo btrfs subvolume snapshot /var/log /mnt/up/fr-log

Instead of creating from the mount like I did for root:

sudo mount -L root /mnt/up
sudo btrfs subvolume snapshot /mnt/up/@ /mnt/up/fr-root

I tried the steps here Creating btrfs subvolume like @ or @home but my edits to fstab would cause the box to fail on boot.

1

Here's the way I got the needed results from my preseed in-target install script:

# create @log subvolume for mounting /var/log
# this is kludgy but since preseed didn't provide a way...
# this the only way i could create a hidden '@' handle for the /var/log partition 
if [ ! -d /mnt ]; then mkdir /mnt; fi
mount -L log /mnt
btrfs subvolume create /mnt/@log
mv -f /var/log/* /mnt/@log/ || true
umount /mnt
while read -r line
do
    if [[ "$line" =~ "LABEL=log" ]]; then
        echo "LABEL=log       /var/log        btrfs   relatime,ssd,subvol=@log    0       2" >> /tmp/fstab
    else
        echo "$line" >> /tmp/fstab
    fi
done < /etc/fstab
cp -v /tmp/fstab /etc/fstab
btrfs subvolume list /
btrfs subvolume list /var/log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.