掛載/卸載磁盤

掛載/卸載磁盤
=====================

mount命令node

NAME
mount - mount a filesystem
(掛載一個文件系統)
umount命令
NAME
umount - unmount file systems
(卸載文件系統)

示例:
[root@aminglinux ~]# df -h |grep -v tmpfs
文件系統    容量 已用    可用  已用% 掛載點
/dev/sda3  17G 1.2G    15G    8%         /
/dev/sda1 197M 94M 104M  48%    /boot

[root@aminglinux /]# mkdir /newdir
[root@aminglinux /]# mount /dev/sdb1 /newdir             //掛載磁盤
[root@aminglinux /]# df -h |grep -v tmpfs
文件系統     容量 已用 可用 已用% 掛載點
/dev/sda3   17G 1.2G 15G   8%       /
/dev/sda1 197M 94M 104M 48%   /boot
/dev/sdb1 2.0G 33M 2.0G 2%     /newdir
[root@aminglinux /]# umount /newdir                    //卸載磁盤
linux




認識 /etc/fstab配置文件

[root@aminglinux /]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jun 5 21:48:45 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=20413d8e-ec21-4e62-b066-876e054fc051 / xfs defaults 0 0
UUID=cb88978f-84b3-4922-b7a4-61e0f874dead /boot xfs defaults 0 0
UUID=a5c8f981-229a-4c35-a8a8-e4d5bb2a64e6 swap swap defaults 0 0
UUID=8d6e18fc-dd7e-4451-b623-ba9a6cb5e2a1 /newdir xfs defaults 0 0
//也能夠寫成分區的LABEL,分區名(/dev/sdb2)

[root@aminglinux /]# df -h |grep -v tmpfs
文件系統 容量 已用 可用 已用% 掛載點
/dev/sda3 17G 1.2G 15G 8% /
/dev/sda1 197M 94M 104M 48% /boot
[root@aminglinux /]# mount -a                                                      //-a;會把/etc/fstab中出現的全部磁盤分區掛載上。
[root@aminglinux /]# df -h |grep -v tmpfs
文件系統 容量 已用 可用 已用% 掛載點
/dev/sda3 17G 1.2G 15G 8% /
/dev/sda1 197M 94M 104M 48% /boot
/dev/sdb2 2.0G 33M 2.0G 2% /newdir

[root@aminglinux /]# mkdir /newdir/dir1
[root@aminglinux /]# mount -o remount,ro /dev/sdb2 /newdir    //-o,用來指定掛載分區有哪些特性。例如:remount,從新掛載;ro,只讀
[root@aminglinux /]# mkdir /newdir/dir2
mkdir: 沒法建立目錄"/newdir/dir2": 只讀文件系統
[root@aminglinux /]# mount |grep sdb2
/dev/sdb2 on /newdir type xfs (ro,relatime,attr2,inode64,noquota)
[root@aminglinux /]# mount -o remount /newdir
[root@aminglinux /]# mkdir /newdir/dir2
[root@aminglinux /]# ls /newdir
dir1 dir2
[root@aminglinux newdir]# umount /newdir //當前目錄還在卸載分區上,分區不能卸載
umount: /newdir:目標忙。
(有些狀況下經過 lsof(8) 或 fuser(1) 能夠
找到有關使用該設備的進程的有用信息)
[root@aminglinux newdir]# umount -l /newdir //-l;能夠實現上述狀況的分區卸載
[root@aminglinux newdir]# df -h |grep -v tmpfs
文件系統 容量 已用 可用 已用% 掛載點
/dev/sda3 17G 1.2G 15G 8% /
/dev/sda1 197M 94M 104M 48% /boot

blkid命令
NAME
blkid - locate/print block device attributes
(定位/打印塊設備屬性)

[root@aminglinux /]# blkid
/dev/sda1: UUID="cb88978f-84b3-4922-b7a4-61e0f874dead" TYPE="xfs"
/dev/sda2: UUID="a5c8f981-229a-4c35-a8a8-e4d5bb2a64e6" TYPE="swap"
/dev/sda3: UUID="20413d8e-ec21-4e62-b066-876e054fc051" TYPE="xfs"
/dev/sdb1: LABEL="TEST" UUID="002a5f1c-f3e0-41f3-a3b0-92c745e90935" TYPE="xfs"
/dev/sdb2: LABEL="APP" UUID="8d6e18fc-dd7e-4451-b623-ba9a6cb5e2a1" TYPE="xfs"
/dev/sdb5: UUID="000dfe90-868a-4072-8d3e-f8bb6a73d929" TYPE="ext4"
/dev/sdb6: LABEL="BACKUP" UUID="e977ccc9-d400-4e94-bc97-bda3b60272d7" TYPE="ext4"
/dev/sr0: UUID="2016-12-05-13-55-45-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"

創建一個swap文件增長虛擬內存
增長虛擬磁盤的基本思路:創建swapfile→格式化爲swap格式→啓用該虛擬磁盤

示例:
[root@aminglinux newdir]# dd if=/dev/zero of=/tmp/newdisk    bs=1M             count=200
                                                   if 指定源   of指定目標文件    bs定義塊大小 count定義塊的數量
記錄了200+0 的讀入
記錄了200+0 的寫出
209715200字節(210 MB)已複製,2.94556 秒,71.2 MB/秒

[root@aminglinux newdir]# mkswap -f /tmp/newdisk //格式化爲swap格式
正在設置交換空間版本 1,大小 = 204796 KiB
無標籤,UUID=9c143581-77ed-4f5b-8873-8dec93558cf2

[root@aminglinux newdir]# free -m
total used free shared buff/cache available
Mem: 1984 123 1510 8 351 1683
Swap: 3813 0 3813
[root@aminglinux newdir]# swapon /tmp/newdisk              //啓用虛擬磁盤
swapon: /tmp/newdisk:不安全的權限 0644,建議使用 0600。
[root@aminglinux newdir]# free -m
total used free shared buff/cache available
Mem: 1984 123 1509 8 351 1683
Swap: 4013 0 4013
[root@aminglinux newdir]# chmod 0600 /tmp/newdisk

[root@aminglinux newdir]# swapoff /tmp/newdisk             //停用虛擬磁盤         安全

相關文章
相關標籤/搜索