免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2217 | 回复: 2
打印 上一主题 下一主题

Linux 增加分区大小 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-12 21:10 |只看该作者 |倒序浏览
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
  1. Command (m for help): p

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

  5.    Device Boot      Start         End      Blocks   Id  System
  6. /dev/sdb1   *           1         130     1044193+  83  Linux
  7. /dev/sdb2             131         391     2096482+  82  Linux swap
  8. /dev/sdb3             392         521     1044225   83  Linux
  9. /dev/sdb4             522        8942    67641682+   5  Extended
  10. /dev/sdb5             522         586      522081   83  Linux
  11. /dev/sdb6             587         651      522081   83  Linux
  12. /dev/sdb7             652        1173     4192933+  83  Linux
  13. /dev/sdb8            1174        2419    10008463+  83  Linux
复制代码
可以看到,增加了一个sdb8的分区,柱面号从1174到2419.


写入分区表,执行分区操作
  1. Command (m for help): w
  2. The partition table has been altered!

  3. Calling ioctl() to re-read partition table.

  4. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
  5. The kernel still uses the old table.
  6. The new table will be used at the next reboot.
  7. Syncing disks.
复制代码
分区完后,是看不到文件系统的
  1. [root@hdp0 hadoop]# df -m
  2. Filesystem             1M-块        已用     可用 已用% 挂载点
  3. /dev/sdb1                 1004       582       372  62% /
  4. none                      1014         0      1014   0% /dev/shm
  5. /dev/sdb3                 1004       807       147  85% /home
  6. /dev/sdb5                  494        11       458   3% /opt
  7. /dev/sdb7                 4031      3272       554  86% /usr
  8. /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

查看文件系统,可以看到新建立的分区/文件系统已经挂载上,能够使用了。
  1. [root@hdp0 hadoop]# df -m
  2. Filesystem             1M-块        已用     可用 已用% 挂载点
  3. /dev/sdb1                 1004       582       372  62% /
  4. none                      1014         0      1014   0% /dev/shm
  5. /dev/sdb3                 1004       807       147  85% /home
  6. /dev/sdb5                  494        11       458   3% /opt
  7. /dev/sdb7                 4031      3272       554  86% /usr
  8. /dev/sdb6                  494        87       382  19% /var
  9. /dev/sdb8                 9621        54      9079   1% /home/develop
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-01-12 21:11 |只看该作者
谢谢分享

论坛徽章:
0
3 [报告]
发表于 2012-01-13 01:15 |只看该作者
顶了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP