如何将多个选项传递给“tune2fs -E mount_opts”?

lve*_*lla 4 linux filesystems ext4

根据手册:

mount_opts=mount_option_string
                      Set  a  set  of  default mount options which will be used when the file
                      system is mounted.  Unlike  the  bitmask-based  default  mount  options
                      which  can  be  specified with the -o option, mount_option_string is an
                      arbitrary string with a maximum length of 63 bytes, which is stored  in
                      the superblock.
Run Code Online (Sandbox Code Playgroud)

如果我尝试设置单个选项,它会起作用:

$ tune2fs -E mount_opts=data=writeback /dev/sde2
tune2fs 1.43.5 (04-Aug-2017)
Setting extended default mount options to 'data=writeback'
Run Code Online (Sandbox Code Playgroud)

但如果我尝试设置多个选项,它似乎与tune2fs自己的解析机制冲突:

$ tune2fs -E mount_opts=data=writeback,noatime /dev/sde2 
tune2fs 1.43.5 (04-Aug-2017)

Bad options specified.

Extended options are separated by commas, and may take an argument which
    is set off by an equals ('=') sign.

Valid extended options are:
    clear_mmp
    hash_alg=<hash algorithm>
    mount_opts=<extended default mount options>
    stride=<RAID per-disk chunk size in blocks>
    stripe_width=<RAID stride*data disks in blocks>
    test_fs
    ^test_fs
Run Code Online (Sandbox Code Playgroud)

如何在“mount_opts”上传递带有多个选项的字符串?

小智 6

正如托马斯所说,sparated by commas是为了扩展期权分离。然而,mount_opts选项分离也是使用,(参见Linux内核fs/ext4/super.c:parse_options())完成的,并且从这个答案开始e2fsprogsmke2fs 无法 tune2fs在语义上区分一个与另一个。

与 Theodore Y. Ts'o 的邮件往来揭示

是的,这是tune2fs的一个缺点。

没有语法可以使用常见的ext操作工具来实现此目的。Ts'o 建议使用debugfs以下解决方法:

您可以使用 debugfs 设置扩展安装选项:
debugfs -w -R "set_super_value mount_opts foo,bar" /dev/sda1

在这种情况下,您需要debugfs -w -R "set_super_value mount_opts data=writeback,noatime" /dev/sde2,但这不会产生您期望的效果

安装后,ext4内核模块将抱怨Unrecognized mount option "noatime" or missing value; 事实上,只能指定ext特定的选项,而noatime不是(参见相同的内核源文件,可用选项列在数组中tokens)。功能上最接近的匹配是lazytime.

所以,使用debugfs -w -R "set_super_value mount_opts data=writeback,lazytime" /dev/sde2.