在另一个分区中创建类似“@”的子卷

在另一个分区中创建类似“@”的子卷

我将 /var/log 作为 btrfs 文件系统,放在与根目录不同的分区中。我使用快照进行更新,稍后将回滚。

# 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

我的根分区一切正常,问题出在我的日志分区上。我在 /var/log 中创建的任何快照都显示在 /var/log 目录中,我不知道如何回滚 /var/log 快照。我喜欢根分区隐藏子卷的方式,我想对日志分区做同样的事情。

这是我的根分区和日志分区以及一些快照

[~]$ 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

由于没有“@log”来创建 fr-log 快照,我必须:

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

而不是像我对 root 所做的那样从挂载处创建:

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

我尝试了这里的步骤创建 btrfs 子卷,如 @ 或 @home但是我对 fstab 的编辑会导致启动失败。

答案1

以下是我从预先植入的目标安装脚本中获取所需结果的方法:

# 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

相关内容