USB 上的 EXT4 - 如何指定与根磁盘分区相同的日志记录行为

USB 上的 EXT4 - 如何指定与根磁盘分区相同的日志记录行为

请考虑之前的讨论作为这个新问题的背景。

我修改了我的脚本,并将相同的文件系统选项应用到我的 USB 驱动器的 ext4 分区,使用,以及 fstab 中指定的挂载选项。

这些选项与之前的讨论相同。我已应用这些更改并重新启动,但是命令没有报告我所期望的内容,即它会显示类似于内部硬盘驱动器分区报告的安装选项。报道内容如下:

/dev/sdc3 on /site/DB005_F1 type ext4 (rw,relatime)
/dev/sdc4 on /site/DB005_F2 type ext4 (rw,relatime)
/dev/sdc5 on /site/DB005_F3 type ext4 (rw,relatime)
/dev/sdc6 on /site/DB005_F4 type ext4 (rw,relatime)
/dev/sdc7 on /site/DB005_F5 type ext4 (rw,relatime)
/dev/sdc8 on /site/DB005_F6 type ext4 (rw,relatime)
/dev/sdc9 on /site/DB005_F7 type ext4 (rw,relatime)
/dev/sdc10 on /site/DB005_F8 type ext4 (rw,relatime)
/dev/sdc11 on /site/DB006_F1 type ext4 (rw,relatime)
/dev/sdc12 on /site/DB006_F2 type ext4 (rw,relatime)
/dev/sdc13 on /site/DB006_F3 type ext4 (rw,relatime)
/dev/sdc14 on /site/DB006_F4 type ext4 (rw,relatime)
/dev/sdc15 on /site/DB006_F5 type ext4 (rw,relatime)
/dev/sdc16 on /site/DB006_F6 type ext4 (rw,relatime)
/dev/sdc17 on /site/DB006_F7 type ext4 (rw,relatime)
/dev/sdc18 on /site/DB006_F8 type ext4 (rw,relatime)

这些都报告相同,但只报告“rw,relatime”,而我期望更多。

完整的第一个 USB 分区的报告(与所有其他分区相同)如下:

root@OasisMega1:/DB001_F2/Oasis/bin# more tuneFS.previous.DB005_F1.20220907-210437.dumpe2fs
dumpe2fs 1.45.5 (07-Jan-2020)
Filesystem volume name:   DB005_F1
Last mounted on:          <not available>
Filesystem UUID:          11c8fbcc-c1e1-424d-9ffe-ad0ccf480128
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_fi
le dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash 
Default mount options:    journal_data user_xattr acl block_validity nodelalloc
Filesystem state:         clean
Errors behavior:          Remount read-only
Filesystem OS type:       Linux
Inode count:              6553600
Block count:              26214400
Reserved block count:     1310720
Free blocks:              25656747
Free inodes:              6553589
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      1017
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Sat Nov  7 09:57:44 2020
Last mount time:          Wed Sep  7 18:18:32 2022
Last write time:          Wed Sep  7 20:55:33 2022
Mount count:              211
Maximum mount count:      10
Last checked:             Sun Nov 22 13:50:57 2020
Check interval:           1209600 (2 weeks)
Next check after:         Sun Dec  6 13:50:57 2020
Lifetime writes:          1607 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      802d4ef6-daf4-4f68-b889-435a5ce467c3
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x21a24a19
Journal features:         journal_checksum_v3
Journal size:             512M
Journal length:           131072
Journal sequence:         0x000000bd
Journal start:            0
Journal checksum type:    crc32c
Journal checksum:         0xf0a385eb

有谁知道为什么会发生这种情况?

可以采取什么措施让内部硬盘和 USB 硬盘报告相同的选项吗?

在我的/etc/default/中文件中,我目前使用以下涉及的定义

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash scsi_mod.use_blk_mq=1 usb-storage.quirks=1058:25ee:u ipv6.disable=1"

我是否需要指定另一个怪癖才能使日志记录和挂载选项按预期生效?或者这又是一个“一切都好“情况和其他帖子一样吗?

修改后的脚本:

#!/bin/sh

####################################################################################
###
### $Id: tuneFS.sh,v 1.3 2022/09/08 03:31:12 root Exp $
###
### Script to set consistent (local/site) preferences for filesystem treatment at boot-time or mounting
###
####################################################################################

TIMESTAMP=`date '+%Y%m%d-%H%M%S' `
BASE=`basename "$0" ".sh" `


###
### These variables will document hard-coded 'mount' preferences for filesystems
###
count=1
BOOT_MAX_INTERVAL="-c 20"   ### max number of boots before fsck [20 boots]
TIME_MAX_INTERVAL="-i 2w"   ### max calendar time between boots before fsck [2 weeks]
ERROR_ACTION="-e remount-ro"    ### what to do if error encountered
#-m reserved-blocks-percentage

###
### This OPTIONS string should be updated manually to document
### the preferred and expected settings to be applied to ext4 filesystems
###
OPTIONS="-o journal_data,block_validity,nodelalloc"


ASSIGN=0
REPORT=0
VERB=0
SINGLE=0
USB=0
while [ $# -gt 0 ]
do
    case ${1} in
        --default ) REPORT=0 ; ASSIGN=0 ; shift ;;
        --report )  REPORT=1 ; ASSIGN=0 ; shift ;;
        --force )   REPORT=0 ; ASSIGN=1 ; shift ;;
        --verbose ) VERB=1 ; shift ;;
        --single )  SINGLE=1 ; shift ;;
        --usb )     USB=1 ; shift ;;
        * ) echo "\n\t Invalid parameter used on the command line.  Valid options:  [ --default | --report | --force | --single | --usb | --verbose ] \n Bye!\n" ; exit 1 ;;
    esac
done


workHorse()
{
    reference=`ls -t1 "${PREF}."*".dumpe2fs" 2>/dev/null | tail -1 `

    if [ -n "${reference}" -a -s "${reference}" ]
    then
        if [ ! -f "${PREF}.dumpe2fs.REFERENCE" ]
        then
            mv -v ${reference} ${PREF}.dumpe2fs.REFERENCE
        fi
    fi

    reference=`ls -t1 "${PREF}."*".verify" 2>/dev/null | tail -1 `

    if [ -n "${reference}" -a -s "${reference}" ]
    then
        if [ ! -f "${PREF}.verify.REFERENCE" ]
        then
            mv -v ${reference} ${PREF}.verify.REFERENCE
        fi
    fi

    BACKUP="${BASE}.previous.${PARTITION}.${TIMESTAMP}"
    BACKUP="${BASE}.previous.${PARTITION}.${TIMESTAMP}"

    rm -f ${PREF}.*.tune2fs
    rm -f ${PREF}.*.dumpe2fs

    ### reporting by 'tune2fs -l' is a subset of that from 'dumpe2fs -h'

    if [ ${REPORT} -eq 1 ]
    then
        ### No need to generate report from tune2fs for this mode.

        ( dumpe2fs -h ${DEVICE} 2>&1 ) | awk '{
                if( NR == 1 ){ print $0 } ;
                if( index($0,"revision") != 0 ){ print $0 } ;
                if( index($0,"mount options") != 0 ){ print $0 } ;
                if( index($0,"features") != 0 ){ print $0 } ;
                if( index($0,"Filesystem flags") != 0 ){ print $0 } ;
                if( index($0,"directory hash") != 0 ){ print $0 } ;
            }'>${BACKUP}.dumpe2fs
        echo "\n dumpe2fs REPORT [$PARTITION]:"
        cat ${BACKUP}.dumpe2fs
    else
        ### Generate report from tune2fs for this mode but only as sanity check.

        tune2fs -l ${DEVICE} 2>&1 >${BACKUP}.tune2fs

        ( dumpe2fs -h ${DEVICE} 2>&1 ) >${BACKUP}.dumpe2fs

        if [ ${VERB} -eq 1 ] ; then
            echo "\n tune2fs REPORT:"
            cat ${BACKUP}.tune2fs

            echo "\n dumpe2fs REPORT:"
            cat ${BACKUP}.dumpe2fs
        fi

        if [ ${ASSIGN} -eq 1 ]
        then
            echo "  COMMAND:  tune2fs ${COUNTER_SET} ${BOOT_MAX_INTERVAL}  ${TIME_MAX_INTERVAL}  ${ERROR_ACTION}  ${OPTIONS}  ${DEVICE} ..."
            tune2fs ${COUNTER_SET} ${BOOT_MAX_INTERVAL}  ${TIME_MAX_INTERVAL}  ${ERROR_ACTION}  ${OPTIONS}  ${DEVICE}

            rm -f ${PREF}.*.verify
            ( dumpe2fs -h ${DEVICE} 2>&1 ) >${BACKUP}.verify

            if [ ${VERB} -eq 1 ] ; then  
                echo "\n Changes:"
                diff ${BACKUP}.dumpe2fs ${BACKUP}.verify
            fi
        else
            if [ ${VERB} -eq 1 ] ; then  
                echo "\n Differences:"
                diff ${BACKUP}.tune2fs ${BACKUP}.dumpe2fs
            fi

            rm -f ${BACKUP}.verify
        fi
    fi
}


workPartitions()
{
    case ${PARTITION} in
        1 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda3"  ; OPTIONS="" ;;
                5 ) DEVICE="/dev/sdc3"  ;;
                6 ) DEVICE="/dev/sdc11" ;;
            esac ;;
        2 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda7"  ;;
                5 ) DEVICE="/dev/sdc4"  ;;
                6 ) DEVICE="/dev/sdc12" ;;
            esac ;;
        3 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda8"  ;;
                5 ) DEVICE="/dev/sdc5"  ;;
                6 ) DEVICE="/dev/sdc13" ;;
            esac ;;
        4 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda9"  ;;
                5 ) DEVICE="/dev/sdc6"  ;;
                6 ) DEVICE="/dev/sdc14" ;;
            esac ;;
        5 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda12" ;;
                5 ) DEVICE="/dev/sdc7"  ;;
                6 ) DEVICE="/dev/sdc15" ;;
            esac ;;
        6 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda13" ;;
                5 ) DEVICE="/dev/sdc8"  ;;
                6 ) DEVICE="/dev/sdc16" ;;
            esac ;;
        7 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda14" ;;
                5 ) DEVICE="/dev/sdc9"  ;;
                6 ) DEVICE="/dev/sdc17" ;;
            esac ;;
        8 ) case ${DISK_ID} in
                1 ) DEVICE="/dev/sda4"  ;;
                5 ) DEVICE="/dev/sdc10" ;;
                6 ) DEVICE="/dev/sdc18" ;;
            esac ;;
    esac
    PARTITION="DB00${DISK_ID}_F${PARTITION}"
    PREF="${BASE}.previous.${PARTITION}"

    echo "\n\t\t PARTITION = ${PARTITION}"
    echo "\t\t DEVICE    = ${DEVICE}"

    count=`expr ${count} + 1 `
    COUNTER_SET="-C ${count}"
    workHorse

}


workPartitionGroups()
{
    if [ ${SINGLE} -eq 1 ]
    then
        for PARTITION in `echo ${ID_SET} `
        do
            echo "\n\t Actions only for DB00${DISK_ID}_F${PARTITION} ? [y|N] => \c" ; read sel
            if [ -z "${sel}" ] ; then  sel="N" ; fi
            case ${sel} in
                y* | Y* ) DOIT=1 ; break ;;
                * ) DOIT=0 ;;
            esac
        done

        if [ ${DOIT} -eq 1 ]
        then
            #echo "\t\t PARTITION ID == ${PARTITION} ..."
            workPartitions
            exit
        fi
    else
        for PARTITION in `echo ${ID_SET} `
        do
            #echo "\t\t PARTITION ID == ${PARTITION} ..."
            workPartitions
        done
    fi
}


if [ ${USB} -eq 1 ]
then
    for DISK_ID in 5 6
    do
        echo "\n\n DISK ID == ${DISK_ID} ..."
        ID_SET="1 2 3 4 5 6 7 8"
        workPartitionGroups
    done
else
    DISK_ID="1"
    echo "\n\n DISK ID == ${DISK_ID} ..."
    ID_SET="2 3 4 5 6 7 8"
    workPartitionGroups
fi



exit 0
exit 0
exit 0

答案1

如果在 中指定,某些 ext4 文件系统选项可能不会生效,/etc/fstab因为它们需要更改文件系统结构。其中一些可以在卸载文件系统时简单地应用tune2fs,但有些选项可能需要在之后运行完整的文件系统检查tune2fs才能正确生效。

据我所知,没有任何机制会根据磁盘是否通过 USB 连接来影响文件系统选项。

相关内容