之前,我的一块Raspberry Pi作为一个简单的NAS,通过fstab文件实现了开机自动挂载移动硬盘。
根据网上别人嚼过的东西,没有深究。fstab如下:
1
2
3
4
5
6
7
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
UUID=FD720D1BCFDB2930 /media/pi/usbhdd ntfs defaults,noatime 0 0
a swapfile is not a swap partition, no line here
use dphys-swapfile swap[on|off] for that
使用UUID作为标识挂载了一块NTFS的移动硬盘,参数为defaults,noatime,一直以来相安无事。
直至,我把移动硬盘拔掉后开机,无法正常引导进入系统。
我一度以为是我经常暴力关机导致tf卡文件系统损坏。连上显示器和键盘救援一下,boot过程在
1
[** ]A start job is running for dev-disk-by\x2duuid-XXXXXXXX.device (xx s / 1min 30s)
随即进入emergency mode。大致知道原因了:未找到fstab中指定的硬盘
根据Archlinux wiki,若要将其设置为可忽略,可添加nofail选项[1]:
外部设备在插入时挂载,在未插入时忽略。这需要 nofail 选项,可以在启动时若设备不存在直接忽略它而不报错.
1
/etc/fstab
1
/dev/sdg1 /media/backup jfs defaults,nofail 0 2
External devices that are to be mounted when present but ignored if absent may require the nofail option. This prevents errors being reported at boot. For example:
1
/etc/fstab
1
/dev/sdg1 /media/backup jfs nofail,x-systemd.device-timeout=1 0 2
The nofail option is best combined with the x-systemd.device-timeout option. This is because the default device timeout is 90 seconds, so a disconnected external device with only nofail will make your boot take 90 seconds longer, unless you reconfigure the timeout as shown. Make sure not to set the timeout to 0, as this translates to infinite timeout.
If your external device requires another systemd unit to be loaded (for example the network for a network share) you can use x-systemd.requires=x combined with x-systemd.automount to postpone automounting until after the unit is available. For example:
1
/etc/fstab
1
//host/share /net/share cifs noauto,nofail,x-systemd.automount,x-systemd.requires=network-online.target,x-systemd.device-timeout=10,workgroup=workgroup,credentials=/foo/credentials 0 0
综合参考[2],我最终的fstab文件如下:
1
2
3
4
5
6
7
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
UUID=FD720D1BCFDB2930 /media/pi/usbhdd ntfs defaults,nofail,x-systemd.device-timeout=1,noatime 0 0
a swapfile is not a swap partition, no line here
use dphys-swapfile swap[on|off] for that
即使boot阶段没有接入移动硬盘,也能正常启动。