RK3568 Debian10 固态硬盘自动挂载

Platform: RK3568
OS: Debian10
Kernel: v4.19.219
Module: Wdxsky SSD NVME 950 128G


需求

开机启动时自动挂载ssd固态硬盘。

实现

编辑/etc/fstab文件

# <file system>                 <mount pt>              <type>          <options>               <dump>  <pass>
/dev/nvme0n1p1          /media/linaro/ssd        auto        defaults,nofail,x-systemd.device-timeout=1,noatime        0       0

步骤

  1. 我们的ssd固态硬盘是pcie nvme接口的,kernel层先配置好pcie节点属性,之后确认设备可识别

    root@linaro-alip:~# ls /dev/nvme0n1p1 
    /dev/nvme0n1p1
    
  2. 打开Debian的文件管理器File Manager PCManFM,发现左侧快捷栏已识别到盘符,点击会提示需要输入用户密码,之后便可挂载成功,从以下df命令的结果可以看出是挂载到了/media/linaro/2803-1B06 目录

    root@linaro-alip:~# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/root       3.4G  2.5G  750M  78% /
    devtmpfs        978M  8.0K  978M   1% /dev
    tmpfs           986M   10M  976M   2% /dev/shm
    tmpfs           986M   17M  969M   2% /run
    tmpfs           5.0M  4.0K  5.0M   1% /run/lock
    tmpfs           986M     0  986M   0% /sys/fs/cgroup
    tmpfs           198M  8.0K  198M   1% /run/user/1000
    tmpfs           198M     0  198M   0% /run/user/0
    /dev/mmcblk0p8  8.3G  3.8M  8.3G   1% /media/linaro/9d85d337-9d03-4448-b4bd-4b399230974e
    /dev/mmcblk0p7  126M   13M  107M  11% /media/linaro/9cda8ba9-2cbe-4382-83b3-61a2c34adc92
    /dev/nvme0n1p1  120G  2.5G  117G   3% /media/linaro/2803-1B06
    
  3. 想要实现自动挂载,不需要输入密码确认,则可通过修改/etc/fstab文件来实现。一开始没想太多,参考网上的资料12,进行如下默认配置,就可以实现自动挂载功能了

    # <file system>			<mount pt>		<type>		<options>		<dump>	<pass>
    /dev/nvme0n1p1          /mnt/ssd        auto        defaults        0       0
    

    该挂载点是在/mnt/ssd 目录,实测发现在文件管理器中此目录没有快捷显示,要经多次点击打开对应目录才能看到ssd的内容,用起来不够便捷,应该还可以继续优化。

  4. 参考快捷显示的路径,新建一个/media/linaro/ssd目录进行挂载,经验证可以在快捷栏显示出来。满以为这就大功告成了,后来发现有个大问题,当没有连接ssd时上电启动进不了系统,会卡死在logo界面。主要报错信息如下:

    [  OK  ] Started Load/Save RF Kill Switch Status.
    [    4.266069] rk-pcie 3c0800000.pcie: PCIe Linking... LTSSM is 0x0
    [    5.279411] rk-pcie 3c0800000.pcie: PCIe Linking... LTSSM is 0x0
    [    6.292739] rk-pcie 3c0800000.pcie: PCIe Linking... LTSSM is 0x1
    [    7.306069] rk-pcie 3c0800000.pcie: PCIe Linking... LTSSM is 0x0
    [    8.319409] rk-pcie 3c0800000.pcie: PCIe Linking... LTSSM is 0x0
    [*     ] (1 of 2) A start job is running for… Time Synchronized (5s / no limit)
    [***   ] (1 of 2) A start job is running for… Time Synchronized (6s / no limit)
    [   ***] (2 of 2) A start job is running for /dev/nvme0n1p1 (9s / 1min 30s)
    [   11.359404] rk-pcie 3c0800000.pcie: PCIe Link Fail
    [  *** ] (2 of 2) A start job is running for /dev/nvme0n1p1 (29s / 1min 30s)
    [   32.052777] vcc5v0_otg: disabling
    [   32.052808] vcc3v3_lcd0_n: disabling
    [   32.052821] vcc3v3_lcd1_n: disabling
    [ ***  ] (2 of 2) A start job is running for…ev/nvme0n1p1 (1min 15s / 1min 30s)  
    ......
    [ TIME ] Timed out waiting for device /dev/nvme0n1p1.
    [DEPEND] Dependency failed for /media/linaro/ssd.
    [DEPEND] Dependency failed for Local File Systems.
             Starting Set console font and keymap...
             Starting Raise network interfaces...
             Starting Enable support fo…l executable binary formats...
    [  OK  ] Stopped Forward Password R…uests to Wall Directory Watch.
    [  OK  ] Reached target Sound Card.
    [  OK  ] Stopped Dispatch Password …ts to Console Directory Watch.
    [  OK  ] Reached target Login Prompts.
    [  OK  ] Reached target Timers.
    [  OK  ] Reached target Paths.
             Starting Create Volatile Files and Directories...
    [  OK  ] Closed Syslog Socket.
    [  OK  ] Started Emergency Shell.
    [  OK  ] Reached target Emergency Mode.
    [  OK  ] Reached target Sockets.
    [  OK  ] Started Set console font and keymap.
    [  OK  ] Started Enable support for…nal executable binary formats.
    [  OK  ] Started Create Volatile Files and Directories.
             Starting Network Time Synchronization...
             Starting Update UTMP about System Boot/Shutdown...
             Starting Network Name Resolution...
    [  OK  ] Started Update UTMP about System Boot/Shutdown.
             Starting Update UTMP about System Runlevel Changes...
    [  OK  ] Started Raise network interfaces.
    [  OK  ] Started Update UTMP about System Runlevel Changes.
    [  OK  ] Started Network Time Synchronization.
    [  OK  ] Started Network Name Resolution.
    [  OK  ] Reached target Host and Network Name Lookups.
    [  OK  ] Reached target Network.
    You are in emergency mode. After logging in, type "journalctl -xb" to view
    system logs, "systemctl reboot" to reboot, "systemctl default" or "exit"
    to boot into default mode.
    
    Cannot open access to console, the root account is locked.
    See sulogin(8) man page for more details.
    
    Press Enter to continue.
    

    从打印上看应该是系统没识别到nvme设备时先会进行1min30s的等待,timeout之后就进入了emergency mode。

  5. 我们的需求肯定是有连接ssd设备时自动挂载,没有连接时也不影响系统正常启动。继续查阅资料3,发现可以在< options > 中加上nofail选项来解决,该选项设置后外部设备在插入时可挂载,在未插入时忽略错误正常启动。该选项通常会结合x-systemd.device-timeout 来使用4,表示等待该设备多长时间才认为可用于挂载(即判断该设备可执行挂载操作),默认等待90s。而noatime选项则表示不更新文件系统上 inode 访问次数,有助于提升性能5。添加以上选项后测试不论有没有外接ssd均不影响系统正常启动,验证成功。

附录

附上fstab文件的基本格式与用法说明6,对于外挂的硬盘,主要就是要写明文件系统,挂载目录,文件系统类型,然后根据需要设置< optinos >选项,最后< dump >和< pass >一般都填0就好。

The fstab (/etc/fstab) (or file systems table) file is a system configuration file on Debian systems. The fstab file typically lists all available disks and disk partitions, and indicates how they are to be initialized or otherwise integrated into the overall system’s file system.

Example

# <file system>        <dir>         <type>    <options>             <dump> <pass>
/dev/sda1              /             ext4      defaults              1      1
/dev/hdxx              /usr          ext4      defaults              1      1
/dev/sda5              swap          swap      defaults              0      0

It is not necessary to list /proc and /sys in the fstab unless some special options are needed. The boot system will always mount them.

Field definitions

/etc/fstab contains the following fields separated by a space or tab:

<file system>   <dir>   <type>  <options>       <dump>  <pass>
  • - defines the storage device (i.e. /dev/sda1).

  • - tells the mount command where it should mount the to.

  • - defines the file system type of the device or partition to be mounted. Many different file systems are supported. Some examples are: ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. The ‘auto’ type lets the mount command to attempt to guess what type of file system is used, this is useful for removable devices such as CDs and DVDs.

  • - define particular options for filesystems. Some options relate only to the filesystem itself. Some of the more common options are:

    • auto - file system will mount automatically at boot, or when the command ‘mount -a’ is issued.
    • noauto - the filesystem is mounted only when you tell it to.
    • exec - allow the execution binaries that are on that partition (default).
    • noexec - do not allow binaries to be executed on the filesystem.
    • ro - mount the filesystem read only.
    • rw - mount the filesystem read-write.
    • sync - I/O should be done synchronously.
    • async - I/O should be done asynchronously.
    • flush - specific option for FAT to flush data more often, thus making copy dialogs or progress bars to stays up until things are on the disk.
    • user - permit any user to mount the filesystem (implies noexec,nosuid,nodev unless overridden).
    • nouser - only allow root to mount the filesystem (default).
    • defaults - default mount settings (equivalent to rw,suid,dev,exec,auto,nouser,async).
    • suid - allow the operation of suid, and sgid bits. They are mostly used to allow users on a computer system to execute binary executables with temporarily elevated privileges in order to perform a specific task.
    • nosuid - block the operation of suid, and sgid bits.
    • noatime - do not update inode access times on the filesystem. Can help performance.
    • nodiratime - do not update directory inode access times on the filesystem. Can help performance. You do not need to enable this flag if you have already enabled noatime.
    • relatime - update inode access times relative to modify or change time. Access time is only updated if the previous access time was earlier than the current modify or change time (similar to noatime, but doesn’t break mutt or other applications that need to know if a file has been read since the last time it was modified). Can help performance.
  • - is used by the dump utility to decide when to make a backup. When installed, dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system, if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the entry.

  • fsck reads the number and determines in which order the file systems should be checked. Possible entries are 0, 1, and 2. The root file system should have the highest priority, 1, all other file systems you want to have checked should get a 2. File systems with a value 0 will not be checked by the fsck utility.


欢迎留言讨论,感谢阅读~

参考资料


  1. etc fstab 详解linux,/etc/fstab功能详解 ↩︎

  2. linux之fstab文件详解 ↩︎

  3. 浅析fstab与移动硬盘挂载方法 ↩︎

  4. systemd时代的/etc/fstab ↩︎

  5. 使用noatime提升文件系统性能 ↩︎

  6. fstab ↩︎

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值