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。

转载于:https://blog.51cto.com/junch/2299044

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值