ZFS rpool 在启动时无法挂载

ZFS rpool 在启动时无法挂载

我的系统启动正常,但我试图解决几个与 ZFS 相关的启动错误,如下所示:

cannot mount '/root': directory is not empty
cannot mount '/var/cache': directory is not empty

凭借我的无限智慧,我将“rpool/var/cache /var/cache zfs defaults 0 0”添加到我的 fstab 中,我的系统无法重新启动,它将我踢到终端,在那里我可以从 fstab 中删除该行并重新启动我的系统。以下是 /etc/fstab 的当前状态:

rpool/var/log /var/log zfs defaults 0 0
rpool/var/tmp /var/tmp zfs defaults 0 0
/dev/zvol/rpool/swap none swap defaults 0 0

有一件奇怪的事情,在它重新启动后,它陷入了登录循环,我不得不进入终端,username按照主目录中的这些说明

现在 rpool 无法挂载,结果我的主目录中的文件夹以及所有文件都丢失了,因为我的许多系统文件夹都是从 rpool 继承的。我的 ZFS 如下所示:

$ zfs get mountpoint,mounted,canmount,overlay rpool -t filesystem -r
NAME               PROPERTY    VALUE                SOURCE
rpool              mountpoint  /                    local
rpool              mounted     no                   -
rpool              canmount    on                   local
rpool              overlay     off                  default
rpool/ROOT         mountpoint  none                 local
rpool/ROOT         mounted     no                   -
rpool/ROOT         canmount    off                  local
rpool/ROOT         overlay     off                  local
rpool/ROOT/ubuntu  mountpoint  /                    local
rpool/ROOT/ubuntu  mounted     yes                  -
rpool/ROOT/ubuntu  canmount    noauto               local
rpool/ROOT/ubuntu  overlay     off                  inherited from rpool/ROOT
rpool/home         mountpoint  /home                inherited from rpool
rpool/home         mounted     no                   -
rpool/home         canmount    on                   default
rpool/home         overlay     off                  default
rpool/home/greg    mountpoint  /home/greg           inherited from rpool
rpool/home/greg    mounted     yes                  -
rpool/home/greg    canmount    on                   default
rpool/home/greg    overlay     off                  default
rpool/home/root    mountpoint  /root                local
rpool/home/root    mounted     no                   -
rpool/home/root    canmount    on                   default
rpool/home/root    overlay     off                  default
rpool/srv          mountpoint  /srv                 inherited from rpool
rpool/srv          mounted     yes                  -
rpool/srv          canmount    on                   default
rpool/srv          overlay     off                  default
rpool/var          mountpoint  /var                 inherited from rpool
rpool/var          mounted     no                   -
rpool/var          canmount    off                  local
rpool/var          overlay     off                  default
rpool/var/cache    mountpoint  /var/cache           inherited from rpool
rpool/var/cache    mounted     yes                  -
rpool/var/cache    canmount    on                   default
rpool/var/cache    overlay     off                  default
rpool/var/games    mountpoint  /var/games           inherited from rpool
rpool/var/games    mounted     yes                  -
rpool/var/games    canmount    on                   default
rpool/var/games    overlay     off                  default
rpool/var/log      mountpoint  legacy               local
rpool/var/log      mounted     yes                  -
rpool/var/log      canmount    on                   default
rpool/var/log      overlay     off                  default
rpool/var/mail     mountpoint  /var/mail            inherited from rpool
rpool/var/mail     mounted     yes                  -
rpool/var/mail     canmount    on                   default
rpool/var/mail     overlay     off                  default
rpool/var/spool    mountpoint  /var/spool           inherited from rpool
rpool/var/spool    mounted     yes                  -
rpool/var/spool    canmount    on                   default
rpool/var/spool    overlay     off                  default
rpool/var/tmp      mountpoint  legacy               local
rpool/var/tmp      mounted     yes                  -
rpool/var/tmp      canmount    on                   default
rpool/var/tmp      overlay     off                  default

我的所有池都在我的 zpool 列表中:

$ zpool list
NAME         SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
Pool-1tb     976G   414G   562G         -     4%    42%  1.00x  ONLINE  -
Pool-500gb   488G  70.1G   418G         -     0%    14%  1.00x  ONLINE  -
rpool        952G   684G   268G         -    57%    71%  1.00x  ONLINE  -

启动后我无法挂载 rpool:

$ zfs mount rpool
cannot mount '/': directory is not empty

这是我运行 journalctl -b 时出现的当前 ZFS 相关错误: 在此处输入图片描述

关于如何在启动时挂载 rpool 以及如何恢复系统,有什么建议吗?

使用 zfsutils-linux 0.7.5 和 zfs-dkms 0.7.5 运行 Ubuntu 18.04

编辑:

df -h on / 的输出

$ ls -la
total 174
drwxr-xr-x   26 root root   30 Apr 29 06:58 .
drwxr-xr-x   26 root root   30 Apr 29 06:58 ..
drwxr-xr-x    2 root root  166 Apr 29 06:56 bin
drwxr-xr-x    4 root root   22 May  5 06:21 boot
drwxr-xr-x   24 root root 5380 May  5 07:22 dev
drwxr-xr-x  154 root root  265 May  5 07:24 etc
drwxr-xr-x    3 root root    3 May  4 12:21 home
lrwxrwxrwx    1 root root   33 Apr 29 06:58 initrd.img -> boot/initrd.img-4.15.0-99-generic
lrwxrwxrwx    1 root root   33 Apr 29 06:58 initrd.img.old -> boot/initrd.img-4.15.0-96-generic
drwxr-xr-x   24 root root   37 Apr 20 18:58 lib
drwxr-xr-x    2 root root   45 Jan 20  2019 lib32
drwxr-xr-x    2 root root    3 Jul 10  2019 lib64
drwxr-xr-x    3 root root    3 May  3 01:32 media
drwxr-xr-x    2 root root    2 Apr 27  2018 mnt
drwxr-xr-x   13 root root   13 Mar 29 12:34 opt
drwxr-xr-x    5 greg root    5 Apr 23 11:42 Pool-1tb
drwxr-xr-x    6 greg root    6 Apr 21 14:17 Pool-500gb
dr-xr-xr-x 1325 root root    0 May  5 07:21 proc
drwxr-xr-x   11 root root   12 Apr 20 19:27 root
drwxr-xr-x   37 root root 1140 May  5 07:22 run
drwxr-xr-x    2 root root  218 May  2 17:25 sbin
drwxr-xr-x   16 root root   17 Apr 30 13:02 snap
drwxr-xr-x    2 root root    2 Apr 27  2018 srv
dr-xr-xr-x   13 root root    0 May  5 07:21 sys
drwxrwxrwt   20 root root   21 May  5 07:31 tmp
drwx------    4 root root    4 Apr 28  2018 .Trash-0
drwxr-xr-x   12 root root   12 Jul 27  2019 usr
drwxr-xr-x   15 root root   17 Apr 27  2018 var
lrwxrwxrwx    1 root root   30 Apr 29 06:58 vmlinuz -> boot/vmlinuz-4.15.0-99-generic
lrwxrwxrwx    1 root root   30 Apr 29 06:58 vmlinuz.old -> boot/vmlinuz-4.15.0-96-generic

/home 上的 ls -la 的输出

$ ls -la
total 18
drwxr-xr-x  3 root root  3 May  4 12:21 .
drwxr-xr-x 26 root root 30 Apr 29 06:58 ..
drwxr-xr-x 22 greg greg 25 May  5 08:46 greg

/home/greg 上的 ls -la 的输出

$ df -h
Filesystem         Size  Used Avail Use% Mounted on
udev                95G     0   95G   0% /dev
tmpfs               19G  4.6M   19G   1% /run
rpool/ROOT/ubuntu  258G   24G  235G  10% /
tmpfs               95G  4.0K   95G   1% /dev/shm
tmpfs              5.0M  4.0K  5.0M   1% /run/lock
tmpfs               95G     0   95G   0% /sys/fs/cgroup
rpool/var/log      236G  1.4G  235G   1% /var/log
rpool/var/tmp      235G  128K  235G   1% /var/tmp
/dev/loop0         161M  161M     0 100% /snap/gnome-3-28-1804/116
/dev/loop3          94M   94M     0 100% /snap/core/9066
/dev/loop1          94M   94M     0 100% /snap/darktable-kyrofa/49
/dev/loop4         243M  243M     0 100% /snap/gnome-3-34-1804/27
/dev/loop2         141M  141M     0 100% /snap/gnome-3-26-1604/97
/dev/loop5         116M  116M     0 100% /snap/checksum-validator/2
/dev/loop6         141M  141M     0 100% /snap/gnome-3-26-1604/98
/dev/loop7         157M  157M     0 100% /snap/gnome-3-28-1804/110
/dev/loop8         2.5M  2.5M     0 100% /snap/gnome-calculator/730
/dev/loop9          93M   93M     0 100% /snap/darktable-kyrofa/45
/dev/loop10         44M   44M     0 100% /snap/snap-store/415
/dev/loop11         94M   94M     0 100% /snap/core/8935
/dev/loop12         63M   63M     0 100% /snap/gtk-common-themes/1506
/dev/loop13        143M  143M     0 100% /snap/slack/23
/dev/loop14        143M  143M     0 100% /snap/slack/22
/dev/loop15         55M   55M     0 100% /snap/core18/1705
/dev/loop16         62M   62M     0 100% /snap/authy/3
/dev/loop17         55M   55M     0 100% /snap/gtk-common-themes/1502
/dev/loop18        9.2M  9.2M     0 100% /snap/canonical-livepatch/95
/dev/loop19         55M   55M     0 100% /snap/core18/1754
/dev/loop20        4.4M  4.4M     0 100% /snap/gnome-calculator/704
Pool-1tb           946G  415G  532G  44% /Pool-1tb
Pool-500gb         473G   71G  403G  15% /Pool-500gb
rpool/srv          235G  128K  235G   1% /srv
rpool/var/games    235G  128K  235G   1% /var/games
rpool/var/mail     235G  128K  235G   1% /var/mail
tmpfs               19G   16K   19G   1% /run/user/120
tmpfs               19G   36K   19G   1% /run/user/1000

ls -la on / 的输出

$ ls -la
ls: cannot access '.gvfs': Permission denied
total 69
drwxr-xr-x 23 greg greg   26 May  5 07:22 .
drwxr-xr-x  3 root root    3 May  4 12:21 ..
-rw-------  1 greg greg 2938 May  5 07:24 .bash_history
drwx------ 18 greg greg   20 May  5 05:57 .cache
drwx------ 17 greg greg   20 May  4 17:49 .config
drwx------  3 root root    3 May  4 13:07 .dbus
drwxr-xr-x  2 greg greg    2 May  4 13:04 Desktop
drwxr-xr-x  2 greg greg    2 May  4 13:04 Documents
drwxr-xr-x  2 greg greg    2 May  4 13:04 Downloads
drwx------  2 greg greg    2 May  4 13:04 .gconf
drwx------  3 greg greg    5 May  4 13:06 .gnupg
d?????????  ? ?    ?       ?            ? .gvfs
-rw-------  1 greg greg 2480 May  5 07:22 .ICEauthority
drwx------  3 greg greg    3 May  4 13:04 .local
drwx------  5 greg greg    5 May  4 17:49 .mozilla
drwxr-xr-x  2 greg greg    2 May  4 13:04 Music
drwxr-xr-x  2 greg greg    2 May  4 12:21 NAS
drwx------  3 greg greg    3 May  4 13:04 .nv
drwxr-xr-x  2 greg greg    3 May  5 05:57 Pictures
drwx------  3 greg greg    3 May  4 17:49 .pki
drwxr-xr-x  2 greg greg    2 May  4 13:04 Public
drwxr-xr-x  3 greg greg    3 May  4 13:06 snap
drwx------  2 greg greg    2 May  4 13:06 .ssh
-rw-r--r--  1 greg greg    0 May  4 13:07 .sudo_as_admin_successful
drwxr-xr-x  2 greg greg    2 May  4 13:04 Templates
drwxr-xr-x  2 greg greg    2 May  4 13:04 Videos

/root 上的 ls -la 的输出

$ ls -la
total 42
drwxr-xr-x 11 root root  12 Apr 20 19:27 .
drwxr-xr-x 26 root root  30 Apr 29 06:58 ..
-rw-------  1 root root 399 May  4 12:59 .bash_history
drwx------  4 root root   4 Apr 28  2018 .cache
drwx------  6 root root   6 Jun 23  2018 .config
drwx------  3 root root   3 Apr 28  2018 .dbus
drwx------  2 root root   3 Apr 20 20:01 .ecryptfs
drwx------  2 root root   2 Nov  8  2018 .gconf
drwxr-xr-x  2 root root   3 May  5 07:21 .hplip
drwxr-xr-x  3 root root   3 Apr 28  2018 .local
drwxr-xr-x  3 root root   3 Mar 29 19:01 snap
drwx------  3 root root   6 May  5 06:24 .synaptic

/var/cache 上的 ls -la 的输出

$ ls -la
total 142
drwxr-xr-x 18 root root  19 Feb 18 06:30 .
drwxr-xr-x 15 root root  17 Apr 27  2018 ..
drwx------  2 root root  22 Apr 30 13:02 apparmor
drwxr-xr-x  4 root root   4 Dec  6  2018 app-info
drwxr-xr-x  3 root root   5 May  5 06:21 apt
drwxr-xr-x  2 root root   6 Apr 29  2018 cracklib
drwxrwx---  3 root lp    11 May  5 06:31 cups
drwxr-xr-x  2 root root   7 May  5 06:21 debconf
drwxr-xr-x  2 root root 153 Apr 30 13:02 fontconfig
drwxr-xr-x  2 root root   4 May  4 13:05 fwupd
drwxr-xr-x  2 root root   2 Jun  5  2018 gdm
drwx------  2 root root   3 May  2 17:26 ldconfig
drwxr-xr-x 35 man  man   37 May  5 06:21 man
-rw-r--r--  1 root root 227 May  5 05:28 motd-news
drwxr-xr-x  3 root root   3 Sep  3  2018 PackageKit
drwxr-xr-x  3 root root   5 May  5 07:22 samba
drwx------  2 root root   2 Aug 30  2016 slack
drwxr-xr-x  3 root root   6 May  4 15:28 snapd
drwxr-xr-x  2 root root   3 Apr 29  2018 ubuntu-advantage-tools

/var/spool 上的 ls -la 的输出

$ ls -la
total 11
drwxr-xr-x  5 root   root  5 May  4 12:26 .
drwxr-xr-x 15 root   root 17 Apr 27  2018 ..
drwxr-xr-x  3 root   root  3 May  4 12:26 cron
drwx--x---  3 root   lp    3 May  4 12:26 cups
drwx------  2 syslog adm   2 May  4 12:21 rsyslog

答案1

您需要mountpoint从数据集中删除冗余、未使用的属性。如果rpool(根数据集)实际上未使用,则删除该mountpoint属性并将其设置在实际使用的数据集上(rpool/ROOT/ubuntu):

zfs set mountpoint=none rpool

最重要的是,你应该rootfs除了mountpoint=/在数据集级别设置之外,还要设置zpool 属性:

zpool set bootfs=rpool/ROOT/ubuntu rpool

此外,删除挂载点目录也是安全的(ZFS 将在挂载时创建它们)。请重命名或备份这些目录。

如果您没有救援磁盘,您可以通过在启动命令行参数中添加init=/bin/Busybox sh和删除参数来获取 Busybox shell。然后,您可以导入池而不安装( ),然后根据需要编辑属性。root=zpool import -R /mnt -n rpool

最后,绝不依靠 fstab 来挂载 zfs文件系统数据集(除了 zvols 之外swap),除非您知道自己在做什么,因为具有标准mountpoint属性的数据集会提前挂载。使用mountpoint=legacy允许使用mount或 通过 进行挂载fstab

相关内容