使用Stratis從命令行管理Linux存儲(chǔ)
通過從命令行運(yùn)行它,得到這個(gè)易于使用的 Linux 存儲(chǔ)工具的主要用途。
正如本系列的***部分和第二部分中所討論的,Stratis 是一個(gè)具有與 ZFS 和 Btrfs 相似功能的卷管理文件系統(tǒng)。在本文中,我們將介紹如何在命令行上使用 Stratis。
安裝 Stratis
對(duì)于非開發(fā)人員,現(xiàn)在嘗試 Stratis 最簡(jiǎn)單的方法是在 Fedora 28 中。
你可以用以下命令安裝 Stratis 守護(hù)進(jìn)程和 Stratis 命令行工具:
# dnf install stratis-cli stratisd
創(chuàng)建一個(gè)池
Stratis 有三個(gè)概念:blockdevs、池和文件系統(tǒng)。 Blockdevs 是組成池的塊設(shè)備,例如磁盤或磁盤分區(qū)。一旦創(chuàng)建池,就可以從中創(chuàng)建文件系統(tǒng)。
假設(shè)你的系統(tǒng)上有一個(gè)名為 vdg
的塊設(shè)備,它目前沒有被使用或掛載,你可以在它上面創(chuàng)建一個(gè) Stratis 池:
# stratis pool create mypool /dev/vdg
這假設(shè) vdg
是完全清零并且是空的。如果它沒有被使用,但有舊數(shù)據(jù),則可能需要使用 pool create
的 -force
選項(xiàng)。如果正在使用,請(qǐng)勿將它用于 Stratis。
如果你想從多個(gè)塊設(shè)備創(chuàng)建一個(gè)池,只需在 pool create
命令行中列出它們。你也可以稍后使用 blockdev add-data
命令添加更多的 blockdevs。請(qǐng)注意,Stratis 要求 blockdevs 的大小至少為 1 GiB。
創(chuàng)建文件系統(tǒng)
在你創(chuàng)建了一個(gè)名為 mypool
的池后,你可以從它創(chuàng)建文件系統(tǒng):
# stratis fs create mypool myfs1
從 mypool
池創(chuàng)建一個(gè)名為 myfs1
的文件系統(tǒng)后,可以使用 Stratis 在 /dev/stratis
中創(chuàng)建的條目來掛載并使用它:
# mkdir myfs1
# mount /dev/stratis/mypool/myfs1 myfs1
文件系統(tǒng)現(xiàn)在已被掛載在 myfs1
上并準(zhǔn)備可以使用。
快照
除了創(chuàng)建空文件系統(tǒng)之外,你還可以創(chuàng)建一個(gè)文件系統(tǒng)作為現(xiàn)有文件系統(tǒng)的快照:
# stratis fs snapshot mypool myfs1 myfs1-experiment
這樣做后,你可以掛載新的 myfs1-experiment
,它將初始包含與 myfs1
相同的文件內(nèi)容,但它可能隨著文件系統(tǒng)的修改而改變。無論你對(duì) myfs1-experiment
所做的任何更改都不會(huì)反映到 myfs1
中,除非你卸載了 myfs1
并將其銷毀:
# umount myfs1
# stratis fs destroy mypool myfs1
然后進(jìn)行快照以重新創(chuàng)建并重新掛載它:
# stratis fs snapshot mypool myfs1-experiment myfs1
# mount /dev/stratis/mypool/myfs1 myfs1
獲取信息
Stratis 可以列出系統(tǒng)中的池:
# stratis pool list
隨著文件系統(tǒng)寫入更多數(shù)據(jù),你將看到 “Total Physical Used” 值的增加。當(dāng)這個(gè)值接近 “Total Physical Size” 時(shí)要小心。我們?nèi)栽谂μ幚磉@個(gè)問題。
列出池中的文件系統(tǒng):
# stratis fs list mypool
列出組成池的 blockdevs:
# stratis blockdev list mypool
目前只提供這些最少的信息,但它們將在未來提供更多信息。
摧毀池
當(dāng)你了解了 Stratis 可以做什么后,要摧毀池,首先確保從它創(chuàng)建的所有文件系統(tǒng)都被卸載并銷毀,然后使用 pool destroy
命令:
# umount myfs1
# umount myfs1-experiment (if you created it)
# stratis fs destroy mypool myfs1
# stratis fs destroy mypool myfs1-experiment
# stratis pool destroy mypool
stratis pool list
現(xiàn)在應(yīng)該顯示沒有池。