1,首先查看实际磁盘个数和大小。
1.1,#fdisk -l (如果是虚拟机,则是# ls /dev/vd*)
-
[root@nagios ~]# fdisk -l | grep sd
Disk /dev/sdb: 300.0 GB, 300000000000 bytes
/dev/sdb1 1 26109 209720511 83 Linux
/dev/sdb2 26110 36472 83240797+ 83 Linux
Disk /dev/sda: 300.0 GB, 300000000000 bytes
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 36473 292455424 8e Linux LVM
-
其中sda1,和sda2 不死磁盘,而是sda磁盘的分区。
所以看出,有两个磁盘,分别是300G和500G。
2,使用fdisk进行分区。
fdisk 加"磁盘路劲"参数 ,进去根据提示,敲m显示帮助信息。
-
[root@nagios ~]# fdisk /dev/sda
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)
其中重要的几个,p输出磁盘分区表,n添加磁盘分区,d删除磁盘分区,t改变分区格式,l列出每种分区格式的ID值。
3,举例创建一个linux分区。
-
[root@localhost ~]# fdisk /dev/vdb
-
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
-
Building a new DOS disklabel with disk identifier 0xc8542e4a.
-
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): p
-
-
Disk /dev/vdb: 322.1 GB, 322122547200 bytes
-
16 heads, 63 sectors/track, 624152 cylinders
-
Units = cylinders of 1008 * 512 = 516096 bytes
-
Sector size (logical/physical): 512 bytes / 512 bytes
-
I/O size (minimum/optimal): 512 bytes / 512 bytes
-
Disk identifier: 0xc8542e4a
-
-
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
-
First cylinder (1-624152, default 1):
-
Using default value 1
-
Last cylinder, +cylinders or +size{K,M,G} (1-624152, default 624152): +100G
-
-
Command (m for help): p
-
-
Disk /dev/vdb: 322.1 GB, 322122547200 bytes
-
16 heads, 63 sectors/track, 624152 cylinders
-
Units = cylinders of 1008 * 512 = 516096 bytes
-
Sector size (logical/physical): 512 bytes / 512 bytes
-
I/O size (minimum/optimal): 512 bytes / 512 bytes
-
Disk identifier: 0xc8542e4a
-
-
Device Boot Start End Blocks Id System
-
/dev/vdb1 1 208052 104858176+ 83 Linux
-
-
Command (m for help): w
-
The partition table has been
-
-
Calling ioctl() to re-read partition table.
-
Syncing disks.
-
[root@localhost ~]#
第13行: 输入p,显示所有分区,看到还没有建立分区。
第24行: 输入n,新建分区。
第28行:要求选择主分区还是扩展分区,这里选择主分区。
第31行:要求输入分区号,这里填1,就会创建/dev/sda1分区。
第30行:输入开始扇区,如果新建默认是1,直接回车。
第31行: 输入结束扇区,或者输入大小,这里输入大小 “+100G”,注意必须有"+"符号。
第46行: 将分区信息写入磁盘,分区信息保存退出。
4,查看分区,可以看到多了/dev/sdb1分区:
-
[root@localhost ~]# fdisk -l /dev/sdb
-
-
Disk /dev/sdb: 322.1 GB, 322122547200 bytes
-
16 heads, 63 sectors/track, 624152 cylinders
-
Units = cylinders of 1008 * 512 = 516096 bytes
-
Sector size (logical/physical): 512 bytes / 512 bytes
-
I/O size (minimum/optimal): 512 bytes / 512 bytes
-
Disk identifier: 0xc8542e4a
-
-
Device Boot Start End Blocks Id System
-
/dev/sdb1 1 208052 104858176+ 83 Linux
5,格式化分区:
利用划好的分区,可以直接进行文件系统格式化。
-
[root@localhost ~]# mkfs.ext4 /dev/vdb1
-
mke2fs 1.41.12 (17-May-2010)
-
warning: 144 blocks unused.
格式化时间长短,取决于,磁盘分区大小。
6,挂载分区:
将/dev/vdb1分区挂载在/mnt目录下。要确保/mnt/目录为空,或者挂载在一个实际为空的其他目录。
-
[root@localhost ~]# mount /dev/vdb1 /mnt/
-
[root@localhost ~]# cd /mnt/
-
[root@localhost mnt]# ls
-
lost+found
-
[root@localhost mnt]#
这里就完成了,磁盘的分区,格式化,和挂载,此时对挂载的目录的操作就相当于对磁盘的操作。
阅读(1378) | 评论(0) | 转发(0) |