Ubuntu掛載新硬盤


1、加掛硬盤

Shell代碼 復制代碼
  1. sudo hdparm -I /dev/sdb       硬盤硬件安裝后,此命令測試linux系統是否能找到掛載的未分區硬盤  
sudo hdparm -I /dev/sdb       硬盤硬件安裝后,此命令測試linux系統是否能找到掛載的未分區硬盤

 

2、創建分區

Shell代碼 復制代碼
  1. sudo fdisk /dev/sdb  
sudo fdisk /dev/sdb

       sda是第一塊SCSI硬盤,sdb第二塊,以此類推...物理分區使用a、b編號,每個物理硬盤最多有四個主邏輯分區(或擴展分區),所以自動分區中,擴展分區sda2下第一個邏輯分區編號從5開始

第一次執行sudo fdisk /dev/sdb,出現了Error: Unable to open /dev/sdb - unrecognised disk label.  提示找不到磁盤標簽,可以使用 parted 進行分區(sudo parted  /dev/sdb )。

Shell代碼 復制代碼
  1. Command (m for help):   
  2. 這里按m獲得幫助   
  3. a   toggle a bootable flag   將分區設置為啟動區   
  4. b   edit bsd disklabel    編輯bsd的disklabel   
  5. c   toggle the dos compatibility flag  設置該分區為dos分區   
  6. d   delete a partition 刪除分區   
  7. l   list known partition types  列出已知的分區類型   
  8. m   print this menu  打印幫助列表   
  9. n   add a new partition 創建新分區   
  10. o   create a new empty DOS partition table   
  11. p   print the partition table查看分區信息   
  12. q   quit without saving changes 退出不保存   
  13. s   create a new empty Sun disklabel   
  14. t   change a partition's system id改變分區類型   
  15. u   change display/entry units   
  16. v   verify the partition table   
  17. w   write table to disk and exit 保存退出   
  18. x   extra functionality (experts only)   
  19.   
  20. Command (m for help):p  //查看新硬盤的分區   
  21. ********************************************************************   
  22. Disk /dev/sdb: 1000204 MB, 1000202273280 bytes   
  23. 255 heads, 63 sectors/track, 121601 cylinders   
  24. Units = cylinders of 16065 * 512 = 8225280 bytes   
  25. Device Boot Start End Blocks Id System   
  26. ********************************************************************   
  27. Command (m for help):n  //創建新分區   
  28. File system type  (default ext2): ext3    //輸入想使用的分區格式   
  29. Partition name:  backup                      //輸入分區的名字   
  30. First cylinder  (default 0cyl):                //第幾個柱面,我們按照默認   
  31. Last cylinder or +size or +sizeMB or +sizeKB  (default 0cyl):+1000000M    //這里我們按大小輸入 即+1000000M (注意這個M為大寫)   
  32. Warning: You requested a partition from 0cyl to 121576cyl.                   
  33. The closest location we can manage is 1cyl to 121575cyl.  Is this still   
  34. acceptable to you?   
  35.    y   Yes                                                                   
  36.    n   No   
  37. 當然是y   
  38. Command (m for help): p            //查看新硬盤分區后的情況   
  39. ********************************************************************   
  40. Disk /dev/sdb: 1000 GB, 1000202273280 bytes   
  41. 255 heads, 63 sectors/track, 121601 cylinders   
  42. Units = cylinders of 16065 * 512 = 8225280 bytes   
  43.   
  44.    Device Boot      Start         End      Blocks   Id  System    
  45. /dev/sdb1               2      121576   976559157   83  Linux    
  46. ******************************************************************   
  47. Command (m for help): w   
  48. Information: Don't forget to update /etc/fstab, if necessary.            //寫入硬盤分區屬性並結束  
Command (m for help):
這里按m獲得幫助
a   toggle a bootable flag   將分區設置為啟動區
b   edit bsd disklabel    編輯bsd的disklabel
c   toggle the dos compatibility flag  設置該分區為dos分區
d   delete a partition 刪除分區
l   list known partition types  列出已知的分區類型
m   print this menu  打印幫助列表
n   add a new partition 創建新分區
o   create a new empty DOS partition table
p   print the partition table查看分區信息
q   quit without saving changes 退出不保存
s   create a new empty Sun disklabel
t   change a partition's system id改變分區類型
u   change display/entry units
v   verify the partition table
w   write table to disk and exit 保存退出
x   extra functionality (experts only)

Command (m for help):p  //查看新硬盤的分區
********************************************************************
Disk /dev/sdb: 1000204 MB, 1000202273280 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
********************************************************************
Command (m for help):n  //創建新分區
File system type  (default ext2): ext3    //輸入想使用的分區格式
Partition name:  backup                      //輸入分區的名字
First cylinder  (default 0cyl):                //第幾個柱面,我們按照默認
Last cylinder or +size or +sizeMB or +sizeKB  (default 0cyl):+1000000M    //這里我們按大小輸入 即+1000000M (注意這個M為大寫)
Warning: You requested a partition from 0cyl to 121576cyl.                
The closest location we can manage is 1cyl to 121575cyl.  Is this still
acceptable to you?
   y   Yes                                                                
   n   No
當然是y
Command (m for help): p            //查看新硬盤分區后的情況
********************************************************************
Disk /dev/sdb: 1000 GB, 1000202273280 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               2      121576   976559157   83  Linux 
******************************************************************
Command (m for help): w
Information: Don't forget to update /etc/fstab, if necessary.            //寫入硬盤分區屬性並結束

 

3、格式化硬盤

Shell代碼 復制代碼
  1. sudo mkfs -t ext3 /dev/sdb1               //把上面創建的新硬盤分區格式化為ext3格式,這個要等一會才能自動結束   
  2. ********************************************************************************   
  3. mke2fs 1.40.8 (13-Mar-2008)   
  4. Filesystem label=   
  5. OS type: Linux   
  6. Block size=4096 (log=2)   
  7. Fragment size=4096 (log=2)   
  8. 61038592 inodes, 244137796 blocks   
  9. 12206889 blocks (5.00%) reserved for the super user   
  10. First data block=0  
  11. Maximum filesystem blocks=0  
  12. 7451 block groups   
  13. 32768 blocks per group, 32768 fragments per group   
  14. 8192 inodes per group   
  15. Superblock backups stored on blocks:   
  16.     327689830416384022937629491281920088473616056322654208,   
  17.     409600079626241123942420480000238878727166361678675968,   
  18.     102400000214990848  
  19.   
  20. Writing inode tables: done                              
  21. Creating journal (32768 blocks): done   
  22. Writing superblocks and filesystem accounting information: done   
  23.   
  24. This filesystem will be automatically checked every 37 mounts or   
  25. 180 days, whichever comes first.  Use tune2fs -c or -i to override.   
  26. ********************************************************************************  
sudo mkfs -t ext3 /dev/sdb1               //把上面創建的新硬盤分區格式化為ext3格式,這個要等一會才能自動結束
********************************************************************************
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
61038592 inodes, 244137796 blocks
12206889 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
7451 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
    102400000, 214990848

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
********************************************************************************

 

4、設置sdb1的卷標

Shell代碼 復制代碼
  1. sudo e2label /dev/sdb1 /backup                  //這里/backup 就是在/dev/sdb1根下起了個名字  
sudo e2label /dev/sdb1 /backup                  //這里/backup 就是在/dev/sdb1根下起了個名字

 

5、設置掛載點

Shell代碼 復制代碼
  1. sudo mkdir /backup                   //在根路徑下創建掛載點  
sudo mkdir /backup                   //在根路徑下創建掛載點

 

6、設置開機自動掛載

Shell代碼 復制代碼
  1. sudo vim /etc/fstab  
sudo vim /etc/fstab

 <file system> <mount point>   <type>  <options>       <dump>      <pass>

    1                         2                      3              4                   5                6 1 指代文件系統的設備名。最初,該字段只包含待掛載分區的設備名(如/dev/sda1)。現在,除設備名外,還可以包含LABEL或UUID 2 文件系統掛載點。文件系統包含掛載點下整個目錄樹結構里的所有數據,除非其中某個目錄又掛載了另一個文件系統 3 文件系統類型。下面是多數常見文件系統類型(ext3,tmpfs,devpts,sysfs,proc,swap,vfat) 4 mount命令選項。mount選項包括noauto(啟動時不掛載該文件系統)和ro(只讀方式掛載文件系統)等。在該字段里添加用戶或屬主選項,即可允許該用戶掛載文件系統。多個選項之間必須用逗號隔開。其他選項的相關信息可參看mount命令手冊頁(-o選項處) 5轉儲文件系統?該字段只在用dump備份時才有意義。數字1表示該文件系統需要轉儲,0表示不需要轉儲 6文件系統檢查?該字段里的數字表示文件系統是否需要用fsck檢查。0表示不必檢查該文件系統,數字1示意該文件系統需要先行檢查(用於根文件系統)。數字2則表示完成根文件系統檢查后,再檢查該文件系統
文件中增加如下配置信息

Shell代碼 復制代碼
  1. LABEL=/backup   /backup      ext3        defaults        1       2  
LABEL=/backup   /backup      ext3        defaults        1       2

 掛載分區的卷標名稱    掛載點  掛載分區文件類型  掛載方式         略         略

或者

Shell代碼 復制代碼
  1. /dev/sdb1     /backup      ext3      defaults      1      2  
/dev/sdb1     /backup      ext3      defaults      1      2

或者在命令行手動掛載(每次重啟機器后都需要執行一次)

Shell代碼 復制代碼
  1. mount -vl -t ext3 /dev/sdb1 /backup  掛載文件系統/顯示標簽   
mount -vl -t ext3 /dev/sdb1 /backup  掛載文件系統/顯示標簽 

 

7、重啟機器查看結果

Shell代碼 復制代碼
  1. df -h //查看分區空間使用情況,就可以看到/backup已經自動掛載   
  2. Filesystem            Size  Used Avail Use% Mounted on   
  3. /dev/sda1             139G  121G   12G  92% /   
  4. varrun                1.3G   68K  1.3G   1% /var/run   
  5. varlock               1.3G     0  1.3G   0% /var/lock   
  6. udev                  1.3G   32K  1.3G   1% /dev   
  7. devshm                1.3G     0  1.3G   0% /dev/shm   
  8. /dev/sdb1             924G   11G  867G   2% /backup  
df -h //查看分區空間使用情況,就可以看到/backup已經自動掛載
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             139G  121G   12G  92% /
varrun                1.3G   68K  1.3G   1% /var/run
varlock               1.3G     0  1.3G   0% /var/lock
udev                  1.3G   32K  1.3G   1% /dev
devshm                1.3G     0  1.3G   0% /dev/shm
/dev/sdb1             924G   11G  867G   2% /backup

 成功了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM