linux擴展非lvm的主分區磁盤空間

最近發現備份服務器的分區空間開始告警,需要擴充磁盤空間, 在存儲中把卷擴大後, linux 系統中還不能馬上識別, 因爲沒有用linux 的LVM 來管理磁盤, 所以只好用 fdisk 來擴充分區了。

用fdisk 先刪除原有分區, 再重建分區, 起始cylinder 絕對不可以改,這樣會破壞原分區的數據。

分區建好後, 就可以用e2fsck 先檢查一下分區, 再用resize2fs 擴大就可以了。

[root@linuxprobe ~]# umount /dev/sda4 #卸載磁盤分區

若提示磁盤忙,使用fuser找出將正在使用磁盤的程序並結束掉;

fuser -m -v /data
fuser -m -v -i -k /data
使用fdisk工具先刪除/dev/sda4分區,然後創建新分區,注意開始的磁柱號要和原來的一致(是保證數據不丟失的關鍵步驟),結束的磁柱號默認回車使用全部磁盤。

[root@linuxprobe ~]# fdisk /dev/sda

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): p #查看分區表信息Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005210c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1497 1572864 82 Linux swap / Solaris
/dev/sda4 1497 2611 8952832 83 Linux

Command (m for help): d #刪除分區Partition number (1-4): 4 #刪除第四個Command (m for help): p #再次查看分區信息,/dev/sda4已被刪除Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005210c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1497 1572864 82 Linux swap / Solaris

Command (m for help): n #創建新的分區Command action
e extended
p primary partition (1-4)
p #創建爲主分區
Selected partition 4
First cylinder (1497-3916, default 1497): #經對比,正好和上一個磁盤柱一致,默認即可Using default value 1497
Last cylinder, +cylinders or +size{K,M,G} (1497-3916, default 3916):
Using default value 3916 #直接默認就可以Command (m for help): p #查看分區表信息Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005210c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1497 1572864 82 Linux swap / Solaris
/dev/sda4 1497 3916 19436582 83 Linux

Command (m for help): wp #保存並退出,如果創建有誤,直接退出不要保存即可The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

重新創建分區後,需要重啓一下;

[root@linuxprobe ~]# init 6
[root@linuxprobe ~]# e2fsck -f /dev/sda4 #檢查分區信息[root@linuxprobe ~]# resize2fs -p /dev/sda4 #調整分區大小
重新掛載、查看分區大小、數據

[root@linuxprobe ~]# mount /dev/sda4 /data
[root@linuxprobe ~]# df -hT
[root@linuxprobe ~]# cat /data/linuxprobe
we are Linuxer

在vim修改/etc/fstab文件,加入【/dev/sda4 /disk4 ext2 defaults 0 0】一行,並保存,實現開機自動mount。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章