请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
搜索

快捷运维-自动分区

[复制链接]
31237 aqzt 发表于 2016-11-17 16:19:06
本帖最后由 aqzt 于 2016-11-17 16:21 编辑

适用场景:一块硬盘,只分系统分区,存在部分未划分空间的情况。
-—————————————————————————————————————
centos6.8下测试:
  1. [root@centos6c ~]#
  2. [root@centos6c ~]#
  3. [root@centos6c ~]# df -h
  4. Filesystem Size Used Avail Use% Mounted on
  5. /dev/sda2 20G 671M 18G 4% /
  6. tmpfs 499M 0 499M 0% /dev/shm
  7. /dev/sda1 283M 27M 241M 11% /boot
  8. [root@centos6c ~]#
  9. [root@centos6c ~]#
  10. [root@centos6c ~]# bash auto_fdisk.sh
  11. Step 1.No lock file,begin to create lock file and continue.
  12. Step 2.Begin to check free disk.
  13. ext4

  14. WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
  15. switch off the mode (command ‘c’) and change display units to
  16. sectors (command ‘u’).

  17. Command (m for help): Command action
  18. e extended
  19. p primary partition (1-4)
  20. Selected partition 4
  21. First cylinder (2984-4699, default 2984): Using default value 2984
  22. Last cylinder, +cylinders or +size{K,M,G} (2984-4699, default 4699): Using default value 4699

  23. Command (m for help): First cylinder (2984-4699, default 2984): Using default value 2984
  24. Last cylinder, +cylinders or +size{K,M,G} (2984-4699, default 4699): Using default value 4699

  25. Command (m for help):
  26. Disk /dev/sda: 34.4 GB, 34359738368 bytes
  27. 255 heads, 56 sectors/track, 4699 cylinders
  28. Units = cylinders of 14280 * 512 = 7311360 bytes
  29. Sector size (logical/physical): 512 bytes / 512 bytes
  30. I/O size (minimum/optimal): 512 bytes / 512 bytes
  31. Disk identifier: 0×000aa6c6

  32. Device Boot Start End Blocks Id System
  33. /dev/sda1 * 1 44 307200 83 Linux
  34. Partition 1 does not end on cylinder boundary.
  35. /dev/sda2 44 2912 20480000 83 Linux
  36. Partition 2 does not end on cylinder boundary.
  37. /dev/sda3 2912 2984 512000 82 Linux swap / Solaris
  38. Partition 3 does not end on cylinder boundary.
  39. /dev/sda4 2984 4699 12250636 5 Extended
  40. /dev/sda5 2984 4699 12250608 83 Linux

  41. Command (m for help): Command (m for help): Command (m for help): The partition table has been altered!

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

  43. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
  44. The kernel still uses the old table. The new table will be used at
  45. the next reboot or after you run partprobe(8) or kpartx(8)
  46. Syncing disks.
  47. BLKPG: Device or resource busy
  48. error adding partition 1
  49. BLKPG: Device or resource busy
  50. error adding partition 2
  51. BLKPG: Device or resource busy
  52. error adding partition 3
  53. mke2fs 1.41.12 (17-May-2010)
  54. 文件系统标签=
  55. 操作系统:Linux
  56. 块大小=4096 (log=2)
  57. 分块大小=4096 (log=2)
  58. Stride=0 blocks, Stripe width=0 blocks
  59. 767040 inodes, 3062652 blocks
  60. 153132 blocks (5.00%) reserved for the super user
  61. 第一个数据块=0
  62. Maximum filesystem blocks=3137339392
  63. 94 block groups
  64. 32768 blocks per group, 32768 fragments per group
  65. 8160 inodes per group
  66. Superblock backups stored on blocks:
  67. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

  68. 正在写入inode表: 完成
  69. Creating journal (32768 blocks): 完成
  70. Writing superblocks and filesystem accounting information: 完成

  71. This filesystem will be automatically checked every 29 mounts or
  72. 180 days, whichever comes first. Use tune2fs -c or -i to override.
  73. Filesystem Size Used Avail Use% Mounted on
  74. /dev/sda2 20G 671M 18G 4% /
  75. tmpfs 499M 0 499M 0% /dev/shm
  76. /dev/sda1 283M 27M 241M 11% /boot
  77. /dev/sda5 12G 30M 11G 1% /data
  78. [root@centos6c ~]#

  79. centos7.2下测试:
  80. [root@centos7a ~]#
  81. [root@centos7a ~]#
  82. [root@centos7a ~]# df -h
  83. 文件系统 容量 已用 可用 已用% 挂载点
  84. /dev/sda3 10G 1.1G 8.9G 11% /
  85. devtmpfs 488M 0 488M 0% /dev
  86. tmpfs 497M 0 497M 0% /dev/shm
  87. tmpfs 497M 6.7M 490M 2% /run
  88. tmpfs 497M 0 497M 0% /sys/fs/cgroup
  89. /dev/sda1 297M 106M 192M 36% /boot
  90. tmpfs 100M 0 100M 0% /run/user/0
  91. /dev/sda5 49G 53M 46G 1% /data
  92. [root@centos7a ~]#
  93. [root@centos7a ~]#
  94. [root@centos7a ~]#
  95. [root@centos7a ~]#
  96. [root@centos7a ~]#
  97. [root@centos7a ~]#
  98. [root@centos7a ~]# df -h
  99. 文件系统 容量 已用 可用 已用% 挂载点
  100. /dev/sda3 10G 1.1G 8.9G 11% /
  101. devtmpfs 488M 0 488M 0% /dev
  102. tmpfs 497M 0 497M 0% /dev/shm
  103. tmpfs 497M 6.7M 490M 2% /run
  104. tmpfs 497M 0 497M 0% /sys/fs/cgroup
  105. /dev/sda1 297M 106M 192M 36% /boot
  106. tmpfs 100M 0 100M 0% /run/user/0
  107. /dev/sda5 49G 53M 46G 1% /data
  108. [root@centos7a ~]#
  109. [root@centos7a ~]#
  110. [root@centos7a ~]# bash auto_fdisk.sh
  111. Step 1.No lock file,begin to create lock file and continue.
  112. Step 2.Begin to check free disk.
  113. 欢迎使用 fdisk (util-linux 2.23.2)。

  114. 更改将停留在内存中,直到您决定将更改写入磁盘。
  115. 使用写入命令前请三思。

  116. 命令(输入 m 获取帮助):All primary partitions are in use
  117. 添加逻辑分区 6
  118. No free sectors available

  119. 命令(输入 m 获取帮助):e: unknown command
  120. 命令操作
  121. a toggle a bootable flag
  122. b edit bsd disklabel
  123. c toggle the dos compatibility flag
  124. d delete a partition
  125. g create a new empty GPT partition table
  126. G create an IRIX (SGI) partition table
  127. l list known partition types
  128. m print this menu
  129. n add a new partition
  130. o create a new empty DOS partition table
  131. p print the partition table
  132. q quit without saving changes
  133. s create a new empty Sun disklabel
  134. t change a partition’s system id
  135. u change display/entry units
  136. v verify the partition table
  137. w write table to disk and exit
  138. x extra functionality (experts only)

  139. 命令(输入 m 获取帮助):命令(输入 m 获取帮助):命令(输入 m 获取帮助):All primary partitions are in use
  140. 添加逻辑分区 6
  141. No free sectors available

  142. 命令(输入 m 获取帮助):命令(输入 m 获取帮助):命令(输入 m 获取帮助):
  143. 磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
  144. Units = 扇区 of 1 * 512 = 512 bytes
  145. 扇区大小(逻辑/物理):512 字节 / 512 字节
  146. I/O 大小(最小/最佳):512 字节 / 512 字节
  147. 磁盘标签类型:dos
  148. 磁盘标识符:0x00013952

  149. 设备 Boot Start End Blocks Id System
  150. /dev/sda1 * 2048 616447 307200 83 Linux
  151. /dev/sda2 616448 1640447 512000 82 Linux swap / Solaris
  152. /dev/sda3 1640448 22611967 10485760 83 Linux
  153. /dev/sda4 22611968 125829119 51608576 5 Extended
  154. /dev/sda5 22614016 125829119 51607552 83 Linux

  155. 命令(输入 m 获取帮助):命令(输入 m 获取帮助):命令(输入 m 获取帮助):The partition table has been altered!

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

  157. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
  158. The kernel still uses the old table. The new table will be used at
  159. the next reboot or after you run partprobe(8) or kpartx(8)
  160. 正在同步磁盘。
  161. 文件系统 容量 已用 可用 已用% 挂载点
  162. /dev/sda3 10G 1.1G 8.9G 11% /
  163. devtmpfs 488M 0 488M 0% /dev
  164. tmpfs 497M 0 497M 0% /dev/shm
  165. tmpfs 497M 6.7M 490M 2% /run
  166. tmpfs 497M 0 497M 0% /sys/fs/cgroup
  167. /dev/sda1 297M 106M 192M 36% /boot
  168. tmpfs 100M 0 100M 0% /run/user/0
  169. /dev/sda5 49G 53M 46G 1% /data
  170. [root@centos7a ~]#
  171. [root@centos7a ~]#
  172. [root@centos7a ~]#
复制代码

回复

使用道具 举报

主东锁 发表于 2016-12-2 21:40:40
我了个去,顶了
回复 支持 反对

使用道具 举报

诚太爱 发表于 2016-12-3 01:05:40
确实不错,顶先
回复 支持 反对

使用道具 举报

旺大善 发表于 2016-12-3 07:55:41
没人回帖。。。我来个吧
回复 支持 反对

使用道具 举报

凡运福 发表于 2016-12-3 19:32:05
好,很好,非常好!
回复 支持 反对

使用道具 举报

达雷础 发表于 2016-12-4 04:40:22
1v1飘过
回复 支持 反对

使用道具 举报

博光广 发表于 2016-12-4 21:23:10
为了三千积分!
回复 支持 反对

使用道具 举报

公业干 发表于 2016-12-5 06:21:44
我也来顶一下..
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表