ubuntu掛載硬碟
在linux下載入一塊硬碟從總體上分為以下幾個步驟: 1、用fdisk對硬碟進行分割槽 2、用mkfs.ext4對硬碟進行格式化 3、建立一個掛接目錄(如果需要掛接到已存在的目錄,此步驟可以省略) 4、用mount將該分割槽掛接到指定的目錄 5、如果想實現啟動時自動掛接,那麼還需要修改fstab檔案
具體操作如下:
-
[[email protected] ~]# fdisk -l --檢視硬碟分割槽資訊
-
Disk /dev/sda: 32.2 GB, 32212254720 bytes
-
255 heads, 63 sectors/track, 3916 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
Device Boot Start End Blocks Id System
-
/dev/sda1 * 1 3661 29406951 83 Linux
-
/dev/sda2 3662 3915 2040255 82 Linux swap
-
Disk /dev/sdb: 1073 MB, 1073741824 bytes --可以看到有一塊空閒的硬碟還未分割槽
-
255 heads, 63 sectors/track, 130 cylinders
-
Units = cylinders of 16065 * 512 = 8225280 bytes
-
Disk /dev/sdb doesn't contain a valid partition table
-
[[email protected] ~]# fdisk /dev/sdb --使用fdisk工具對sdb進行分割槽
-
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
-
Building a new DOS disklabel. Changes will remain in memory only,
-
until you decide to write them. After that, of course, the previous
-
content won't be recoverable.
-
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
-
Command (m for help): m --列出fdisk工具的引數
-
Command action
-
a toggle a bootable flag
-
b edit bsd disklabel
-
c toggle the dos compatibility flag
-
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): n --輸入“n”增加一個分割槽
-
Command action --選擇是建立主分割槽還是擴充套件分割槽
-
e extended
-
p primary partition (1-4)
-
p --輸入“p”建立主分割槽
-
Partition number (1-4): 1 --輸入分割槽號
-
First cylinder (1-130, default 1): 1
-
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): 130
-
Command (m for help): w --寫入分割槽表並退出
-
The partition table has been altered!
-
Calling ioctl() to re-read partition table.
-
Syncing disks.
-
[[email protected] ~]# mkfs.ext4 /dev/sdb1 --將新建立的分割槽進行格式化
-
mke2fs 1.35 (28-Feb-2004)
-
Filesystem label=
-
OS type: Linux
-
Block size=4096 (log=2)
-
Fragment size=4096 (log=2)
-
130560 inodes, 261048 blocks
-
13052 blocks (5.00%) reserved for the super user
-
First data block=0
-
Maximum filesystem blocks=268435456
-
8 block groups
-
32768 blocks per group, 32768 fragments per group
-
16320 inodes per group
-
Superblock backups stored on blocks:
-
32768, 98304, 163840, 229376
-
Writing inode tables: done
-
Creating journal (4096 blocks): done
-
Writing superblocks and filesystem accounting information: done
-
This filesystem will be automatically checked every 26 mounts or
-
180 days, whichever comes first. Use tune2fs -c or -i to override.
-
[[email protected] ~]# mkdir /newdisk --建立一個新的掛接目錄
-
[[email protected] ~]# mount /dev/sdb1 /newdisk --將sdb1掛接到/newdisk下
-
[[email protected] ~]# df -lh --檢視目前硬碟空閒,新建硬碟已經成功掛接
-
Filesystem Size Used Avail Use% Mounted on
-
/dev/sda1 28G 2.4G 24G 9% /
-
none 506M 0 506M 0% /dev/shm
-
/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