添加磁盘扩容操作:
1、添加物理磁盘到服务器重启服务器,#fdisk -l查看识别磁盘(以/dev/sdb为例)
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0006a7c5
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 287 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 287 5222 39640064 83 Linux
disk /dev/sdb: 21.5 gb, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00000000
2、添加分区
[root@localhost ~]# fdisk /dev/sdb
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition (删除分区)
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)
#用"n"新建分区选择"p"主分区,在这里可以新建三个主分区剩下的可以建成扩展分区 选择“e”扩展分区
Command (m for help): n
Command action
e extended (扩展分区)
p primary partition (1-4) (主分区)
1
Invalid partition number for type `1'
Command action
e extended
p primary partition (1-4)
p (p为新建主分区)
Partition number (1-4): 1 (主分区号)
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G (给主分区分配2G空间)
Command (m for help): p (打印出配置的分区信息)
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xbf76d5e8
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux (已经分配好的分区)
一般是先建三个主分区再有需求在建剩下空间的扩展分区
新建三个主分区和两个扩展分区并且保存退出
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xbf76d5e8
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 524 2104515 83 Linux
/dev/sdb3 525 786 2104515 83 Linux
/dev/sdb4 787 2610 14651280 5 Extended
/dev/sdb5 787 918 1060258+ 83 Linux
/dev/sdb6 919 1050 1060258+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、使分区生效
[root@localhost ~]# partprobe (强制让内核重新找一次分区表)
4、查看新建分区
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xbf76d5e8
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 524 2104515 83 Linux
/dev/sdb3 525 786 2104515 83 Linux
/dev/sdb4 787 2610 14651280 5 Extended
/dev/sdb5 787 918 1060258+ 83 Linux
/dev/sdb6 919 1050 1060258+ 83 Linux
5、格式化分区
[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkfs.ext3 /dev/sdb2
[root@localhost ~]# mkfs.ext3 /dev/sdb3
[root@localhost ~]# mkfs.ext3 /dev/sdb5
[root@localhost ~]# mkfs.ext3 /dev/sdb6 (剩下的分区都格式化)
6、新建挂载目录并且挂载到系统上
[root@localhost ~]# mkdir -p /sdb/sdb1
[root@localhost ~]# mkdir -p /sdb/sdb2
[root@localhost ~]# mkdir -p /sdb/sdb3
[root@localhost ~]# mkdir -p /sdb/sdb5
[root@localhost ~]# mkdir -p /sdb/sdb6
[root@localhost ~]# ls /sdb
sdb1 sdb2 sdb3 sdb5 sdb6
[root@localhost ~]# mount /dev/sdb1 /sdb/sdb1
[root@localhost ~]# mount /dev/sdb2 /sdb/sdb2
[root@localhost ~]# mount /dev/sdb3 /sdb/sdb3
[root@localhost ~]# mount /dev/sdb5 /sdb/sdb5
[root@localhost ~]# mount /dev/sdb6 /sdb/sdb6
7、修改配置文件设置开机自动挂载
[root@localhost ~]# vi /etc/fstab
# /etc/fstab
# Created by anaconda on Fri Oct 14 22:27:19 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=bd82cad1-2b0a-4984-9846-06e690b1fdad / ext3 defaults 1 1
UUID=6d8f8e24-7849-4ad9-af35-7e8fb71eb7ec /boot ext3 defaults 1 2
UUID=dc268ee4-ba91-471f-9acf-94d0a2658083 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sdb1 /sdb/sdb1 ext3 defaults 0 0 (新添加挂载选项)
/dev/sdb2 /sdb/sdb2 ext3 defaults 0 0 (defaults都是00)
/dev/sdb3 /sdb/sdb3 ext3 defaults 0 0
/dev/sdb5 /sdb/sdb5 ext3 defaults 0 0
/dev/sdb6 /sdb/sdb6 ext3 defaults 0 0
8、重启服务器生效,并查看分区结果
[root@localhost ~]# reboot
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 38G 7.7G 28G 22% /
tmpfs tmpfs 495M 0 495M 0% /dev/shm
/dev/sda1 ext3 194M 30M 155M 17% /boot
/dev/sdb1 ext3 2.0G 68M 1.9G 4% /sdb/sdb1
/dev/sdb2 ext3 2.0G 68M 1.9G 4% /sdb/sdb2
/dev/sdb3 ext3 2.0G 68M 1.9G 4% /sdb/sdb3
/dev/sdb5 ext3 1020M 34M 935M 4% /sdb/sdb5
/dev/sdb6 ext3 1020M 34M 935M 4% /sdb/sdb6
扩容成功。
备注:1、这是在虚拟机上自己实验操作的,所以一块盘的空间20G在真正的工作环境中扩充的盘都是几百G甚至好几个T的;
2、Linux上还有一个伸缩性更好的为服务器扩容的方法即LVM,更灵活操作也很简单。