跳到主要内容

Filesystem

N/AMinixExtExt2Xia
Max FS size64 MB2 GB 4 TB 2 GB
Max file size64 MB2 GB 2 GB 64 MB
Max file name16/30 c255 c255 c248 c
3 times supportNoNoYesYes
ExtensibleNoNoYesNo
Var. block sizeNoNoYesNo
fscreategrowshrinkmovecopychecklabeluuidpkgs
btrfsbtrfs-progs/btrfs-tools
exfat
ext2e2fsprogs
ext2e2fsprogs
ext2e2fsprogs
f2fsf2fs-tools
fat16dosfstools, mtools
fat32dosfstools, mtools
hfshfsutils
hfs+hfsutils
jfsjfsutils
swaputil-linux
lukscryptsetup, dmsetup
lvm2 pvlvm2
minixutil-linux
nilfs2nilfs-utils/nilfs-tools
ntfsntfs-3g/ntfsprogs
reiser4reiser4progs
reiserfsreiserfsprogs/reiserfs-utils
udfudftools
xfsxfsprogs, xfsdump

基准测试

# /dev/zero 最快,但可能会被压缩
time cat /dev/zero | head -c $((1024*1024*500)) > /dev/null
real 0m0.439s
user 0m0.026s
sys 0m0.747s

# /dev/urandom 性能较慢
time cat /dev/urandom | head -c $((1024*1024*500)) > /dev/null
real 1m25.427s
user 0m0.097s
sys 1m25.713s

# openssl 随机数相对更快
time openssl rand $((1024*1024*500)) | head -c $((1024*1024*500)) > /dev/null
real 0m9.721s
user 0m9.024s
sys 0m1.284s

# 监控 IO 状况
iostat -mx -d sda 1

dd bs=16M count=64 if=test of=test1 conv=fdatasync

常用操作

# 可查看速度
pv /home/user/bigfile.iso | md5sum
# 8.25 后可查看进度
dd if=/dev/urandom of=/dev/null status=progress
# urandom 会限制速度,可以使用文件来测试
truncat -s 10G test.data
dd if=test.data of=/dev/null status=progress
# 似乎会更快
pv < /dev/sda > /dev/sdb
# 使用 PV 监控速度
dd if=/dev/urandom | pv | dd of=/dev/null
# 简单一点
pv bigfile.iso | dd of=VirtualDisk.raw
# 在 DD 执行以后也可以查看进度
kill -USR1 $(pgrep ^dd)
watch -n5 'kill -USR1 $(pgrep ^dd)'
# 在 BSD/MAC 下需要 INFO
kill -INFO $(pgrep ^dd$)
# 同上简单一点
pkill -usr1 dd

# 将磁盘制作为镜像文件
dd if=/dev/sdb of=./disk.img
# 从文件恢复到磁盘
dd if=./disk.img of=/dev/sdb

# 挂载 smb
# Windows 共享无密码时使用 guest
mount_smbfs //guest:[email protected]/share/ ~/mnt/share/
# 或者挂载 cifs 也可以
mount -t cifs -o username=guest,password=guest //192.168.8.1/share/ ~/mnt/share/

# 如果使用的环境没有相关的 linux 工具,可以考虑使用 docker
docker run --rm -it --privileged -v /:/host ubuntu

diskutil

OS X

# 相当于 fdisk -l
diskutil list
# umount 经常无法直接操作
diskutil unmount /Volumes/<挂载名>
diskutil unmountdisk /dev/disk2
# 格式化磁盘
diskutil eraseDisk HFS+ DISK disk2
# 磁盘分区
diskutil partitionDisk disk4 1 GPT HFS+ newdisk R

# 添加 ext 类磁盘操作工具
brew install e2fsprogs
ls `brew --prefix e2fsprogs`/sbin

特殊特性

  • rename2
    • overlay 依赖
    • zfs 尚不支持
  • clone
    • zfs 尚不支持

FAQ

disk vs rdisk on BSD

man hdiutil

/dev/rdisk nodes are character-special devices, but are "raw" in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel's filesystem code.

即 rdisk 几乎是直接访问物理设备,disk 还会经过系统缓存.在能使用 rdisk 时不使用 disk.

http://superuser.com/questions/631592

文件时间

时间缩写全称说明
atimeAccess Time访问时间
ctimeChange Time当访问权限等修改时,会修改该时间
mtimeModify Time当修改文件内容时会修改该时间
btimeBirth Time创建时间
windowslinuxsolarisdragonflynaclfreebsddarwinnetbsdopenbsdplan9
atime
mtime
ctime✓*
btimen/an/an/an/a
  • Windows XP 不支持 ctime, Vista 以上支持.
  • 可使用 stat 文件名 查看
  • 该表格摘自 djherbis/times
$ stat sg_store.db
File: 'sg_store.db'
Size: 45056 Blocks: 88 IO Block: 4096 regular file
Device: 1000004h/16777220d Inode: 45296478 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 501/ root) Gid: ( 20/ root)
Access: 2016-09-22 15:26:54.000000000 +0800
Modify: 2016-09-22 15:26:54.000000000 +0800
Change: 2016-09-22 15:27:20.000000000 +0800
Birth: 2016-09-21 23:05:30.000000000 +0800

# 修改 mtime 和 ctime
$ touch sg_store.db
# 修改 ctime
$ chown root:root sg_store.db