问题描述
刚遇到一个问题:在重启Linux系统时,挂载的vfat文件系统中所有文件的时间戳显示在错误的时区。似乎设备开始认为它的本地时间是 UTC,所以它显示所有时间戳和偏移。
重现步骤:
-
创建一些小的 FAT 格式的图像:
dd if=/dev/zero of=small.img bs=1M seek=1 count=0
mkfs.vfat small.img
-
在本地安装此映像:
mount -t vfat -o umask=0022,gid=1001,uid=1001 small.img mnt
-
将时区设置为非 UTC 时区;
-
stat mnt/newfile
File: mnt/newfile Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 700h/1792d Inode: 40 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2021-03-22 12:19:56.000000000 +0100 Modify: 2021-03-22 12:19:56.000000000 +0100 Change: 2021-03-22 12:19:56.000000000 +0100 Birth: -
timedatectl
Local time: Mon 2021-03-22 12:19:07 CET Universal time: Mon 2021-03-22 11:19:07 UTC RTC time: Mon 2021-03-22 11:19:07 Time zone: Europe/Vienna (CET,+0100) System clock synchronized: yes NTP service: active RTC in local TZ: no
-
卸载文件系统,检查重新挂载时是否有任何更改:
umount mnt; mount -t vfat -o umask=0022,uid=1001 small.img mnt; stat mnt/newfile
File: mnt/newfile Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 700h/1792d Inode: 64 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2021-03-22 00:00:00.000000000 +0100 Modify: 2021-03-22 12:19:56.000000000 +0100 Change: 2021-03-22 12:19:56.000000000 +0100 Birth: -
-
重启系统;
-
再次挂载图像,查看创建文件的时间戳:
File: mnt/newfile Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 700h/1792d Inode: 26 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2021-03-22 01:00:00.000000000 +0100 Modify: 2021-03-22 13:19:56.000000000 +0100 Change: 2021-03-22 13:19:56.000000000 +0100 Birth: -
可以清楚地观察到,时间向前移动了 1 小时(12:10 到 13:19),而时区显示相同 - +0100。看起来 mount
现在认为文件时间戳是以 UTC 记录的,因此它会尝试以“正确”偏移来显示它们。
为了检查前面语句的有效性,让我们使用 tz=UTC
选项显式地重新挂载相同的文件系统:
mount -t vfat -o umask=0022,uid=1001,tz=UTC small.img mnt; stat mnt/newfile
File: mnt/newfile
Size: 0 Blocks: 0 IO Block: 16384 regular empty file
Device: 700h/1792d Inode: 50 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-03-22 01:00:00.000000000 +0100
Modify: 2021-03-22 13:19:56.000000000 +0100
Change: 2021-03-22 13:19:56.000000000 +0100
Birth: -
即使系统的时区确实是 CET:
date
Mon Mar 22 12:26:42 CET 2021
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)