使用 BTRFS 和更多子卷安装 Ubuntu

使用 BTRFS 和更多子卷安装 Ubuntu

我想安装一个带有btrfs文件系统的 Ubuntu 服务器(以 RAID1 方式)。

问题是我在安装程序中看不到创建更多子卷的选项。安装程序默认创建两个:@@home,我还想分开@var,,@tmp...

有什么办法可以做到这一点吗?也许用 shell... 但我认为安装程序不理解的子卷功能btrfs,因此您无法在每个子卷中挂载每个分区...

答案1

在您完成初始安装后,更改这一点应该很容易。

  • 一个巧妙的方法是拍摄 的两个快照@,将它们分别命名为@var@tmp
  • 然后删除 中的所有内容@var(除了 ) ,然后将@var/var的内容移至并删除。 也一样。@var/var/*@var/*@var/var@tmp/tmp/
  • 然后/etc/fstab使用新的子卷挂载点进行修改/var/tmp
  • 重启。
  • 最后(我不太确定最后一点)您应该能够通过安装下的子卷(因此同一个子卷被安装两次,一次作为,一次作为)并删除和来删除@/var和的原始内容。@/tmp@/mnt//mnt/mnt/var/mnt/tmp

答案2

你是对的,安装程序不知道 BTRFS 子卷,对于 18.04 来说仍然如此。

使用单独的子卷/var/log/可以恢复快照/而不会丢失日志。

  • 照常进行服务器设置,在完成安装步骤,选择回去执行 shell
  • 列出所有目标文件系统:

    mount | grep target
    
    /dev/md-0 on /target type btrfs (rw,noatime,space_cache,subvolid=257,subvol=/@)
    /dev/md-0 on /target/home type btrfs (rw,noatime,space_cache,subvolid=258,subvol=/@home)
    proc on /target/proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /target/dev type devtmpfs (rw,nosuid,relatime,size=475608k,nr_inodes=118902,mode=755)
    
  • 在此示例中,记下 btrfs 设备/dev/dm-0

  • 现在卸载所有已挂载的文件系统。

    umount /target/dev
    umount /target/proc
    umount /target/boot/efi
    umount /target/home
    umount /target/
    
  • 安装您的平坦的btrfs 文件系统:

    cd /tmp
    mkdir work
    mount /dev/dm-0 work
    cd work
    
  • 验证安装是否正确(应该显示@@home):

    ls 
    
    @ @home
    
  • 创建附加子卷 ( @tmp, @var, @var-log)

    btrfs subvolume create @tmp
    btrfs subvolume create @var
    btrfs subvolume create @var-log
    
  • 移动数据

    mv @/var/log/* @var-log/
    mv @/var/* @var/
    
    # Remove data from tmp
    rm @/tmp/* @/tmp/.*
    
    # For 18.04, remove the swapfile since it won't work on btrfs
    rm @/swapfile
    
  • 将新的子卷添加到 fstab,设备部分可能与之前的挂载命令不同,从已经存在的挂载点复制设备部分。

    ...
    /dev/mapper/root-root /               btrfs   noatime,subvol=@ 0       1
    /dev/mapper/root-root /home           btrfs   noatime,subvol=@home 0       2
    /dev/mapper/root-root /var            btrfs   noatime,subvol=@var 0       2
    /dev/mapper/root-root /var/log        btrfs   noatime,subvol=@var-log 0       2
    
  • 卸载

    cd /tmp
    umount work
    sync
    
  • exit, 然后完成安装

  • 安装和配置鲷鱼,一个出色的自动化快照工具。

相关内容