LPI Linux 認證/控制檔案系統掛載和解除安裝
外觀
(LPIC-1 版本 5.0)
權重:3
描述
考生應能夠配置檔案系統的掛載。
關鍵知識領域
- 手動掛載和解除安裝檔案系統。
- 配置啟動時檔案系統的掛載。
- 配置使用者可掛載的可移動檔案系統。
- 使用標籤和 UUID 來識別和掛載檔案系統。
- 瞭解 systemd 掛載單元。
以下是使用檔案、術語和實用程式的部分列表
/etc/fstab/media/mountumountblkidlsblk
mount 命令用於將某些裝置上的檔案系統附加到大的檔案樹。
mount [options] mount [options] [-t vfstype] [-o options] device dir
如果裝置或目錄在 /etc/fstab 中列出,可以使用以下命令
mount [options] [-o options [,...]] device | dir
通常只有 root 才有掛載裝置的許可權,除非在 /etc/fstab 檔案中指定。示例
# Print all the mounted filesystems (/etc/mtab). mount
# Mount devices or dirs listed in /etc/fstab. mount -a
# Mount /dev/hdc partition in read only mode without updating /etc/mtab. mount -n -o ro /dev/hdc /mnt
# Allow a user to mount the CDROM if the following line is in /etc/fstab: # /dev/cdrom /media/cdrom iso9660 ro,user,noauto,unhide mount /media/cdrom mount /dev/cdrom
# Sync in realtime mount -o sync /dev/sdb1 /mnt/usb
要將檔案系統從檔案樹中分離,請使用 umount。
umount [options] umount [options] [-o options [,...]] device | dir
繁忙的檔案系統無法解除安裝。
- 開啟的檔案
- 程序的工作目錄。
示例
umount -a # Unmount devices or dirs listed in /etc/fstab. umount /mnt # Unmount the filesystem attached to /mnt. umount /media/cdrom # Allow a user to unmount the CDROM if the following line is in /etc/fstab: /dev/cdrom /media/cdrom iso9660 ro,user,noauto,unhide
/etc/fstab 檔案包含在執行 mount -a 時將使用所有檔案系統和相關資訊。(啟動時)
/etc/mtab 檔案由核心維護,並跟蹤已掛載或未掛載的內容。/etc/fstab 的格式為
#Device Mount point Fs type Options 1 2 /dev/hda3 / reiserfs defaults 1 2 /dev/hda1 /boot ext2 defaults 1 2 /dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0 usbdevfs /proc/bus/usb usbdevfs noauto 0 0 /dev/hda2 swap swap pri=42 0 0
常用選項
- ro: 只讀
- noauto: 不要自動掛載
- exec: 可以在檔案系統上執行二進位制檔案
- suid: 允許設定使用者位
- user: 允許使用者掛載/解除安裝它
- unhide: 隱藏檔案可見
- async: 所有操作將非同步執行
- default: rw, suid, dev, exec, auto, nouser 和 async
- 在 /etc/fstab 中建立一行,允許任何使用者訪問軟盤。檢查您是否可以掛載軟盤並使用 touch 建立檔案。
- 執行以下操作
- 在軟盤上建立 ext2 檔案系統。
- 掛載軟盤。
- 將所有檔案 /etc/*.conf 複製到軟盤。
- 解除安裝它。發生了什麼事?
- 重新掛載並檢查所有檔案是否都在那裡。
- 發出以下命令
- Tar cvf /dev/fd0 /etc/*.conf
- 嘗試重新掛載。發生了什麼事?
- 使用 tar 檢視軟盤的內容。