相信不少人使用過(guò)阿里云的服務(wù)器,使用阿里云服務(wù)器對(duì)于添加的硬盤(pán)需要自行掛載家卖。這里記錄下使用亞馬遜云硬盤(pán)方面碰到的坑僻焚。
一砸捏、事件起因
我創(chuàng)建了一個(gè)新的CentOS Linux實(shí)例冗懦。我實(shí)例的創(chuàng)建后爽冕,但是當(dāng)系統(tǒng)上線時(shí)只顯示盤(pán)8GB是可用的。創(chuàng)建實(shí)例的時(shí)候我很認(rèn)真的確認(rèn)我選擇了30GB的硬盤(pán)披蕉,百思不得其解,最后在有過(guò)aws經(jīng)驗(yàn)的朋友幫助下解決此問(wèn)題,其實(shí)是他也踩過(guò)的坑没讲。
二眯娱、操作步驟
1.查看分區(qū)信息
使用 df -h 查看分區(qū)信息,發(fā)現(xiàn)根分區(qū)只有8個(gè)G
fdisk -l 可以看到實(shí)際空間是32.2 G
2.擴(kuò)大硬盤(pán)空間
對(duì)磁盤(pán)重新分區(qū)操作(接下來(lái)會(huì)介紹詳細(xì)步驟):
現(xiàn)在來(lái)對(duì)命令進(jìn)行介紹:
對(duì)/dev/xvda 分區(qū)進(jìn)行操作
[root@ip-172-31-26-162 ~]# fdisk /dev/xvda
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').
使用u選項(xiàng) 顯示單元扇區(qū)
Command (m for help): u
Changing display/entry units to sectors
按p 顯示詳細(xì)信息:
Command (m for help): p
Disk /dev/xvda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0050d75
Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 62914559 31456256 83 Linux
刪除第一個(gè)分區(qū)
Command (m for help): d
Selected partition 1
開(kāi)始創(chuàng)建一個(gè)新的分區(qū)爬凑,第一個(gè)扇面輸入2048徙缴,需跟原有的start扇區(qū)一致。結(jié)尾的扇區(qū)選擇最后一塊(默認(rèn)即最后一個(gè))
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-62914559, default 63): 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Using default value 62914559
再打印分區(qū)信息嘁信,會(huì)發(fā)現(xiàn)所有的磁盤(pán)空間都使用上了
Command (m for help): p
Disk /dev/xvda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0050d75
Device Boot Start End Blocks Id System
/dev/xvda1 2048 62914559 31456256 83 Linux
設(shè)置分區(qū)1為啟動(dòng)標(biāo)志
Command (m for help): a
Partition number (1-4): 1
按 w 將分區(qū)信息寫(xiě)入磁盤(pán):
Command (m for help): w
最后重啟系統(tǒng)并再次運(yùn)行resize2fs
[root@ip-172-31-26-162 ~]# reboot
[root@ip-172-31-26-162 ~]# resize2fs /dev/xvda1
......
[root@ip-172-31-26-162 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 30G 1.9G 27G 7% /
tmpfs 498M 0 498M 0% /dev/shm
磁盤(pán)已經(jīng)成功擴(kuò)大到實(shí)際大小了