前言:天下儲存,分久必合
話說天下大勢,分久必合,合久必分。儲存之道,亦復如是。
你手上有兩台 NAS,一台放影片,一台放文件。每次找檔案,得先想:「這玩意兒當初存在曹操那邊還是孫權那邊?」——彷彿在三國地圖上翻來翻去找糧草,還沒找到檔案,人已經先崩潰了。
這時候你需要的,就是 mergerfs。
mergerfs 是一種 Union Filesystem——它不會動你原始硬碟上的任何資料,而是在上面建立一個虛擬層,把散落各處的儲存空間統一調度。簡單說:它就是諸葛亮,不用搬遷任何一座城池,只憑一張地圖就能讓三軍糧草如臂使指。
曹操許昌糧倉 (NAS A) ──┐
├──→ /media/unified (大本營統一入口)
孫權江東魚米 (NAS B) ──┘
本文將以三國用兵之法,帶你走過 mergerfs 合併儲存的完整戰術。所有指令皆為實戰驗證,搬去直接用。開戰之前,先備齊軍需:
# 安裝 NFS 客戶端(與各路糧倉通訊的驛馬)
sudo apt install nfs-common
# 安裝 mergerfs(統一調度的軍師本尊)
sudo apt install mergerfs
上策:安營扎寨 — 掛載遠端糧倉
策略口訣:「糧草未動,營寨先行。」
打仗第一步不是衝鋒,而是在各路諸侯的城池外建好自家軍營。把遠端 NFS 儲存掛載到本地目錄,就等於在曹操許昌城外和孫權建業城外各建一座軍營,方便隨時調度糧草。
先看我軍部署地圖:
| 角色 | 遠端路徑 (範例) | 本地掛載點 | 說明 |
|---|---|---|---|
| 曹操許昌糧倉 | SERVER_A_IP:/data1 | /mnt/storage1 | 第一台後端儲存 |
| 孫權江東魚米 | SERVER_B_IP:/data2 | /mnt/storage2 | 第二台後端儲存 |
| 大本營 | N/A | /media/unified | 使用者存取的統一入口 |
# 建立掛載目錄(先把營寨的地基打好)
sudo mkdir -p /mnt/storage1 /mnt/storage2
# 掛載第一台 NAS (建議使用 soft mount 避免網路斷線導致系統卡死)
sudo mount -t nfs -o soft,timeo=30,retrans=3 SERVER_A_IP:/data1 /mnt/storage1
# 掛載第二台 NAS
sudo mount -t nfs -o defaults SERVER_B_IP:/data2 /mnt/storage2
這裡有個眉角:第一台用了 soft,timeo=30,retrans=3,翻成白話就是「如果曹操的糧倉三十秒沒回應,重試三次就放棄」。為什麼?因為 NFS 的預設行為是 hard mount——一旦網路斷線,你的系統會像關羽困在麥城一樣,死守不退,整台機器卡到天荒地老。soft mount 則是「打不贏就撤」,識時務者為俊傑。
中策:合縱連橫 — mergerfs 統一調度
策略口訣:「各路諸侯不必遷都,一紙盟約即可號令天下。」
營寨建好了,糧草通道也打通了。但你每次取用還是得分別去 /mnt/storage1 和 /mnt/storage2——這就像明明結了盟,每次調糧還是得分別派人去許昌和建業,何其麻煩。
現在請出我們的軍師諸葛亮——mergerfs。他不搬任何一袋糧草,也不改任何一座倉庫的結構,只是在上面搭了一個統一調度層,讓你在大本營 /media/unified 一個入口就能存取所有糧草。
# 建立統一入口(大本營的帥帳)
sudo mkdir -p /media/unified
# 執行合併指令(諸葛亮攤開地圖,合縱連橫)
sudo mount -t fuse.mergerfs \
-o defaults,allow_other,use_ino,nonempty,category.create=mfs,minfreespace=10G \
/mnt/storage1:/mnt/storage2 \
/media/unified
這條指令就是整場戰役的核心盟約。讓我們逐一解讀軍師的部署策略:
defaults— 採用預設掛載參數(rw, suid, dev 等),穩當的基本盤,行軍必備。allow_other— 允許所有將士取用,不限大將軍。沒有這個參數,只有 root 能存取,其他使用者通通被擋在帥帳門外。category.create=mfs— Most Free Space,最精妙的調度策略。新糧草會自動送往剩餘空間最多的那座糧倉。曹操那邊還有八成空間,孫權那邊只剩兩成?那下一批糧草就全送許昌。軍師自動調度,不勞大將軍操心。minfreespace=10G— 存量低於十石便停止進貨。當某座糧倉空間不足 10GB,軍師會自動停止向它寫入新檔,避免爆倉。use_ino— 每袋糧草都有獨一無二的封印(inode),確保不同倉庫的糧草不會撞號。nonempty— 允許掛載到非空目錄,即使營寨裡已有物資也可進駐。不加這個,大本營目錄裡有東西就會被拒於門外。/mnt/storage1:/mnt/storage2— 冒號是連結各路糧倉的驛道。要加入第三路諸侯?再加一個冒號和路徑即可,擴軍就是這麼簡單。
下策:永鎮社稷 — 寫入國法 fstab
策略口訣:「臨時軍令打得了一仗,國法才能定天下。」
以上操作都是臨時的——機器一重開,盟約作廢,糧道斷絕,大本營唱空城計。要讓這套部署永久生效,得把臨時軍令刻入國法:/etc/fstab。
# [NFS Mounts]
SERVER_A_IP:/data1 /mnt/storage1 nfs soft,timeo=30,retrans=3 0 0
SERVER_B_IP:/data2 /mnt/storage2 nfs defaults 0 0
# [mergerfs Pool]
/mnt/storage1:/mnt/storage2 /media/unified fuse.mergerfs defaults,allow_other,use_ino,category.create=mfs,minfreespace=10G 0 0
寫入前切記:先試陣法再刻入兵書。先用前面的手動指令確認一切運作正常,再寫入 fstab。否則萬一寫錯,開機直接進不了系統——那就不是三國演義,是悲劇了。
巡視糧倉:驗收成果
策略口訣:「佈陣已畢,巡營為先。」
盟約簽了、國法刻了,總得親自巡視一圈,確認糧草確實到位。
清點糧草總量
df -h /media/unified
這條指令會顯示兩台 NAS 的空間總和。如果曹操那邊有 2TB、孫權那邊有 3TB,你應該會看到合計約 5TB 的可用空間。一統天下的感覺,就是這麼爽。
測試糧草調度
在 /media/unified 建立一個大檔案,然後去 /mnt/storage1 和 /mnt/storage2 看看——新檔案被送往哪座糧倉了?如果軍師的 category.create=mfs 策略生效,它應該出現在空間最多的那一邊。
網路頻寬提醒
別忘了,底層走的是 NFS 網路傳輸。你的合併儲存效能,受限於網路頻寬——就像糧道再寬,驛馬跑不快也沒用。建議在 1Gbps 以上的內網環境執行,否則大檔案傳輸會讓你體驗到「千里送糧,慢如牛車」的古人辛酸。
羅貫中曰
羅貫中曰:「余觀天下之儲存,其勢如列國。NAS 各據一方,檔案散落四野,使用者奔走其間,疲於尋覓。mergerfs 者,合縱之策也。不動一磚一瓦,不遷一檔一案,僅以虛擬之層統合萬方,使分散之糧倉化為一體,存取如臂使指。夫用兵之道,上策攻心,不戰而屈人之兵;儲存之道,上策合併,不動而統天下之檔。習得此術者,可謂不遷而合、不動而統、空間聯集、如臂使指。」
願你的儲存版圖,從此天下一統,再無紛爭。
English Version
Prologue: All Storage Under Heaven — United We Store
It is a truth universally acknowledged in the annals of storage that what is divided must eventually be united, and what is united must eventually be divided. So it goes with NAS drives.
You have two NAS boxes. One holds your video archive, the other your documents. Every time you need a file, you must first ask yourself: “Did I stash this in Cao Cao’s granary or Sun Quan’s?” — as if you were fumbling across the map of the Three Kingdoms hunting for supply caches. By the time you find the file, your sanity is already a casualty of war.
What you need is mergerfs.
mergerfs is a Union Filesystem — it never touches the data on your original drives. Instead, it builds a virtual layer on top, unifying scattered storage under a single command structure. In plain terms: it is Zhuge Liang himself. Without relocating a single city, armed with nothing but a map and a feather fan, he makes every granary in the realm respond as one.
Cao Cao's Xuchang Granary (NAS A) ──┐
├──→ /media/unified (Headquarters — unified entry point)
Sun Quan's Jiangdong Stores (NAS B) ──┘
This article deploys the art of war from the Three Kingdoms to walk you through the complete mergerfs storage-unification campaign. Every command has been battle-tested — copy and deploy at will. Before the campaign begins, muster your supplies:
# Install the NFS client (courier horses for communicating with remote granaries)
sudo apt install nfs-common
# Install mergerfs (the grand strategist himself)
sudo apt install mergerfs
First Strategy: Setting Up Camp — Mounting Remote Granaries
Strategist’s Maxim: “Before the grain moves, the camps must be in place.”
The first step in any campaign is not to charge — it is to establish forward camps outside each allied city. Mounting remote NFS storage to local directories is the equivalent of pitching your tents outside Cao Cao’s fortress at Xuchang and Sun Quan’s capital at Jianye, ready to requisition supplies at a moment’s notice.
First, review the deployment map:
| Role | Remote Path (example) | Local Mount Point | Description |
|---|---|---|---|
| Cao Cao’s Xuchang Granary | SERVER_A_IP:/data1 | /mnt/storage1 | First backend storage |
| Sun Quan’s Jiangdong Stores | SERVER_B_IP:/data2 | /mnt/storage2 | Second backend storage |
| Headquarters | N/A | /media/unified | Unified access point for end users |
# Create mount directories (lay the foundations for camp)
sudo mkdir -p /mnt/storage1 /mnt/storage2
# Mount the first NAS (use soft mount to avoid system lockup if the network drops)
sudo mount -t nfs -o soft,timeo=30,retrans=3 SERVER_A_IP:/data1 /mnt/storage1
# Mount the second NAS
sudo mount -t nfs -o defaults SERVER_B_IP:/data2 /mnt/storage2
A tactical note: the first NAS uses soft,timeo=30,retrans=3. In plain language: “If Cao Cao’s granary doesn’t respond within thirty seconds, retry three times and then retreat.” Why? Because the NFS default is a hard mount — once the network goes down, your system will hold its ground like Guan Yu besieged at Mai Castle, refusing to withdraw, locking up the entire machine until the end of time. A soft mount, on the other hand, embraces the ancient wisdom: “He who knows when to retreat is the true hero.”
Second Strategy: The Grand Alliance — mergerfs Unified Command
Strategist’s Maxim: “The lords need not move their capitals; a single pact commands all under heaven.”
The camps are pitched, the supply lines are open. But every time you need something, you still have to send runners separately to /mnt/storage1 and /mnt/storage2 — as if, despite having signed the alliance, you still dispatch separate convoys to Xuchang and Jianye for every sack of grain. Absurd.
Enter our grand strategist, Zhuge Liang — mergerfs. He doesn’t move a single sack of grain, doesn’t alter a single warehouse. He simply lays a unified command layer on top, so that from headquarters at /media/unified, one gate gives you access to every granary in the realm.
# Create the unified entry point (the strategist's command tent at headquarters)
sudo mkdir -p /media/unified
# Execute the merger command (Zhuge Liang unfurls the map — the grand alliance begins)
sudo mount -t fuse.mergerfs \
-o defaults,allow_other,use_ino,nonempty,category.create=mfs,minfreespace=10G \
/mnt/storage1:/mnt/storage2 \
/media/unified
This single command is the core pact of the entire campaign. Let us decode the strategist’s deployment, parameter by parameter:
defaults— Standard marching parameters (rw, suid, dev, etc.). The reliable baseline — no army marches without it.allow_other— All soldiers may access the stores, not just the commanding general. Without this, only root can enter; everyone else is turned away at the tent flap.category.create=mfs— Most Free Space: the strategist’s most brilliant dispatch policy. New supplies are automatically routed to whichever granary has the most room. Cao Cao’s side still has eighty percent capacity while Sun Quan’s is down to twenty? The next shipment goes straight to Xuchang. The strategist handles logistics so the general doesn’t have to.minfreespace=10G— Stop shipping when reserves drop below ten bushels. When any granary falls below 10GB of free space, the strategist automatically stops sending new files there — preventing an overflow crisis.use_ino— Every supply sack gets a unique seal (inode), ensuring sacks from different granaries never share the same mark.nonempty— Permits garrisoning a camp even if it already holds supplies. Without this, if the headquarters directory already contains files, you’ll be barred at the gate./mnt/storage1:/mnt/storage2— The colon is the supply road connecting each granary. Need to bring a third lord into the alliance? Just add another colon and path. Expanding the coalition is that simple.
Third Strategy: Enshrining the Law — Permanent fstab Configuration
Strategist’s Maxim: “A field order wins a battle; only codified law secures the realm.”
Everything above is temporary — reboot the machine and the pact dissolves, supply lines collapse, and headquarters is left performing the Empty Fort Strategy for real. To make this deployment permanent, the field orders must be carved into the law of the land: /etc/fstab.
# [NFS Mounts]
SERVER_A_IP:/data1 /mnt/storage1 nfs soft,timeo=30,retrans=3 0 0
SERVER_B_IP:/data2 /mnt/storage2 nfs defaults 0 0
# [mergerfs Pool]
/mnt/storage1:/mnt/storage2 /media/unified fuse.mergerfs defaults,allow_other,use_ino,category.create=mfs,minfreespace=10G 0 0
Before you inscribe the law, heed this warning: test the formation before carving it into the war manual. Verify everything works with the manual commands first, then write it into fstab. If you get it wrong, the machine won’t boot — and that’s no longer Romance of the Three Kingdoms, it’s a tragedy.
Inspecting the Granaries: Verification
Strategist’s Maxim: “Once the formation is set, inspect the camp before anything else.”
The pact is signed, the law is carved — but a wise commander still inspects the granaries in person to confirm the supplies are truly in place.
Tally the Total Stores
df -h /media/unified
This command shows the combined capacity of both NAS units. If Cao Cao’s side has 2TB and Sun Quan’s has 3TB, you should see roughly 5TB of available space. The feeling of uniting all storage under heaven — there is nothing quite like it.
Test the Supply Dispatch
Create a large file in /media/unified, then check /mnt/storage1 and /mnt/storage2 — which granary received the new shipment? If the strategist’s category.create=mfs policy is working, it should appear on whichever side has more free space.
A Note on Network Bandwidth
Remember, the underlying transport is NFS over the network. Your merged storage performance is bounded by network bandwidth — no matter how wide the supply road, if the courier horses are slow, the grain arrives late. A 1Gbps or faster LAN is recommended. Otherwise, large file transfers will teach you what the ancients meant by “shipping grain a thousand miles by ox cart.”
Luo Guanzhong’s Verdict
Luo Guanzhong writes: “I have surveyed the storage of all under heaven, and its state is like the warring kingdoms. Each NAS holds its own territory, files scattered across the four corners, and the user marches wearily between them, searching without rest. mergerfs is the grand alliance strategy — it moves not a single brick, relocates not a single file, yet through a mere virtual layer it unites all domains as one. Access flows as naturally as the arm commands the fingers. In the art of war, the supreme strategy is to subdue the enemy without battle; in the art of storage, the supreme strategy is to unify without moving a single file. Those who master this art may truly be called united without migration, commanding without movement — storage in concert, responding as one.“
May your storage dominion, from this day forward, be united under heaven — with no more kingdoms at war.
日本語版
序章:天下の記憶域、分久必合
天下の大勢を語れば、分かれること久しければ必ず合し、合すること久しければ必ず分かる。ストレージの道もまた然り。
手元に NAS が二台あるとしましょう。一台は動画アーカイブ、もう一台は書類保管庫。ファイルを探すたびに、「これは曹操の許昌糧倉に置いたか、それとも孫権の江東魚米庫か?」と自問する羽目になります——まるで三國志の地図を広げて兵糧の在り処を探すようなもの。ファイルが見つかる前に、先に気力が尽きてしまいます。
そこで必要になるのが mergerfs です。
mergerfs は Union Filesystem の一種です。元のディスク上のデータには一切手を触れず、その上に仮想レイヤーを構築して、散在するストレージを統一的に指揮します。一言で言えば:mergerfs は諸葛亮その人。城を一つも移さず、地図と羽扇だけで三軍の兵糧を意のままに采配する軍師なのです。
曹操の許昌糧倉 (NAS A) ──┐
├──→ /media/unified(大本営 — 統一入口)
孫権の江東魚米庫 (NAS B) ──┘
本記事では、三國志の用兵術になぞらえて mergerfs によるストレージ統合の完全な戦術を解説します。すべてのコマンドは実戦検証済み。そのままコピーしてご活用ください。出陣の前に、まず軍需物資を整えましょう:
# NFS クライアントをインストール(遠方の糧倉と通信する駅馬)
sudo apt install nfs-common
# mergerfs をインストール(統一指揮を執る軍師本人)
sudo apt install mergerfs
上策:陣営構築 — リモート兵糧庫のマウント
策略口伝:「兵糧未だ動かず、陣営先に立つべし。」
戦の第一歩は突撃ではなく、各諸侯の城外に自軍の陣営を築くことです。リモート NFS ストレージをローカルディレクトリにマウントするということは、曹操の許昌城外と孫権の建業城外にそれぞれ前線基地を設営し、いつでも兵糧を調達できる態勢を整えることに他なりません。
まず、我が軍の配置図をご覧ください:
| 役割 | リモートパス(例) | ローカルマウントポイント | 説明 |
|---|---|---|---|
| 曹操の許昌糧倉 | SERVER_A_IP:/data1 | /mnt/storage1 | 第一のバックエンドストレージ |
| 孫権の江東魚米庫 | SERVER_B_IP:/data2 | /mnt/storage2 | 第二のバックエンドストレージ |
| 大本営 | N/A | /media/unified | エンドユーザー向け統一アクセスポイント |
# マウントディレクトリを作成(陣営の地盤を固める)
sudo mkdir -p /mnt/storage1 /mnt/storage2
# 第一の NAS をマウント(soft mount でネットワーク切断時のシステム凍結を防止)
sudo mount -t nfs -o soft,timeo=30,retrans=3 SERVER_A_IP:/data1 /mnt/storage1
# 第二の NAS をマウント
sudo mount -t nfs -o defaults SERVER_B_IP:/data2 /mnt/storage2
ここで一つ戦術上の要点を。第一の NAS には soft,timeo=30,retrans=3 を指定しています。平たく言えば「曹操の糧倉が三十秒応答しなければ、三回再試行して撤退せよ」ということです。なぜか?NFS の既定動作は hard mount——ネットワークが切れると、システムは麦城に籠もった関羽のように退却を拒否し、マシン全体が永遠に固まってしまうのです。soft mount とは「勝てぬと見れば退く」戦法。時勢を知る者こそ真の英雄というものです。
中策:合従連衡 — mergerfs 統一指揮
策略口伝:「諸侯は遷都の必要なし、一紙の盟約で天下を号令すべし。」
陣営は築き、補給路も開通しました。しかしファイルを取りに行くたびに /mnt/storage1 と /mnt/storage2 を別々に訪ねなければならない——同盟を結んだというのに、兵糧の調達ごとに許昌と建業へ個別に使者を送るようなものです。実に煩わしい。
ここで我らが軍師・諸葛亮——mergerfs の出番です。一袋の兵糧も動かさず、倉庫の構造も一切変えず、ただその上に統一指揮レイヤーを敷くだけ。大本営 /media/unified という一つの門から、全ての糧倉にアクセスできるようにしてくれます。
# 統一入口を作成(大本営の帥帳)
sudo mkdir -p /media/unified
# 統合コマンドを実行(諸葛亮、地図を広げて合従連衡を発動)
sudo mount -t fuse.mergerfs \
-o defaults,allow_other,use_ino,nonempty,category.create=mfs,minfreespace=10G \
/mnt/storage1:/mnt/storage2 \
/media/unified
このコマンドこそが、全戦役の核心たる盟約です。軍師の配備戦略をパラメータごとに読み解きましょう:
defaults— 標準的なマウントパラメータ(rw, suid, dev 等)。堅実な基本装備——行軍に欠かせません。allow_other— 全ての将兵にアクセスを許可。大将軍だけではありません。このパラメータがなければ root のみがアクセスでき、他の全員が帥帳の入口で門前払いを食らいます。category.create=mfs— Most Free Space:軍師の最も精妙な采配戦略。新たな兵糧は、残り容量が最も多い糧倉へ自動的に送られます。曹操側がまだ八割の空きがあり、孫権側は二割しか残っていない?次の荷は全て許昌へ。軍師が自動で采配するので、大将軍が気を揉む必要はありません。minfreespace=10G— 備蓄が十石を下回れば搬入を停止。いずれかの糧倉の空き容量が 10GB を切ると、軍師は自動的にそこへの新規書き込みを止めます——爆倉の危機を未然に防ぐのです。use_ino— 全ての兵糧袋に唯一無二の封印(inode)を付与。異なる糧倉の荷が番号で衝突するのを防ぎます。nonempty— 既に物資がある陣営への進駐を許可。このパラメータがなければ、大本営ディレクトリに既存ファイルがある場合、門の前で入場を拒否されてしまいます。/mnt/storage1:/mnt/storage2— コロンは各糧倉を結ぶ駅路。第三の諸侯を加えたい場合は、コロンとパスをもう一つ追加するだけ。同盟の拡大とはこれほど簡単なのです。
下策:社稷永鎮 — fstab 恒久設定
策略口伝:「臨時の軍令は一戦に勝てるのみ、国法こそが天下を定める。」
ここまでの操作は全て一時的なもの——マシンを再起動すれば盟約は破棄され、補給路は途絶え、大本営は本当の空城計を演じる羽目になります。この配備を恒久化するには、臨時の軍令を国法に刻む必要があります:/etc/fstab です。
# [NFS Mounts]
SERVER_A_IP:/data1 /mnt/storage1 nfs soft,timeo=30,retrans=3 0 0
SERVER_B_IP:/data2 /mnt/storage2 nfs defaults 0 0
# [mergerfs Pool]
/mnt/storage1:/mnt/storage2 /media/unified fuse.mergerfs defaults,allow_other,use_ino,category.create=mfs,minfreespace=10G 0 0
国法に刻む前にご注意を:まず陣法を試してから兵書に記すべし。先に前述の手動コマンドで全てが正常に動作することを確認し、それから fstab に書き込んでください。万が一記述を間違えれば、起動不能に陥ります——それはもはや三國志ではなく、悲劇です。
兵糧庫巡察:検証
策略口伝:「布陣已に畢わらば、巡営を先とすべし。」
盟約を結び、国法に刻んだとはいえ、賢明な将は自ら糧倉を巡察し、兵糧が確実に揃っていることを確認するものです。
兵糧総量の点検
df -h /media/unified
このコマンドは二台の NAS の合計容量を表示します。曹操側が 2TB、孫権側が 3TB であれば、合計約 5TB の利用可能領域が確認できるはずです。天下のストレージを統一した感覚——これほど爽快なものはありません。
兵糧輸送のテスト
/media/unified に大きなファイルを作成し、/mnt/storage1 と /mnt/storage2 を確認してみてください。新しいファイルはどちらの糧倉に送られたでしょうか?軍師の category.create=mfs 戦略が有効であれば、空き容量の多い側に配置されているはずです。
ネットワーク帯域に関する注意
お忘れなく。基盤となる転送は NFS ネットワーク通信です。統合ストレージの性能はネットワーク帯域に制約されます——補給路がいくら広くても、駅馬が遅ければ兵糧の到着も遅れるのです。1Gbps 以上の LAN 環境での運用を推奨します。さもなければ、大容量ファイルの転送で「千里の糧道、牛車の如し」という古人の辛苦を身をもって体験することになるでしょう。
羅貫中曰く
羅貫中曰く:「余、天下のストレージを観るに、その勢は列国の如し。NAS は各々一方に割拠し、ファイルは四方に散逸し、使用者はその間を奔走して疲弊す。mergerfs とは合従連衡の策なり。一磚一瓦を動かさず、一ファイル一案件を移さず、ただ仮想のレイヤーをもって万方を統合し、分散せし糧倉を一体と化す。アクセスは臂の指を使うが如く自在なり。用兵の道、上策は心を攻め、戦わずして人の兵を屈す。ストレージの道、上策は合併し、動かずして天下のファイルを統ぶ。この術を修めし者、まことに遷さずして合し、動かずして統べ、容量は連合し、采配は意のままと称すべし。」
あなたのストレージ版図が、今日より天下統一を果たし、二度と紛争なきことを願います。
