如何給linux添加新硬碟

來源:互聯網
上載者:User

fdisk -l ## 這裡是查看目前系統上有幾塊硬碟

Disk /dev/sda: 36.4 GB, 36401479680 bytes

255 heads, 63 sectors/track, 4425 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sda1 * 1 255 2048256 83 Linux

/dev/sda2 256 1530 10241437+ 83 Linux

/dev/sda3 4296 4425 1044225 82 Linux swap

/dev/sda4 1531 4295 22209862+ f Win95 Ext'd (LBA)

/dev/sda5 1531 2805 10241406 83 Linux

/dev/sda6 2806 4295 11968393+ 83 Linux

Partition table entries are not in disk order

Disk /dev/sdb: 36.7 GB, 36703918080 bytes ## 這裡發現/dev/sdb,容量36.7G,且未被分區

255 heads, 63 sectors/track, 4462 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


Disk /dev/sdc doesn't contain a valid partition table

在伺服器上把硬碟接好,啟動linux,以root登陸。

比如我新加一塊SCSI硬碟,需要將其分成三個區:


#fdisk /dev/sdb
進入fdisk模式:
Command (m for help):p  //查看新硬碟的分區
Command (m for help):n  //建立新分區

可以用m命令來看fdisk命令的內部命令;n命令建立一個新分區;d命令刪除一個存在的分區;p命令顯示分區列表;t命令修改分區的類型ID號;l命令顯示分區ID號的列表;a命令指定開機磁碟分割;w命令是將對分區表的修改存檔讓它發生作用。 

Command action
   e   extended   //輸入e為建立擴充分區
   p   primary partition (1-4)   //輸入p為建立主要磁碟分割,這裡我們選擇p

Partion number(1-4):1  //第一個擴充分區,按你需求可以最多分4個主要磁碟分割
First Cylinder(1-1014,default 1):  1  //第一個主要磁碟分割起始的磁碟塊數
Last cylindet or +siza or +sizeM or +sizeK: +1024MB  //可以是以MB為單位的數字或者以

磁碟塊數,這裡我們輸入+1024MB表示分區大小為1G。

這樣我們就建立完一個分區,如果要建立更多分區可以照上面的步驟繼續建立。

建立完後用w儲存分區。


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.



這樣就分區完,我們還要進行格式化


#mkfs -t ext3 -c /dev/sdb1  //如果有多個分區,則分區修改為sdb2這樣



格式化完後我們需要進行掛載分區,


#mkdir www //建立/www目錄,我們將把新的分區掛到www下
#mount /dev/sdb1 /www  //將/dev/sdb1掛載到/www
# df  //用df命令進行查看
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              3771316   1388956   2190788  39% /
/dev/sda1               101089      9463     86407  10% /boot
none                     62988         0     62988   0% /dev/shm
/dev/sdb1               485906      8239    452580   2% /www  //看到了,這就是我們剛

才新掛載的分區

到這裡我們工作已接近尾聲了,不過我們如果這樣就結束的話,我們每次重新啟動伺服器後都要

進行手工掛載,這樣很麻煩,我們需要修改/etc/fstab檔案來進行自動掛載。


#vi /etc/fstab



在檔案的末尾填加如下內容:


/dev/sdb1               /www                    ext3    defaults        1 2



如有多個分區可修改sdb1和/www,修改完後儲存,重起伺服器。

到此我們添加新硬碟的工作結束了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.