1. 查看当前的磁盘状况
[root@ip-172-**-*8-*7 /]# df -l
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 8256952 7551916 621180 93% /
tmpfs 3816936 0 3816936 0% /dev/shm
2. 添加磁盘后,查看磁盘状况
[root@ip-172-**-*8-*7 /]# fdisk -l
Disk /dev/xvda1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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
Disk /dev/xvdf: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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
从查询结果看出,多了一个/dev/xvdf的盘
3. 用fdisk 对/dev/xvdf 进行分区
[root@ip-172-**-*8-*7 /]# fdisk /dev/xvdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x61b1bc85.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
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): n //试图加入分区
Command action
e extended
p primary partition (1-4)
p //选择加入主分区
Partition number (1-4): 1 //选择加入的分区号为1
################# 以下这段是个小插曲,如果有幸没有遇到,就请绕开直接往下看 ################
Partition 1 is already defined. Delete it before re-adding it. //系统提示分区号为1的分区已定义,重加前请删除
Command (m for help): d //删除分区
Selected partition 1 //系统自动删除分区1
Command (m for help): p //再次显示系统分区
Disk /dev/xvda1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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
Device Boot Start End Blocks Id System
Command (m for help): n //选择添加系统分区
Command action
e extended
p primary partition (1-4)
p //添加主分区
Partition number (1-4): 1 //添加的主分区号为1
############# 没有遇到以上小插曲的可以直接由此往下继续操作 ####################
First cylinder (1-10443, default 1): 1 //选择1号分区的起始cylinder默认选择1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): 10443 //选择1号分区的结束cylinder(或者1号分区的大小)
Command (m for help): n //注:此处如果选择继续添加分区则需输入n,
// 然后重复上面操作继续分区,如果不在继续分区则输入w,如下:
Command (m for help): w //把新的分区表写入磁盘
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@ip-172-**-*8-*7 /]#
再次查看分区情况,多出来一个/dev/xvdf1 的区,这个1是我们在前面指定的,如果我们指定2,就变成 xvdf2了。
[root@ip-172-**-*8-*7 /]# fdisk -l
Disk /dev/xvda1: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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
Disk /dev/xvdf: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x61b1bc85
Device Boot Start End Blocks Id System
/dev/xvdf1 1 10443 83883366 83 Linux
[root@ip-172-**-*8-*7 /]#
分区完之后,使用 cat /proc/partitions 查看分区情况,如果查看不到对应的分区,则使用parprobe 命令刷新一下就可以了,如下:
[root@ip-172-**-*8-*7 /]# cat /proc/partitions
major minor #blocks name
202 1 8388608 xvda1
202 80 83886080 xvdf
202 81 83883366 xvdf1
[root@ip-172-**-*8-*7 /]#
执行刷新命令然后重新查看分区情况
[root@ip-172-**-*8-*7 /]# partprobe /dev/xvdf
[root@ip-172-**-*8-*7 /]# cat /proc/partitions
major minor #blocks name
202 1 8388608 xvda1
202 80 83886080 xvdf
202 81 83883366 xvdf1
[root@ip-172-**-*8-*7 /]#
3. 格式化 /dev/xvdf1 分区
[root@ip-172-**-*8-*7 /]# mkfs -t ext3 /dev/xvdf1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5242880 inodes, 20970841 blocks
1048542 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
640 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@ip-172-**-*8-*7 /]#
4. 创建目录 并将 /dev/xvdf1 挂在到该目录下
[root@ip-172-**-*8-*7 /]# ls
bin certificate.pem etc key.pem lib64 lost+found mnt proc root selinux sys tmp var
boot dev home lib local media opt request.pem sbin srv temp usr
[root@ip-172-**-*8-*7 /]# mkdir /disk01
[root@ip-172-**-*8-*7 /]# ls
bin certificate.pem disk01 home lib local media opt request.pem sbin srv temp usr
boot dev etc key.pem lib64 lost+found mnt proc root selinux sys tmp var
挂载磁盘命令:
[root@ip-172-**-*8-*7 /]# mount /dev/xvdf1 /disk01
注:如果需要也可卸载该磁盘,卸载命令:[root@ip-172-**-*8-*7 /]# umount /dev/xvdf1
[root@ip-172-**-*8-*7 /]# mkfs.ext2 /dev/xvdf1
如果要对已挂载的磁盘进行重新分区,则在分区前必须先要执行上面的卸载命令进行卸载,然后再重新分区
5. 验证挂载是否成功
[root@ip-172-**-*8-*7 /]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda1 8256952 7553248 619848 93% /
tmpfs 3816936 0 3816936 0% /dev/shm
/dev/xvdf1 82567188 188292 78184728 1% /disk01
[root@ip-172-**-*8-*7 /]#
6. 设置开机自动挂载
[root@ip-172-**-*8-*7 /]# vi /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/xvdf1 /disk01 ext3 defaults 0 0
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,m
anaged 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,m
anaged 0 0