Linux增加分区大小

这里以Red hat AS4 为例。当磁盘分区发现不够用时,能想道的第一个做法就是增加分区大小。但是一般Linux如果没有采用逻辑卷管理,则动态增加分区大小很困难,一个能想道的办法就是,备份分区文件系统数据,删除分区,然后再重新创建分区,恢复备份的文件系统,这个做法比较玄,可能删除分区后导致系统无法启动。

第二个做法就是,创建一个新的逻辑分区(当然必须有未使用的磁盘空间能分配),将文件系统从老分区拷贝到新分区,然后修改fstab,使用新分区/文件系统替换老的分区/文件系统

第三种做法是,创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用。

这里采用的是第三种方式:

sdb为第二个SCSI硬盘。
[root@hdp0 hadoop]# /sbin/fdisk /dev/sdb

The number of cylinders for this disk is set to 8942.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
可以看出sdb1,2,3为主分区,sdb4为扩展分区。后面的sdb5,6,7则为逻辑分区。柱面编号(Start,End)是连续的,sdb7只用道了1173,而从扩展分区看最大到8942,也就是说,还有7769个柱面是空闲的,一个柱面大小为8225280,约为8M大小。还剩7769*8225280bytes,约62G未使用。

新增加一个逻辑分区(注:若涉及到主分区和扩展分区,实际情况可能比这个复杂,这里4个主分区(包括扩展分区)都分过了,所以只能分逻辑分区)
Command (m for help): n
First cylinder (1174-8942, default 1174):
Using default value 1174

增加大小为10G
Last cylinder or +size or +sizeM or +sizeK (1174-8942, default 8942): +10240M
增加后看一下,多了一个逻辑分区/dev/sdb8

Command (m for help): p

Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
/dev/sdb8 1174 2419 10008463+ 83 Linux

可以看到,增加了一个sdb8的分区,柱面号从1174到2419.
写入分区表,执行分区操作
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

分区完后,是看不到文件系统的
[root@hdp0 hadoop]# df -m
Filesystem 1M-块 已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var

重启机器

reboot

格式化文件系统

[root@hdp0 hadoop]#/sbin/mkfs.ext3 /dev/sdb8

mount文件系统,/home/develop 为/home下一目录
[root@hdp0 hadoop]#mount /dev/sdb8 /home/develop

查看文件系统,可以看到新建立的分区/文件系统已经挂载上,能够使用了。

[root@hdp0 hadoop]# df -m
Filesystem 1M-块 已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var
/dev/sdb8 9621 54 9079 1% /home/develop

摘自 hongweigg的专栏

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值