Linux 中/data 資料分區磁碟空間不足,如何掛載磁碟。

來源:互聯網
上載者:User

首先,咱們需要類比一下環境,  使用VMware為我添加一塊300G(實際200M~~手動滑稽 -_-)的硬碟裝置。

按照步驟一步一步添加就好。添加完成後需要重啟你的虛擬機器,方能生效。

OK,那麼咱們的環境就有了。我已經為咱們的“伺服器”安裝了個300G(200M)的硬碟了,現在咱們把它掛載到 /data 下。

第一步,為新磁碟建立分區。

[root@~]# ll /dev/sdb*    #檢查第二塊硬碟,及分區brw-rw---- 1 root disk 8, 16 Aug 15 14:35 /dev/sdb#這裡顯示,你有第二塊磁碟,但是沒有分區啊,兄弟~~

  為磁碟建立分區,可以用兩個命令,fdisk  and  parted 。這裡咱們先講 fdisk 。parted等下再說

fdisk 命令,-c 選項:關閉dos相容模式,-u 以扇區為單位為磁碟分割。

當需要為你的磁碟分的細緻一些的時候可以使用,咱們現在要把300G都掛載到 /data 就不使用命令選項了。

下面是等下需要用到的 fdisk  內部指令含義:

m  顯示協助。       n   建立分區。      p  顯示磁碟分割資訊。     d   刪除分區。      w   儲存並退出。     q   退出不儲存。

[root@~]# fdisk /dev/sdb      #fdisk 命令後面直接加 磁碟檔案就好WARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').#這裡的警告資訊就是,建議你關閉dos相容模式,且啟用-u選項,簡單說就是讓你使用 -cu 選項。不過這個警告並不需要太在意,它只會在磁碟未分區時顯示,且不會對咱們下面的操作有任何影響。Command (m for help): p   #先看一下磁碟分割情況Disk /dev/sdb: 213 MB, 213909504 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x1bf8bec7   Device Boot      Start         End      Blocks   Id  System#嗯,空白的    就是沒有進行過磁碟分割。Command (m for help): n      #建立磁碟分割Command action   e   extended   p   primary partition (1-4)   #這裡是系統提示,是按 e 建立擴充分區,還是按 p 建立主要磁碟分割了?p                #咱們就準備整一個分區,自然選擇 p  主要磁碟分割啦~~Partition number (1-4): 1        #鍵入1 , 就是1號主要磁碟分割的意思。First cylinder (1-204, default 1):“斷行符號鍵” (按下Enter)    #這裡是讓你選擇分區開始的柱面,斷行符號就是預設,最初的意思            Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-204, default 204):“斷行符號鍵” (按下Enter)   #這裡是讓你選擇分區結束的柱面,斷行符號就是預設,最後的意思    Using default value 204    (建立好了)Command (m for help): p        #咱們再看一下Disk /dev/sdb: 213 MB, 213909504 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x1bf8bec7   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         204      208880   83  Linux#嗯嗯,分區名稱/dev/sdb1,大小差不多“300G”Command (m for help): w     # 鍵入 w ,一定要儲存後退出。不然所有的設定都不會生效。The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

  fdisk -l 查看一下磁碟的資訊。

[root@~]# fdisk -l| grep '/dev/sdb'Disk /dev/sdb: 213 MB, 213909504 bytes/dev/sdb1               1         204      208880   83  Linux#這就說明咱們的磁碟分割已經建立OK。

 第二步,為你的分區建立檔案系統(格式化)

首先要手動更新一下,讓系統知道 sdb 磁碟分割表有變化了~~

[root@~]# partprobe /dev/sdb[root@~]# # 傲嬌的Linux 並不會給你任何提示。但是這個步驟必不可少

 然後直接給分區裝個 ext4檔案系統就好了

[root@~]# mkfs.ext4 /dev/sdb1    #mkfs 命令接 .ext4 中間不需要使用空格。後面要跟分區的檔案名稱,並不是磁碟檔案名稱,這個要注意。mke2fs 1.41.12 (17-May-2010)··························此處省略數行Writing superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 21 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.#最後這兩個提示資訊是最重要的,它的意思是說:這個檔案系統將在21次掛載或是180天以後自動檢查,使用 tune2fs -c 或-i 可以覆蓋掉預設自動檢查。

 反正我是不需要系統預設檢查什麼的,那我就直接關掉好了,就使用它建議的 tune2fs 命令就好了。

[root@~]# tune2fs -c 0 -i 0 /dev/sdb1    # -c 和 -i 後面都是零(不檢查的意思),還是磁碟分割檔案~~tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1Setting interval between checks to 0 seconds#提示資訊我就不逐條翻譯了,大概意思就是系統不會自動檢查了。

 第三步,將 /dev/sdb1 掛載~~到 /data ,並實現開機自動掛載。

mount 掛載,這個簡單,我就不講了。

[root@~]# mount /dev/sdb1 /data[root@~]# df -h            #最好 df -h 查看一下Filesystem      Size  Used Avail Use% Mounted on/dev/sda3        19G  2.3G   16G  13% /tmpfs           490M     0  490M   0% /dev/shm/dev/sda1       190M   66M  115M  37% /boot/dev/sdb1       194M  1.8M  182M   1% /data               #這裡不應該是300G嗎,難道是我掛錯了?- _ -?

 開機自動實現掛載的方法有很多,咱們就簡單的講三種好了。

方法一:通過 /etc/rc.local   實現開機運行 mount /dev/sdb1 /data 。來實現開機自動掛載

[root@~]# ll /etc/rc.local lrwxrwxrwx 1 root root 13 Aug  6 17:57 /etc/rc.local -> rc.d/rc.local# /etc/rc.local  是 /etc/rc.d/rc.local 的符號連結。在root許可權下直接修改符號連結的檔案就可以了。[root@~]# vim /etc/rc.d/rc.local      #但是我有強迫症,我就要修改源檔案。哼哼~~#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff.touch /var/lock/subsys/localmount /dev/sdb1 /data            #編寫這麼一句就好了,但是我不建議這麼做。可能是因為比較Low吧

方法二:通過 /etc/fstab 實現開機自動掛載

[root@~]# vim /etc/fstab## /etc/fstab# Created by anaconda on Sat Jul 28 14:15:11 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=4b7f430b-398b-4ca4-a6f4-75e11c8498f0 /                       ext4    defaults        1 1UUID=b001470a-e506-4b50-a705-7b4343ac6a7c /boot                   ext4    defaults        1 2UUID=ec344814-973b-45d3-95f0-7ce6265b3247 swap                    swap    defaults        0 0tmpfs                   /dev/shm                tmpfs   defaults        0 0devpts                  /dev/pts                devpts  gid=5,mode=620  0 0sysfs                   /sys                    sysfs   defaults        0 0proc                    /proc                   proc    defaults        0 0/dev/sdb1               /data/                  ext4    defaults        0 0
#第一列裝置的名稱 #第二列 掛載點(目錄) #3,檔案系統類型 #4,defaults 是預設掛載參數
#第一個 0 是指是否進行備份 0(不進行) 第二個 0 是指是否開機磁碟檢查 0 (不檢查)

方法三:通過chkconfig 實現開機自動啟動。

這個方法我也不太建議,畢竟chkconfig還是用來啟用系統服務比較好,掛載的事情還是交給 fstab 的好。

下面的連結就是我寫的如何?chkconfig的開機自啟動~~連結,有興趣的可以看下。

www.cnblogs.com/xuenil/p/9470812.html

至於fdisk  與  parted 的區別,咱們明天再講~~~~~。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.