Filesystem Hierarchy Standard (FHS) "
FHS actually talks about 3 major portions of Linux File System
root
boot process and system management related
usrstands for Unix software resource, i.e. most of the program will be installed and configured here
varvariable, system running related files
static and variable, share and unshare.png
Root Directory - Starts From "/"
reference: http://cn.linux.vbird.org/linux_basic/0210filepermission.php#dir_fhs
some of the refs have been deprecated or obsoleted
目錄 | 應(yīng)放置文件內(nèi)容 |
---|---|
/bin | 系統(tǒng)有很多放置執(zhí)行文件的目錄,但/bin比較特殊抖坪。因?yàn)?bin放置的是在單人維護(hù)模式下還能夠被操作的指令熊楼。 在/bin底下的指令可以被root與一般賬號(hào)所使用辫狼,主要有:cat, chmod, chown, date, mv, mkdir, cp, bash等等常用的指令厘熟。 |
/boot | 這個(gè)目錄主要在放置開機(jī)會(huì)使用到的文件,包括Linux核心文件以及開機(jī)選單與開機(jī)所需配置文件等等捎谨。 Linux kernel常用的檔名為:vmlinuz曼库,如果使用的是grub這個(gè)開機(jī)管理程序, 則還會(huì)存在/boot/grub/這個(gè)目錄喔臀防! |
/dev | 在Linux系統(tǒng)上脊串,任何裝置與接口設(shè)備都是以文件的型態(tài)存在于這個(gè)目錄當(dāng)中的。 你只要透過(guò)存取這個(gè)目錄底下的某個(gè)文件清钥,就等于存取某個(gè)裝置啰~ 比要重要的文件有/dev/null, /dev/zero, /dev/tty, /dev/lp, /dev/hd, /dev/sd*等等 |
/etc | 系統(tǒng)主要的配置文件幾乎都放置在這個(gè)目錄內(nèi)琼锋,例如人員的賬號(hào)密碼文件、 各種服務(wù)的啟始檔等等祟昭。一般來(lái)說(shuō)缕坎,這個(gè)目錄下的各文件屬性是可以讓一般使用者查閱的, 但是只有root有權(quán)力修改篡悟。FHS建議不要放置可執(zhí)行文件(binary)在這個(gè)目錄中喔谜叹。比較重要的文件有: /etc/inittab, /etc/init.d/, /etc/modprobe.conf, /etc/X11/, /etc/fstab, /etc/sysconfig/ 等等。另外搬葬,其下重要的目錄有:/etc/init.d/:所有服務(wù)的預(yù)設(shè)啟動(dòng) script 都是放在這里的荷腊,例如要啟動(dòng)或者關(guān)閉 iptables 的話:『 /etc/init.d/iptables start』、『/etc/init.d/iptables stop』/etc/xinetd.d/:這就是所謂的super daemon管理的各項(xiàng)服務(wù)的配置文件目錄急凰。/etc/X11/:與 X Window 有關(guān)的各種配置文件都在這里女仰,尤其是 xorg.conf 這個(gè) X Server 的配置文件。 |
/home | 這是系統(tǒng)默認(rèn)的用戶家目錄(home directory)抡锈。在你新增一個(gè)一般使用者賬號(hào)時(shí)疾忍, 默認(rèn)的用戶家目錄都會(huì)規(guī)范到這里來(lái)。比較重要的是床三,家目錄有兩種代號(hào)喔: ~:代表目前這個(gè)用戶的家目錄一罩,而 ~dmtsai :則代表 dmtsai 的家目錄! |
/lib | 系統(tǒng)的函式庫(kù)非常的多撇簿,而/lib放置的則是在開機(jī)時(shí)會(huì)用到的函式庫(kù)聂渊, 以及在/bin或/sbin底下的指令會(huì)呼叫的函式庫(kù)而已。 什么是函式庫(kù)呢四瘫?妳可以將他想成是『外掛』汉嗽,某些指令必須要有這些『外掛』才能夠順利完成程序的執(zhí)行之意。 尤其重要的是/lib/modules/這個(gè)目錄莲组, 因?yàn)樵撃夸洉?huì)放置核心相關(guān)的模塊(驅(qū)動(dòng)程序)喔诊胞! |
/media | media是『媒體』的英文,顧名思義,這個(gè)/media底下放置的就是可移除的裝置啦撵孤! 包括軟盤迈着、光盤、DVD等等裝置都暫時(shí)掛載于此邪码。常見的檔名有:/media/floppy, /media/cdrom等等裕菠。 |
/mnt | 如果妳想要暫時(shí)掛載某些額外的裝置,一般建議妳可以放置到這個(gè)目錄中闭专。 在古早時(shí)候奴潘,這個(gè)目錄的用途與/media相同啦!只是有了/media之后影钉,這個(gè)目錄就用來(lái)暫時(shí)掛載用了画髓。 |
/opt | 這個(gè)是給第三方協(xié)力軟件放置的目錄。什么是第三方協(xié)力軟件捌轿奈虾? 舉例來(lái)說(shuō),KDE這個(gè)桌面管理系統(tǒng)是一個(gè)獨(dú)立的計(jì)劃廉赔,不過(guò)他可以安裝到Linux系統(tǒng)中肉微,因此KDE的軟件就建議放置到此目錄下了。 另外蜡塌,如果妳想要自行安裝額外的軟件(非原本的distribution提供的)碉纳,那么也能夠?qū)⒛愕能浖惭b到這里來(lái)。 不過(guò)馏艾,以前的Linux系統(tǒng)中劳曹,我們還是習(xí)慣放置在/usr/local目錄下呢! |
/root | 系統(tǒng)管理員(root)的家目錄攒至。之所以放在這里厚者,是因?yàn)槿绻M(jìn)入單人維護(hù)模式而僅掛載根目錄時(shí)躁劣, 該目錄就能夠擁有root的家目錄迫吐,所以我們會(huì)希望root的家目錄與根目錄放置在同一個(gè)分割槽中。 |
/sbin | Linux有非常多指令是用來(lái)設(shè)定系統(tǒng)環(huán)境的账忘,這些指令只有root才能夠利用來(lái)『設(shè)定』系統(tǒng)志膀,其他用戶最多只能用來(lái)『查詢』而已。 放在/sbin底下的為開機(jī)過(guò)程中所需要的鳖擒,里面包括了開機(jī)溉浙、修復(fù)、還原系統(tǒng)所需要的指令蒋荚。 至于某些服務(wù)器軟件程序戳稽,一般則放置到/usr/sbin/當(dāng)中。至于本機(jī)自行安裝的軟件所產(chǎn)生的系統(tǒng)執(zhí)行文件(system binary), 則放置到/usr/local/sbin/當(dāng)中了惊奇。常見的指令包括:fdisk, fsck, ifconfig, init, mkfs等等互躬。 |
/srv | srv可以視為『service』的縮寫,是一些網(wǎng)絡(luò)服務(wù)啟動(dòng)之后颂郎,這些服務(wù)所需要取用的數(shù)據(jù)目錄吼渡。 常見的服務(wù)例如WWW, FTP等等。舉例來(lái)說(shuō)乓序,WWW服務(wù)器需要的網(wǎng)頁(yè)數(shù)據(jù)就可以放置在/srv/www/里面寺酪。 |
/tmp | 這是讓一般使用者或者是正在執(zhí)行的程序暫時(shí)放置文件的地方。 這個(gè)目錄是任何人都能夠存取的替劈,所以你需要定期的清理一下寄雀。當(dāng)然,重要數(shù)據(jù)不可放置在此目錄霸上住咙俩! 因?yàn)镕HS甚至建議在開機(jī)時(shí),應(yīng)該要將/tmp下的數(shù)據(jù)都刪除嗍省阿趁! |
事實(shí)上FHS針對(duì)根目錄所定義的標(biāo)準(zhǔn)就僅有上面的咚咚,不過(guò)我們的Linux底下還有許多目錄你也需要了解一下的坛猪。 底下是幾個(gè)在Linux當(dāng)中也是非常重要的目錄喔:
目錄 | 應(yīng)放置文件內(nèi)容 |
---|---|
/lost+found | 這個(gè)目錄是使用標(biāo)準(zhǔn)的ext2/ext3文件系統(tǒng)格式才會(huì)產(chǎn)生的一個(gè)目錄脖阵,目的在于當(dāng)文件系統(tǒng)發(fā)生錯(cuò)誤時(shí), 將一些遺失的片段放置到這個(gè)目錄下墅茉。這個(gè)目錄通常會(huì)在分割槽的最頂層存在命黔, 例如你加裝一顆硬盤于/disk中,那在這個(gè)系統(tǒng)下就會(huì)自動(dòng)產(chǎn)生一個(gè)這樣的目錄『/disk/lost+found』 |
/proc | 這個(gè)目錄本身是一個(gè)『虛擬文件系統(tǒng)(virtual filesystem)』喔就斤!他放置的數(shù)據(jù)都是在內(nèi)存當(dāng)中悍募, 例如系統(tǒng)核心、行程信息(process)洋机、周邊裝置的狀態(tài)及網(wǎng)絡(luò)狀態(tài)等等坠宴。因?yàn)檫@個(gè)目錄下的數(shù)據(jù)都是在內(nèi)存當(dāng)中, 所以本身不占任何硬盤空間氨疗臁喜鼓!比較重要的文件例如:/proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net/* 等等。 |
/sys | 這個(gè)目錄其實(shí)跟/proc非常類似衔肢,也是一個(gè)虛擬的文件系統(tǒng)庄岖,主要也是記錄與核心相關(guān)的信息。 包括目前已加載的核心模塊與核心偵測(cè)到的硬件裝置信息等等角骤。這個(gè)目錄同樣不占硬盤容量喔隅忿! |
除了這些目錄的內(nèi)容之外,另外要注意的是,因?yàn)楦夸浥c開機(jī)有關(guān)背桐,開機(jī)過(guò)程中僅有根目錄會(huì)被掛載刘陶, 其他分割槽則是在開機(jī)完成之后才會(huì)持續(xù)的進(jìn)行掛載的行為。就是因?yàn)槿绱死魏常虼烁夸浵屡c開機(jī)過(guò)程有關(guān)的目錄匙隔, 就不能夠與根目錄放到不同的分割槽去!那哪些目錄不可與根目錄分開呢熏版?有底下這些:
/etc:配置文件
/bin:重要執(zhí)行檔
/dev:所需要的裝置文件
/lib:執(zhí)行檔所需的函式庫(kù)與核心所需的模塊
/sbin:重要的系統(tǒng)執(zhí)行文件
-
Devices and Naming Convention
Since all entities include devices are all files within Linux System, therefore, the rules for naming convention
Devices | Name |
---|---|
IDE | /dev/hd[a-z] |
SCSI/SATA/ThumDrive | /dev/sd[a-z] |
VirtIO (參考https://www.cnblogs.com/bakari/p/8309638.html) | /dev/vd[a-z] |
Floppy Drive | /dev/fd[0-1] |
Printer | /dev/lp[0-15] |
CDROM | /dev/cdrom |
Mouse | /dev/mouse |
Mgnetic Tape | /dev/st0[ht0] |
Things need to be aware:
- The
physical slots
!=device naming order
/dev/sda != the 1st slot of your harddisk
- The
number
of device label !=total amount of devices
/dev/sda3 != there are 3 partitions in total, it could be the third partition and omit the 1st and 2nd partition since the number can be assigned manually
- Hardisk consist of tons of sectors, each sector has 512 bytes
- The first sector is one of the most important sectors for which it contains Master Boot Record(MBR) and partition table
- MBR takes 446 bytes, and the rest 66 bytes (partition table takes 64 bytes, terminator takes 2 bytes
- The 64 bytes can be divided into 4 partitions with each of 16 bytes. If there are more than 4 partitions then we use one 16 bytes with single linked table pointer to create an extended partition, from there the logical partition can be generated.
So Basically the system can recognize 3 major partitions at most and then a limited number of logical partitions
Filesystem
EXT2 earlier file system, it was born in 1993, not safe, obsoleted
EXT3 journaling file system, it allows data recovery but the speed is slow
EXT4 improved version of EXT3, rhel6 default file system, support 1EB(1,073,741,824GB) at most, unlimited sub-directories, assign blocks in batches(improved performance for reading and writing), etc...
XFS high-performance journaling file system, support 18EB at most
Important terms:
參考 http://linux.vbird.org/linux_basic_train/unit06.php
-
superblock
record of the entire structure of the file system, including inode/block amount, file system format, relative information, etc...
superblock 為整個(gè)檔案系統(tǒng)的總結(jié)資訊處纷责,要讀取檔案系統(tǒng)一定要從 superblock 讀起。superblock 主要紀(jì)錄資料為:
block 與 inode 的總量撼短;
未使用與已使用的 inode / block 數(shù)量再膳;
block 與 inode 的大小 (block 為 1, 2, 4K,inode 為 128bytes 或 256bytes)曲横;
filesystem 的掛載時(shí)間喂柒、最近一次寫入資料的時(shí)間、最近一次檢驗(yàn)磁碟 (fsck) 的時(shí)間等檔案系統(tǒng)的相關(guān)資訊禾嫉;
一個(gè) valid bit 數(shù)值灾杰,若此檔案系統(tǒng)已被掛載,則 valid bit 為 0 熙参,若未被掛載艳吠,則 valid bit 為 1
-
block
the actual data, if the data is too large, then one file will take multiple blocks
檔案實(shí)際的資料存放在 data block 上面,每個(gè) block 也都會(huì)有號(hào)碼孽椰,提供給檔案來(lái)儲(chǔ)存實(shí)際資料昭娩,也讓 inode 可以紀(jì)錄資料放在哪個(gè) block 號(hào)碼內(nèi)。
原則上黍匾,block 的大小與數(shù)量在格式化完就不能夠再改變了(除非重新格式化)栏渺;
每個(gè) block 內(nèi)最多只能夠放置一個(gè)檔案的資料;
承上锐涯,如果檔案大於 block 的大小磕诊,則一個(gè)檔案會(huì)佔(zhàn)用多個(gè) block 數(shù)量;
承上全庸,若檔案小於 block 秀仲,則該 block 的剩餘容量就不能夠再被使用了(磁碟空間會(huì)浪費(fèi))。
一般來(lái)說(shuō)壶笼,檔案系統(tǒng)內(nèi)的一個(gè)檔案被讀取時(shí),流程是這樣的:
讀到檔案的 inode 號(hào)碼
由 inode 內(nèi)的權(quán)限設(shè)定判定使用者能否存取此檔案
若能讀取則開始讀取 inode 內(nèi)所紀(jì)錄的資料放置於哪些 block 號(hào)碼內(nèi)
讀出 block 號(hào)碼內(nèi)的資料雁刷,組合起來(lái)成為一個(gè)檔案的實(shí)際內(nèi)容覆劈。
至於新建檔案的流程則是這樣的:
有寫入檔案的需求時(shí),先到 metadata 區(qū)找到?jīng)]有使用中的 inode 號(hào)碼
到該 inode 號(hào)碼內(nèi),將所需要的權(quán)限與屬性相關(guān)資料寫入责语,然後在 metadata 區(qū)規(guī)範(fàn)該 inode 為使用中炮障,且更新 superblock 資訊
到 metadata 區(qū)找到?jīng)]有使用中的 block 號(hào)碼,將所需要的實(shí)際資料寫入 block 當(dāng)中坤候,若資料量太大胁赢,則繼續(xù)到 metadata 當(dāng)中找到更多的未使用中的 block 號(hào)碼,持續(xù)寫入白筹,直到寫完資料為止智末。
同步更新 inode 的紀(jì)錄與 superblock 的內(nèi)容。
至於刪除檔案的流程則是這樣的:
將該檔案的 inode 號(hào)碼與找到所屬相關(guān)的 block 號(hào)碼內(nèi)容抹除
將 metadata 區(qū)域的相對(duì)應(yīng)的 inode 與 block 號(hào)碼規(guī)範(fàn)為未使用徒河。
同步更新 superblock 資料系馆。
-
inode
record of the file property, it contains inode number, block number, etc...
每一個(gè) inode 都有號(hào)碼,而 inode 的內(nèi)容在記錄檔案的屬性以及該檔案實(shí)際資料是放置在哪幾號(hào) block 內(nèi)顽照。 inode 記錄的檔案資料至少有底下這些:
該檔案的存取模式(read/write/excute)由蘑;
該檔案的擁有者與群組(owner/group);
該檔案的容量代兵;
該檔案建立或狀態(tài)改變的時(shí)間(ctime)尼酿;
最近一次的讀取時(shí)間(atime);
最近修改的時(shí)間(mtime)植影;
定義檔案特性的旗標(biāo)(flag)谓媒,如 SetUID...;
該檔案真正內(nèi)容的指向 (pointer)何乎;
由於每個(gè)檔案固定會(huì)佔(zhàn)用一個(gè) inode句惯,而目前檔案所記載的屬性資料越來(lái)約多,因此 inode 有底下幾個(gè)特色:
每個(gè) inode 大小均固定為 128 bytes (新的 ext4 與 xfs 可設(shè)定到 256 bytes)支救;
每個(gè)檔案都僅會(huì)佔(zhàn)用一個(gè) inode 而已抢野;
承上,因此檔案系統(tǒng)能夠建立的檔案數(shù)量與 inode 的數(shù)量有關(guān)各墨;
系統(tǒng)讀取檔案時(shí)需要先找到 inode指孤,並分析 inode 所記錄的權(quán)限與使用者是否符合,若符合才能夠開始實(shí)際讀取 block 的內(nèi)容贬堵。
Virtual File System let the user manipulate files without considering in detail how the underlying structure works, i.e. whatever the operating system you are working with, surely there will be a command like cp or copy
that allow you to copy the file in your file system.
Mounting File System
Mount command allows the user to hook
the device file with the kernel
, therefore the device then can be read, written, and executed
.
parameters | how |
---|---|
-a | mount all file system in the definition of /etc/fstab |
-t | assign the type of the target file system |
[root@linuxprobe media]# mount /dev/sda1 /media/disks/oneG
[root@linuxprobe oneG]# cd /media/disks/oneG/
[root@linuxprobe oneG]# tree
.
└── lost+found
1 directory, 0 files
[root@linuxprobe oneG]# vim /etc/fstab
# user defined
/dev/sda1 /media/disks/oneG etx4 defaults 0 0
In Linux system, to mount a file system you cannot count on device name + number in all situation since the name could vary, rather, a UUID
often a better choice for relibility
What is UUID
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. The term globally unique identifier (GUID) is also used, typically in software created by Microsoft.
image.png
# user defined
# /dev/sda1 /media/disks/oneG etx4 defaults 0 0
UUID=488f3d14-6582-4981-b734-d86b6c49db94 /media/disks/oneG etx4 defaults 0 0
[root@linuxprobe oneG]# sync;
[root@linuxprobe oneG]# reboot
To make the fstab
take effect, we need to run the following command
mount -a # mount all potentially-available mount points
for network storage device, we'd better add _netdev
parameter in fstab
# iscsi is based on TCP/IP protocol, so therefore, _netdev parameter can make sure the device will be
# mounted after network is connected, in order to prevent the long waiting boot time
UUID=eb9cbf2f-fce8-413a-b770-8b0f243e8ad6 /iscsi xfs defaults,_netdev 0 0
df and lsblk
Both of them will
detect and represent
the hard disk information
Check thefree space
of your hard disk,df -h
, human-readable
Making better sense of the storage system structure,lsblk
, tree-shape
[root@linuxprobe ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 9.9M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/rhel_linuxprobe-root 17G 4.1G 13G 24% /
/dev/sr0 6.7G 6.7G 0 100% /media/dvd
/dev/nvme0n1p1 1014M 169M 846M 17% /boot
tmpfs 780M 16K 780M 1% /run/user/42
tmpfs 780M 3.5M 776M 1% /run/user/1000
[root@linuxprobe ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 5G 0 disk
sr0 11:0 1 6.6G 0 rom /media/dvd
nvme0n1 259:0 0 20G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
└─nvme0n1p2 259:2 0 19G 0 part
├─rhel_linuxprobe-root 253:0 0 17G 0 lvm /
└─rhel_linuxprobe-swap 253:1 0 2G 0 lvm [SWAP]
Adding new hard disk, SWAP partition
-
Adding hard disk for vmware
virtual machine allows us to scale the storage system in a much nice way
image.png -
fdisk manipulate disk partition table, this command asks user question and gives hint which is very much
user-friendly
as well asversatile
parameters outcome m complete help information n add new partition d delete some partition l list all the viable file system type t change file system type for specified partition p check hte partition table w save and quit q exit without save # list all the partitions fdisk -l # enter edit mode for a particular hard disk [root@linuxprobe ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x88b8f279. Command (m for help):... Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-10485759, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +1G Created a new partition 1 of type 'Linux' and of size 1 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@linuxprobe ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@linuxprobe ~]# file /dev/sda1 /dev/sda1: block special (8/1)
-
mkfs - formatting the device
[root@linuxprobe ~]# mkfs.xfs /dev/sda1 meta-data=/dev/sda1 isize=512 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
-
check the file system type and relative information
[root@linuxprobe ~]# df -T /dev/sda1 Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 xfs 1038336 40368 997968 4% /run/media/linuxprobe/0478a8eb-2cee-4d4f-a00a- 641e41aedd86 # check the partition or directory usage with du command [root@linuxprobe ~]# du -sh /* 0 /bin 130M /boot 0 /dev 29M /etc 29M /home 0 /lib 0 /lib64 6.7G /media 0 /mnt 0 /opt # cp /etc/* to new created /dev/sda1 [root@linuxprobe ~]# cp -fr /etc/* /media/sda1/ # check the file usage of new created /dev/sda1 [root@linuxprobe media]# du -sh /media/sda1 # du with -h parameter - human readable 29M /media/sda1
Adding SWAP Partition
similar to
virtual memory
, helping to acquire some free space by using the hard disk space when the physical memory is used up.
-
make swap partition
[root@linuxprobe media]# fdisk /dev/sda Welcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Device Boot Start End Sectors Size Id Type /dev/sda1 2048 2099199 2097152 1G 83 Linux /dev/sda2 2099200 4196351 2097152 1G 82 Linux swap / Solaris
-
mkswap and swapon
root@linuxprobe media]# swapoff /dev/sdb1 [root@linuxprobe media]# mkswap /dev/db1 mkswap: cannot open /dev/db1: No such file or directory [root@linuxprobe media]# mkswap /dev/sdb1 mkswap: /dev/sdb1: warning: wiping old swap signature. Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=2fb7a5d5-aad0-4f42-9b3f-1ad1788edeed [root@linuxprobe media]# swapon /dev/sdb1 [root@linuxprobe media]# swapon NAME TYPE SIZE USED PRIO /dev/sdb1 partition 1024M 0B -3 /dev/dm-1 partition 2G 0B -2
disk quotation
In order to prevent the disk space is going to be filled with various user data, there is a command that can allocate disk space for the user in a much more appropriate way.
-
xfs_quota - a quotation utility that was designed for the XFS file system particularly
[root@linuxprobe ~]# chmod -R o+w /boot [root@linuxprobe ~]# useradd quotaTest [root@linuxprobe ~]# xfs_quota -x -c "limit bsoft=3m bhard=6m isoft=3 ihard=6 [root@linuxprobe ~]# xfs_quota -x -c report /boot User quota on /boot (/dev/sda1) Blocks User ID Used Soft Hard Warn/Grace ---------- -------------------------------------------------- root 130840 0 0 00 [--------] quotaTest 0 3072 6144 00 [--------] quotaTest" /boot
difference between soft quotation and hard quotation
- soft quotation only warn user, not to stop the user from writing the data into disk
- hard quotation will stop everything, disallow the user to write data into the disk block once for all
[quotaTest@linuxprobe boot]$ [quotaTest@linuxprobe boot]$ dd if=/dev/zero of=/boot/test bs=5M count=1 1+0 records in 1+0 records out 5242880 bytes (5.2 MB, 5.0 MiB) copied, 0.0111994 s, 468 MB/s # bs=8M broke the rule of bhard=6M which is a hard quotation rule!!! [quotaTest@linuxprobe boot]$ dd if=/dev/zero of=/boot/test bs=8M count=1 dd: error writing '/boot/test': Disk quota exceeded 1+0 records in 0+0 records out 4194304 bytes (4.2 MB, 4.0 MiB) copied, 0.00460679 s, 910 MB/s
-
edquota edit user quotas
parameters outcome -u target user -g target group -p copy original rules to the new user/group -t edit the soft time limits for each file system # open the quotation editor (default vim) for the specified user name [root@linuxprobe ~]# edquota -u quotaTest [root@linuxprobe ~]# dd if=/dev/zero of=/boot/quotaTest bs=8M count=1 1+0 records in 1+0 records out 8388608 bytes (8.4 MB, 8.0 MiB) copied, 0.012372 s, 678 MB/s
VDO virtual Data Optimize
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/deduplicating_and_compressing_storage/maintaining-vdo_deduplicating-and-compressing-storage
manage kernel VDO devices and related configuration information
VDO will compress or delete the duplication within the user data in order to optimize the data storage system and speed up the data access.
Permabit
was purchased byRedhat
and the latter got this new technology
The
encryption layer
must be under VDO-
The VDO technology cannot be
overlapped
image.png -
VDO practise
- create a brand new VDO volume
[root@linuxprobe ~]# ls -l /dev/sdb brw-rw----. 1 root disk 8, 16 Jan 26 00:57 /dev/sdb [root@linuxprobe ~]# vdo create --name=vdo00 --device=/dev/sdb -- vdoLogicalSize=200G Creating VDO vdo00 Starting VDO vdo00 Starting compression on VDO vdo00 VDO instance 0 volume is ready at /dev/mapper/vdo00
- Check VDO status
[root@linuxprobe ~]# vdo status --name=vdo00 VDO status: Date: '2021-01-26 01:02:13-05:00' Node: linuxprobe.com
The status includes VDO volume created time, hostname, duplication and compression flag
- Format and Mount VDO
# Format [root@linuxprobe ~]# mkfs.xfs /dev/mapper/vdo00 # `udevadm settle` waits for `udevd` to process the device creation events # for all hardware devices, thus ensuring that any device nodes have been # created successfully before proceeding. [root@linuxprobe vdo00]# udevadm settle # Mount [root@linuxprobe ~]# mount /dev/mapper/vdo00 /media/vdo/vdo00/
- Check vdo stats
[root@linuxprobe vdo00]# vdostats --human-readable Device Size Used Available Use% Space saving% /dev/mapper/vdo00 20.0G 4.0G 16.0G 20% 99% [root@linuxprobe vdo00]# df -h /dev/mapper/vdo00 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vdo00 200G 1.5G 199G 1% /media/vdo/vdo00
- Test for VDO
- Before large file is copied
[root@linuxprobe ~]# vdostats --human-readable Device Size Used Available Use% Space saving% /dev/mapper/vdo00 20.0G 5.4G 14.6G 26% 7% [root@linuxprobe ~]# df -h /dev/mapper/vdo00 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vdo00 200G 1.5G 199G 1% /media/vdo/vdo00
- After the large file is copied
The advantage of the use of VDO is quite obvious[root@linuxprobe ~]# vdostats --human-readable Device Size Used Available Use% Space saving% /dev/mapper/vdo00 20.0G 5.4G 14.6G 26% 7% [root@linuxprobe ~]# df -h /dev/mapper/vdo00 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vdo00 200G 2.9G 198G 2% /media/vdo/vdo00
Before
the large file ....mp4 is copied, thephysical
available space was 5.4G,After
the large file ...mp4 is copied, thephysical
available space is still the same, where the VDO space is changed just a little bit - Add VDO mount point to
fstab
Notice the _netdev parameter,it makes sure the vdo device will be mounted after system and network are all set
[root@linuxprobe ~]# blkid /dev/mapper/vdo00 /dev/mapper/vdo00: UUID="926f56ed-0a52-4647-9004-8edb67edcc7e" TYPE="xfs" [root@linuxprobe ~]# vim /etc/fstab # vdo00 UUID=926f56ed-0a52-4647-9004-8edb67edcc7e /media/vdo/vdo00 xfs defaults,_netdev 0 0
- create a brand new VDO volume
Symbolic link(soft link) and Hard link
-
Symbolic link
In computing, a symbolic link (also symlink or soft link) is a term for any file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution.
If the actual data is deleted, then the link file loses its effect too
image.png -
Hard link
In computing, a hard link is a directory entry that associates a name with a file on a file system. All directory-based file systems must have at least one hard link giving the original name for each file. The term “hard link” is usually only used in file systems that allow more than one hard link for the same file.
In other words, thehard link
is just like apointer
in which it points to the original data block, there can be multiple such pointer, i.e. multiple hard links to the same data block
image.pngNotice the
difference
between theoriginal file
and thedata block
the hard link points to, if the data block was pointed by multiple hard link, i.e. multiple pointers, and one of the hard links was deleted, the data block would be still there, even the so calledoriginal file
is deleted, it actually the hard link is deleted
Different partition hard link is not allowedparameters outcome -s symbolic link -f force create link file for file or directory -i query for replacement -v vebose mode, i.e. show the creation process Practise
[root@linuxprobe linkfile]# ln -s target.txt target [root@linuxprobe linkfile]# ln target.txt targethard [root@linuxprobe linkfile]# ll total 8 lrwxrwxrwx. 1 root root 10 Jan 26 08:42 target -> target.txt -rw-r--r--. 2 root root 12 Jan 26 08:41 targethard -rw-r--r--. 2 root root 12 Jan 26 08:41 target.txt
The second column indicates how many links is linking to the file, the hard link is 2 in the above case since we have just created a hard link to the original file, so therefore, even you deleted the original file, the data still can be accessed since the hard link still there, unless the number of links turns to
ZERO