ubuntu磁碟掛載

宋文舉發表於2018-08-14

前言:如果你係統有一個磁碟(比如在左側選單欄有以下圖示)單獨用來放程式碼,在home目錄下如果想要像操作一個磁碟那樣簡單,可以使用以下的方法

ubuntu磁碟掛載

1.參看磁碟的資訊:df -h

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G  4.0K  7.8G   1% /dev
tmpfs           1.6G  1.5M  1.6G   1% /run
/dev/sda7        46G   27G   18G  61% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            7.9G  224M  7.6G   3% /run/shm
none            100M   84K  100M   1% /run/user
/dev/sda6       830G  293G  496G  38% /media/zjh/c4b953ff-d44d-454f-b409-26b0d5610e06
複製程式碼

可以看到最後一個盤是另外分出來的盤

2.使用dlkid命令來檢視UUID資訊

$ sudo dlkid

/dev/sda5: UUID="35446084-cb8b-427c-b7a9-be3998e61e18" TYPE="swap"
/dev/sda6: UUID="c4b953ff-d44d-454f-b409-26b0d5610e06" TYPE="ext4"
/dev/sda7: UUID="cf35bde6-43f2-4a80-80b9-24497bc1982b" TYPE="ext4" 
複製程式碼

這裡能得到/dev/sda6的UUID

3.建立一空目錄

$mkdir code

4.編輯/etc/fstab檔案

# vim /etc/fstab
複製程式碼
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda7 during installation
UUID=cf35bde6-43f2-4a80-80b9-24497bc1982b /               ext4    errors=remount-ro 0       1
UUID=c4b953ff-d44d-454f-b409-26b0d5610e06 /home/xxx/code               ext4    errors=remount-ro 0       1       
# swap was on /dev/sda5 during installation
UUID=35446084-cb8b-427c-b7a9-be3998e61e18 none            swap    sw              0       0
複製程式碼

新增上面加黑的一行,把/etc/sda6掛載到/home/xxx/code目錄下,這裡的xxx是你自己的目錄,掛載目錄必須是空目錄

5.#mount -a

這樣的話就把那個磁碟掛載過來了。 關注微信公眾號,定期為你推薦移動開發相關文章。

songwenju

相關文章