SlideShare a Scribd company logo
1 of 85
Download to read offline
現代檔案系統 ZFS 的簡介與應用
zuan@chroot
Who am I?
- Zuan
- 118畢業,112 & 119休學中
- Chroot讀書會成員,較常在資安圈出沒
- 什麼都略懂一點,但什麼都不精通
- 喜歡玩資訊跟電子領域的各種事務
- 興趣是買學生證,發廢文,還有騎腳踏車
檔案系統的發展大約可以分三個時期
初期:堪用就好的檔案系統
https://commons.wikimedia.org/wiki/File:Samsung_HD400LD_Hard_Disk_A.jpg
FAT32
https://commons.wikimedia.org/wiki/File:Micro_SD_card_(Nokia).jpg
中期
Journaling功能
解決斷電檔案/檔案系統毀損的問題
https://www.flickr.com/photos/deerwooduk/3743375034
硬碟
寫入
檔案
0000 | 44 75 4C 10 32 76 BD F3 13 CB A1 5D 43 76 49 45
0010 | 6A 0F 28 FC 07 E4 F0 A8 D8 5C 11 C3 98 54 F1 3A
0020 | B5 1C D6 FC 4B 61 60 F1 7F 14 11 07 96 38 38 58
0030 | 86 49 A6 DB 1C CA CF 46 92 73 4A 41 C4 99 45 62
0040 | 6F 24 CF 65 DA A8 0F C5 15 23 F4 75 0B C0 6C 8B
0050 | ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
0060 | ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
0070 | A6 2A 27 BB 2A C4 7B BC 9D 43 A6 49 8E 7C 4A 20
0080 | 76 B3 FD 54 3A 64 27 70 BF 1B 08 28 FF 1B D3 88
0090 | 43 EB 76 0D 96 C6 09 8A F6 7E AD 79 21 AC DE FC
硬碟
斷電
檔案
0000 | 44 75 4C 10 32 76 BD F3 13 CB A1 5D 43 76 49 45
0010 | 6A 0F 28 FC 07 E4 F0 A8 D8 5C 11 C3 98 54 F1 3A
0020 | B5 1C D6 FC 4B 61 60 F1 7F 14 11 07 96 38 38 58
0030 | 86 49 A6 DB 1C CA CF 46 92 73 4A 41 C4 99 45 62
0040 | 6F 24 CF 65 DA A8 0F C5 15 23 F4 75 0B C0 6C 8B
0050 | ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
0060 | ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
0070 | A6 2A 27 BB 2A C4 7B BC 9D 43 A6 49 8E 7C 4A 20
0080 | 76 B3 FD 54 3A 64 27 70 BF 1B 08 28 FF 1B D3 88
0090 | 43 EB 76 0D 96 C6 09 8A F6 7E AD 79 21 AC DE FC
硬碟
寫入Journal
檔案
0000 | 44 75 4C 10 32 76 BD F3 13 CB A1 5D 43 76 49 45
0010 | 6A 0F 28 FC 07 E4 F0 A8 D8 5C 11 C3 98 54 F1 3A
0020 | B5 1C D6 FC 4B 61 60 F1 7F 14 11 07 96 38 38 58
0030 | 86 49 A6 DB 1C CA CF 46 92 73 4A 41 C4 99 45 62
0040 | 6F 24 CF 65 DA A8 0F C5 15 23 F4 75 0B C0 6C 8B
0050 | ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
0060 | ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
0070 | A6 2A 27 BB 2A C4 7B BC 9D 43 A6 49 8E 7C 4A 20
0080 | 76 B3 FD 54 3A 64 27 70 BF 1B 08 28 FF 1B D3 88
0090 | 43 EB 76 0D 96 C6 09 8A F6 7E AD 79 21 AC DE FC
1. 將
8C CE 6B CE F7 C5 34 3D 93 39 B6 88 A5 5B 52 2A
C6 4C 89 A5 40 0E 5A 5C 86 6B AA D2 44 0B 69 AF
寫入0050-006F
Journal
硬碟
寫入檔案
檔案
0000 | 44 75 4C 10 32 76 BD F3 13 CB A1 5D 43 76 49 45
0010 | 6A 0F 28 FC 07 E4 F0 A8 D8 5C 11 C3 98 54 F1 3A
0020 | B5 1C D6 FC 4B 61 60 F1 7F 14 11 07 96 38 38 58
0030 | 86 49 A6 DB 1C CA CF 46 92 73 4A 41 C4 99 45 62
0040 | 6F 24 CF 65 DA A8 0F C5 15 23 F4 75 0B C0 6C 8B
0050 | 8C CE 6B CE F7 C5 34 3D 93 39 B6 88 A5 5B 52 2A
0060 | C6 4C 89 A5 40 0E 5A 5C 86 6B AA D2 44 0B 69 AF
0070 | A6 2A 27 BB 2A C4 7B BC 9D 43 A6 49 8E 7C 4A 20
0080 | 76 B3 FD 54 3A 64 27 70 BF 1B 08 28 FF 1B D3 88
0090 | 43 EB 76 0D 96 C6 09 8A F6 7E AD 79 21 AC DE FC
1. 將
8C CE 6B CE F7 C5 34 3D 93 39 B6 88 A5 5B 52 2A
C6 4C 89 A5 40 0E 5A 5C 86 6B AA D2 44 0B 69 AF
寫入0050-006F
Journal
硬碟
移除Journal
檔案
0000 | 44 75 4C 10 32 76 BD F3 13 CB A1 5D 43 76 49 45
0010 | 6A 0F 28 FC 07 E4 F0 A8 D8 5C 11 C3 98 54 F1 3A
0020 | B5 1C D6 FC 4B 61 60 F1 7F 14 11 07 96 38 38 58
0030 | 86 49 A6 DB 1C CA CF 46 92 73 4A 41 C4 99 45 62
0040 | 6F 24 CF 65 DA A8 0F C5 15 23 F4 75 0B C0 6C 8B
0050 | 8C CE 6B CE F7 C5 34 3D 93 39 B6 88 A5 5B 52 2A
0060 | C6 4C 89 A5 40 0E 5A 5C 86 6B AA D2 44 0B 69 AF
0070 | A6 2A 27 BB 2A C4 7B BC 9D 43 A6 49 8E 7C 4A 20
0080 | 76 B3 FD 54 3A 64 27 70 BF 1B 08 28 FF 1B D3 88
0090 | 43 EB 76 0D 96 C6 09 8A F6 7E AD 79 21 AC DE FC
Journal
多了使用者權限的功能
改用B-Tree之類的資料結構加速檔案存取
http://www.tomshardware.com/reviews/ssd-file-system-ntfs,3166-5.html
NTFS, ext3, reiserfs, HFS+
現代的檔案系統
ZFS, btrfs, ReFS
硬碟會有Silent Corruption
ZFS內建資料Checksum
zfs有scrub功能
資料不會一聲不響的就毀壞
內建Volume Manager以及RAID
什麼是Volume Manager?
傳統磁碟分割有許多問題
分割區無法跨硬碟
分割區移動需要複製全部資料
空間會被卡住
什麼是RAID?
https://commons.wikimedia.org/wiki/File:RAID_1.svg
為什麼需要把RAID整合進檔案系統?
https://commons.wikimedia.org/wiki/File:RAID_1.svg
如果資料有毀壞,不知道哪一份才是對的
檔案系統Checksum結合RAID
就可以知道哪一份是對的
RAID Recovery時其實不用恢復所有資料
Snapshot功能
=> 檔案系統S&L大法
等同於Linux版的Time Machine
快照及快照差異可以被dd出來
(zfs send/recv)
可以用來做差異備份
版本A
備份
100GB
雲端磁碟
版本A
100GB
雲端磁碟
版本A
100GB
版本B
105GB
雲端磁碟
版本A
100GB
版本B
105GB
雲端磁碟
版本A
100GB
版本B
105GB
版本B
105GB
雲端磁碟
版本A
100GB
版本B - 版本A
檔案系統壓縮功能
不是XP就有了?
LZ4 vs DEFLATE(LZ77):
~400MB/s vs ~50MB/s
壓縮耗費的CPU幾乎感受不到
壓縮比也不差
說了那麼多...
How do you turn this on?
硬碟 硬碟 硬碟
ZFS Pool (ZPOOL)
File System File System zvol
ext4, fat… etc
zpool create
zfs create
zfs snapshot
zfs send / zfs recv
有什麼應用?
應用一:家用NAS備份上Google Drive
zfs snapshot x/x@snap2
zfs send -I x/x@snap1 x/x@snap2 | skicka ...
放crontab
可以自己寫一套bash shellscript
應用二:Ubuntu root fs直接灌在zfs上面
https://github.com/zfsonlinux/zfs/wiki/Ubuntu-16.0
4-Root-on-ZFS
個人沒有使用這方法,因為太麻煩
1. 正常灌在ext4上面
2. 開啟新安裝的系統,安裝ZFS
3. USB開機,將root fs複製到ZFS上面
4. chroot進去,update-grub
5. 重開機
剛開使用ZFS的常見問題
Q: ZFS很吃記憶體?
真的很吃,但可以把它限到1G左右
Q: 一定要ECC嗎?
不用的話,如果RAM壞掉,檔案會很難救
END

More Related Content

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

現代檔案系統 ZFS 的簡介與應用