Skip to content

使用快捷运维脚本 自动分区

Robert edited this page Sep 2, 2016 · 3 revisions

使用快捷运维脚本-自动分区
https://github.com/aqzt/kjyw/blob/master/disk/auto_fdisk.sh

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

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): Command action
e extended
p primary partition (1-4)
Selected partition 4
First cylinder (2984-4699, default 2984): Using default value 2984
Last cylinder, +cylinders or +size{K,M,G} (2984-4699, default 4699): Using default value 4699

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

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

Device Boot Start End Blocks Id System

/dev/sda1 * 1 44 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 44 2912 20480000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 2912 2984 512000 82 Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4 2984 4699 12250636 5 Extended
/dev/sda5 2984 4699 12250608 83 Linux

Command (m for help): Command (m for help): Command (m for help): 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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
767040 inodes, 3062652 blocks
153132 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=3137339392
94 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

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

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


centos7.2下测试:
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 10G 1.1G 8.9G 11% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.7M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 297M 106M 192M 36% /boot
tmpfs 100M 0 100M 0% /run/user/0
/dev/sda5 49G 53M 46G 1% /data
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 10G 1.1G 8.9G 11% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.7M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 297M 106M 192M 36% /boot
tmpfs 100M 0 100M 0% /run/user/0
/dev/sda5 49G 53M 46G 1% /data
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]# bash auto_fdisk.sh
Step 1.No lock file,begin to create lock file and continue.
Step 2.Begin to check free disk.
欢迎使用 fdisk (util-linux 2.23.2)。

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

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

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

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

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

设备 Boot Start End Blocks Id System

/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 1640447 512000 82 Linux swap / Solaris
/dev/sda3 1640448 22611967 10485760 83 Linux
/dev/sda4 22611968 125829119 51608576 5 Extended
/dev/sda5 22614016 125829119 51607552 83 Linux

命令(输入 m 获取帮助):命令(输入 m 获取帮助):命令(输入 m 获取帮助):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 or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 10G 1.1G 8.9G 11% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.7M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 297M 106M 192M 36% /boot
tmpfs 100M 0 100M 0% /run/user/0
/dev/sda5 49G 53M 46G 1% /data
[root@centos7a ~]#
[root@centos7a ~]#
[root@centos7a ~]#

Clone this wiki locally