標籤:common dmi 備份 分區 intern 分享 win 技術 兩台電腦
79573271 (可行)
1. 背景
前博 介紹了如何配置Linux的Samba服務以便Windows系統能映射Linux的共用資料夾,因此我們提出疑問:Linux如何訪問其他系統的共用資料夾呢?答案也就是本文介紹的:掛載。
2. 原理
對於Linux系統,根檔案系統“/”之外的其他檔案要想能夠被訪問,都必須通過“關聯”至根檔案系統上的某個目錄來實現,此關聯操作即為“掛載”,此目錄即為“掛載點”,解除此關聯關係的過程稱之為“卸載”。
注意點:掛載點必須是一個目錄。
3. 操作
說明:筆者有兩台電腦,linux(192.168.1.6) ------ windows(192.168.1.7),此測試例就是Linux掛載Windows的共用目錄:e盤
不管是開機自動掛載還是手動掛載,我們都首先在/mnt目錄下建立一個檔案夾,也就是掛載點。
zglinux mnt # mkdir windows
zglinux mnt # ls
windows
1) 手動掛載
手動掛載就是採用Linux的mount命令,終端輸入如下命令:
mount.cifs //192.168.1.7/e /mnt/windows/ -o user=administrator,pass=******(windows的登入密碼)
說明:
1. 第一個欄位mount.cifs表示採用CIFS(Common Internet File System:通用網路檔案系統)掛載將要掛載的目錄,linux支援多種檔案系統,如ext4, xfs, btrfs,f2fs, vfat, ntfs,CIFS是其中一種,具體可以看man 8 mount手冊;
2. 第二個欄位表示將要掛載的檔案系統路徑或塊裝置;
3. 第三個欄位表示Linux的掛載點,也就是我們剛才建立的/mnt/windows目錄;
4. 最後一個欄位-o 以及後面的所有內容表示掛載選項,各個選項以“,”分隔。比如此掛載需要知道Windows的使用者名稱和密碼;
5. 操作可能需要root許可權,可以在命令前面加sudo;
2) 自動掛載
自動掛載即Linux開機啟動時自動掛載所需的分區,所有需要掛載的分區通過檔案/etc/fstab描述。因而,我們只需要修改此檔案即可完成自動掛載。通過cat /etc/fstab 和man fstab可以查看典型的掛載資訊條目:
LABEL=t-home2 /home ext4 defaults,auto_da_alloc 0 2
其中:
第一個欄位:This field describes the block special device or remote filesystemto be mounted. (描述將要掛載的特定塊裝置或遠程檔案系統);
第二個欄位:This field describes the mount point for the filesystem. (描述掛載點);
第三個欄位:This field describes the type of the filesystem. (描述掛載檔案系統);
第四個欄位:This field describes the mount options associated with thefilesystem.(描述檔案系統相關聯的掛載選項);
第五個欄位:This field is used by dump(8) to determine which filesystems need tobe dumped.(針對ext2/3/4檔案系統,是否要備份,防止因異常斷電導致的資料丟失。具體可以查看man 8 dump,如果沒有此命令,請先用apt-get install dump安裝。此欄位預設填0,不需要dump);
第六個欄位:This field is used by fsck(8) to determine the order in whichfilesystem checks are done at boot time.(意思是:指定系統啟動時通過fsck檢查檔案系統的順序,根檔案系統檢查順序為1,其他為2。預設為0表示不執行檢查,由於我們要掛載網路檔案,此處填0,不進行檢查);
有了上述分析,我們通過 vi 開啟/etc/fstab,在檔案末尾添加如下行即可實現Linux系統開機自動掛載
//192.168.1.7/e /mnt/windows/ cifs username=administrator,password=****(windows密碼) 0 0
4. 測試
編輯好/etc/fstab檔案後,我們重啟Linux系統,查看是否成功掛載。結果表明:掛載成功。以後就可以把Windows的共用目錄當作Linux的一個盤來訪問了。
5. 參考
http://blog.csdn.net/hello_word___/article/details/77300279
$man 8 mount
$man mount.cifs
Linux開機掛載windows共用資料夾