1. 程式人生 > >ubuntu掛載硬碟

ubuntu掛載硬碟

在linux下載入一塊硬碟從總體上分為以下幾個步驟:  1、用fdisk對硬碟進行分割槽  2、用mkfs.ext4對硬碟進行格式化  3、建立一個掛接目錄(如果需要掛接到已存在的目錄,此步驟可以省略)  4、用mount將該分割槽掛接到指定的目錄  5、如果想實現啟動時自動掛接,那麼還需要修改fstab檔案   

具體操作如下: 

  1. [[email protected] ~]# fdisk -l --檢視硬碟分割槽資訊

  2. Disk /dev/sda: 32.2 GB, 32212254720 bytes

  3. 255 heads, 63 sectors/track, 3916 cylinders

  4. Units = cylinders of 16065 * 512 = 8225280 bytes

  5. Device Boot Start End Blocks Id System

  6. /dev/sda1 * 1 3661 29406951 83 Linux

  7. /dev/sda2 3662 3915 2040255 82 Linux swap

  8. Disk /dev/sdb: 1073 MB, 1073741824 bytes --可以看到有一塊空閒的硬碟還未分割槽

  9. 255 heads, 63 sectors/track, 130 cylinders

  10. Units = cylinders of 16065 * 512 = 8225280 bytes

  11. Disk /dev/sdb doesn't contain a valid partition table

  12. [[email protected] ~]# fdisk /dev/sdb --使用fdisk工具對sdb進行分割槽

  13. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

  14. Building a new DOS disklabel. Changes will remain in memory only,

  15. until you decide to write them. After that, of course, the previous

  16. content won't be recoverable.

  17. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

  18. Command (m for help): m --列出fdisk工具的引數

  19. Command action

  20. a toggle a bootable flag

  21. b edit bsd disklabel

  22. c toggle the dos compatibility flag

  23. d delete a partition

  24. l list known partition types

  25. m print this menu

  26. n add a new partition

  27. o create a new empty DOS partition table

  28. p print the partition table

  29. q quit without saving changes

  30. s create a new empty Sun disklabel

  31. t change a partition's system id

  32. u change display/entry units

  33. v verify the partition table

  34. w write table to disk and exit

  35. x extra functionality (experts only)

  36. Command (m for help): n --輸入“n”增加一個分割槽

  37. Command action --選擇是建立主分割槽還是擴充套件分割槽

  38. e extended

  39. p primary partition (1-4)

  40. p --輸入“p”建立主分割槽

  41. Partition number (1-4): 1 --輸入分割槽號

  42. First cylinder (1-130, default 1): 1

  43. Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): 130

  44. Command (m for help): w --寫入分割槽表並退出

  45. The partition table has been altered!

  46. Calling ioctl() to re-read partition table.

  47. Syncing disks.

  48. [[email protected] ~]# mkfs.ext4 /dev/sdb1 --將新建立的分割槽進行格式化

  49. mke2fs 1.35 (28-Feb-2004)

  50. Filesystem label=

  51. OS type: Linux

  52. Block size=4096 (log=2)

  53. Fragment size=4096 (log=2)

  54. 130560 inodes, 261048 blocks

  55. 13052 blocks (5.00%) reserved for the super user

  56. First data block=0

  57. Maximum filesystem blocks=268435456

  58. 8 block groups

  59. 32768 blocks per group, 32768 fragments per group

  60. 16320 inodes per group

  61. Superblock backups stored on blocks:

  62. 32768, 98304, 163840, 229376

  63. Writing inode tables: done

  64. Creating journal (4096 blocks): done

  65. Writing superblocks and filesystem accounting information: done

  66. This filesystem will be automatically checked every 26 mounts or

  67. 180 days, whichever comes first. Use tune2fs -c or -i to override.

  68. [[email protected] ~]# mkdir /newdisk --建立一個新的掛接目錄

  69. [[email protected] ~]# mount /dev/sdb1 /newdisk --將sdb1掛接到/newdisk下

  70. [[email protected] ~]# df -lh --檢視目前硬碟空閒,新建硬碟已經成功掛接

  71. Filesystem Size Used Avail Use% Mounted on

  72. /dev/sda1 28G 2.4G 24G 9% /

  73. none 506M 0 506M 0% /dev/shm

  74. /dev/sdb1 1004M 18M 936M 2% /newdisk

到此為止,我們的新硬碟已經載入成功了,但是這裡有一個問題,一旦我們重新啟動系統,還需要用mount命令重新掛接才能訪問新硬碟,如果我需要掛接的工作在系統啟動過程中完成,那麼我需要用vi配置/etc/fstab檔案,將/dev/sdb1  /newdisk   ext4  defaults    1 1 新增到/etc/fstab的最後,然後重新啟動系統即可。  第一列為裝置號或該裝置的卷標  第二列為掛載點  第三列為檔案系統  第四列為檔案系統引數  第五列為是否可以用demp命令備份。0:不備份,1:備份,2:備份,但比1重要性小。設定了該引數後,Linux中使用dump命令備份系統的時候就可以備份相應設定的掛載點了。  第六列為是否在系統啟動的時候,用fsck檢驗分割槽。因為有些掛載點是不需要檢驗的,比如:虛擬記憶體swap、/proc等。0:不檢驗,1:要檢驗,2要檢驗,但比1晚檢驗,一般根目錄設定為1,其他設定為2就可以了。 解除掛載 

umount /dev/sdb1 

檢視分割槽是ext3還是ext4系統 

df -hT