添加一塊新磁盤

tag:由于業(yè)務(wù)需求的增長(zhǎng),磁盤空間日漸捉襟見肘,現(xiàn)新增一塊硬盤到linux服務(wù)器,一起來看看怎么操作吧:

1.先看看已有的磁盤及掛載點(diǎn)

[root@GHCLC6X-6786 ~]# df
文件系統(tǒng)             1K-塊      已用      可用 已用% 掛載點(diǎn)
/dev/sda3             13932624   2534836  10690052  20% /
tmpfs                  2996552         0   2996552   0% /dev/shm
/dev/sda1               516040     43608    446220   9% /boot

2.列出所有的硬盤

[root@GHCLC6X-6786 ~]# fdisk -l | grep -P "Disk /dev/[a-z]{0,3}:"
Disk /dev/sda: 16.1 GB, 16106127360 bytes
Disk /dev/sdb: 102.0 GB, 102005473280 bytes

根據(jù)之前的對(duì)比 可以看到一塊102GB的新硬盤 位于/dev/sdb

3.下面就來分區(qū)吧

這里用到的是fdisk命令,下面是該命令的一些參數(shù)說明:
p、打印分區(qū)表。
n、新建一個(gè)新分區(qū)。
d、刪除一個(gè)分區(qū)。
q、退出不保存。
w、把分區(qū)寫進(jìn)分區(qū)表,保存并退出。

[root@GHCLC6X-6786 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb23f0ad9.
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)

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').

Command (m for help):n  
#這里輸入n 新建一個(gè)新分區(qū)

Command action
   e   extended
   p   primary partition (1-4)
p    
#這里的p為建立主分區(qū),e為拓展分區(qū),我這里是新建主分區(qū),所以選p。

Partition number (1-4):1
#分區(qū)數(shù)量,我填的1,即單個(gè)分區(qū)

First cylinder (1-12401, default 1): 
Using default value 1
#這里默認(rèn)就好,默認(rèn)從第一柱面開始分配

Last cylinder, +cylinders or +size{K,M,G} (1-12401, default 12401): 
Using default value 12401
#默認(rèn)為最后一個(gè)柱面結(jié)束,即分配全部空間

Command (m for help): w
#w  寫入分區(qū)表并保存退出
The partition table has been altered!

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

4.格式化分區(qū)

這里使用快速格式化為ext4歸檔格式

[root@GHCLC6X-6786 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系統(tǒng)標(biāo)簽=
操作系統(tǒng):Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6225920 inodes, 24902750 blocks
1245137 blocks (5.00%) reserved for the super user
第一個(gè)數(shù)據(jù)塊=0
Maximum filesystem blocks=4294967296
760 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

正在寫入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

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

5.掛載磁盤

[root@GHCLC6X-6786 ~]# mkdir /data  #建立掛載點(diǎn)
[root@GHCLC6X-6786 ~]# mount /dev/sdb1 /data

6.設(shè)置自動(dòng)掛載

在這里,分區(qū)已經(jīng)成功掛載上去了,我們用df命令可以看到掛載信息:

[root@GHCLC6X-6786 ~]# df
文件系統(tǒng)             1K-塊      已用      可用 已用% 掛載點(diǎn)
/dev/sda3             13932624   2542920  10681968  20% /
tmpfs                  2996552         0   2996552   0% /dev/shm
/dev/sda1               516040     43608    446220   9% /boot
/dev/sdb1             98048020    192176  92875296   1% /data

但是,每次開機(jī)掛載未免太過麻煩,下面來設(shè)置開機(jī)自動(dòng)掛載吧:

[root@GHCLC6X-6786 ~]# vim /etc/fstab

在文件尾寫入掛載信息即可,如下圖所示:

fstab.png

--大功告成!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容