Linux下磁盘分区

环境:
Redhat6.5 64位

安装前准备,给虚拟机添加一块磁盘,大小10G

第一步先查看系统磁盘列表

 1 [root@localhost ~]# fdisk -l
 2 
 3 Disk /dev/sda: 32.2 GB, 32212254720 bytes
 4 255 heads, 63 sectors/track, 3916 cylinders
 5 Units = cylinders of 16065 * 512 = 8225280 bytes
 6 Sector size (logical/physical): 512 bytes / 512 bytes
 7 I/O size (minimum/optimal): 512 bytes / 512 bytes
 8 Disk identifier: 0x00029423
 9 
10    Device Boot      Start         End      Blocks   Id  System
11 /dev/sda1   *           1          64      512000   83  Linux
12 Partition 1 does not end on cylinder boundary.
13 /dev/sda2              64         587     4194304   82  Linux swap / Solaris
14 Partition 2 does not end on cylinder boundary.
15 /dev/sda3             587        3917    26749952   83  Linux
16 
17 Disk /dev/sdb: 10.7 GB, 10737418240 bytes     //第二块磁盘没有分区列表,也就是没有分区
18 255 heads, 63 sectors/track, 1305 cylinders
19 Units = cylinders of 16065 * 512 = 8225280 bytes
20 Sector size (logical/physical): 512 bytes / 512 bytes
21 I/O size (minimum/optimal): 512 bytes / 512 bytes
22 Disk identifier: 0x00000000

第二步,给第二块磁盘(/dev/sdb)分区

 1 [root@localhost ~]# fdisk /dev/sdb    //给第二块硬盘分区
 2 
 3 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
 4          switch off the mode (command 'c') and change display units to
 5          sectors (command 'u').
 6 
 7 Command (m for help): n     //新建一个分区
 8 Command action
 9    e   extended
10    p   primary partition (1-4)
11 p            //分区类型为主分区
12 Partition number (1-4): 1    //由于主分区加扩展分区只能有四个1-4
13 First cylinder (1-1305, default 1):     //直接回车默认为第一块分区
14 Using default value 1
15 Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +2G    //由于磁盘柱面不好理解,可以直接指定分区大小单位(K,M,G)
16 
17 Command (m for help): n   //再新建一个分区
18 Command action
19    e   extended
20    p   primary partition (1-4)
21 e    //分区类型为扩展分区
22 Partition number (1-4): 2   //不能使用前面已用过的分区号
23 First cylinder (263-1305, default 263):    //直接回车,默认起始柱面即可
24 Using default value 263
25 Last cylinder, +cylinders or +size{K,M,G} (263-1305, default 1305): +5G   //指定分区大小
26 
27 Command (m for help): n    //新建分区
28 Command action
29    l   logical (5 or over)
30    p   primary partition (1-4)
31 l       //前面已经有了扩展分区,所以可以新建逻辑分区了
32 First cylinder (263-916, default 263):       //直接回车
33 Using default value 263
34 Last cylinder, +cylinders or +size{K,M,G} (263-916, default 916): +2G   //指定分区大小
35 
36 Command (m for help): n
37 Command action
38    l   logical (5 or over)
39    p   primary partition (1-4)
40 l
41 First cylinder (525-916, default 525):
42 Using default value 525
43 Last cylinder, +cylinders or +size{K,M,G} (525-916, default 916): +2G
44 
45 Command (m for help): p      //查看分区列表
46 
47 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
48 255 heads, 63 sectors/track, 1305 cylinders
49 Units = cylinders of 16065 * 512 = 8225280 bytes
50 Sector size (logical/physical): 512 bytes / 512 bytes
51 I/O size (minimum/optimal): 512 bytes / 512 bytes
52 Disk identifier: 0x9c990fc8
53 
54    Device Boot      Start         End      Blocks   Id  System
55 /dev/sdb1               1         262     2104483+  83  Linux
56 /dev/sdb2             263         916     5253255    5  Extended
57 /dev/sdb5             263         524     2104483+  83  Linux
58 /dev/sdb6             525         786     2104483+  83  Linux
59 
60 Command (m for help): w    //保存分区列表并退出

注意退出后,这时磁盘还不能写入内容。

第三步,刷新磁盘

1 [root@localhost ~]# partprobe /dev/sdb

第四步格式化前面的sdb5和sdb6,分区只有格式化后才能写入内容。

 1 [root@localhost ~]# mkfs -t ext4 /dev/sdb5     //mkfs 制作文件系统  -t 指定文件系统类型
 2 mke2fs 1.41.12 (17-May-2010)
 3 Filesystem label=
 4 OS type: Linux
 5 Block size=4096 (log=2)
 6 Fragment size=4096 (log=2)
 7 Stride=0 blocks, Stripe width=0 blocks
 8 131648 inodes, 526120 blocks
 9 26306 blocks (5.00%) reserved for the super user
10 First data block=0
11 Maximum filesystem blocks=541065216
12 17 block groups
13 32768 blocks per group, 32768 fragments per group
14 7744 inodes per group
15 Superblock backups stored on blocks:
16     32768, 98304, 163840, 229376, 294912
17 
18 Writing inode tables: done
19 Creating journal (16384 blocks): done
20 Writing superblocks and filesystem accounting information: done
21 
22 This filesystem will be automatically checked every 34 mounts or
23 180 days, whichever comes first.  Use tune2fs -c or -i to override.
24 [root@localhost ~]# mkfs -t ext4 /dev/sdb6
25 mke2fs 1.41.12 (17-May-2010)
26 Filesystem label=
27 OS type: Linux
28 Block size=4096 (log=2)
29 Fragment size=4096 (log=2)
30 Stride=0 blocks, Stripe width=0 blocks
31 131648 inodes, 526120 blocks
32 26306 blocks (5.00%) reserved for the super user
33 First data block=0
34 Maximum filesystem blocks=541065216
35 17 block groups
36 32768 blocks per group, 32768 fragments per group
37 7744 inodes per group
38 Superblock backups stored on blocks:
39     32768, 98304, 163840, 229376, 294912
40 
41 Writing inode tables: done
42 Creating journal (16384 blocks): done
43 Writing superblocks and filesystem accounting information: done
44 
45 This filesystem will be automatically checked every 38 mounts or
46 180 days, whichever comes first.  Use tune2fs -c or -i to override.

第五步,挂在分区测试

1 [root@localhost ~]# mkdir /media/mountsdb    //新建一个目录挂载分区使用
2 [root@localhost ~]# mount /dev/sdb5 /media/mountsdb/
3 [root@localhost ~]# cd /media/mountsdb/
4 [root@localhost mountsdb]# ls
5 lost+found
6 [root@localhost mountsdb]# touch example.txt  //创建文件测试是否能写入内容
7 [root@localhost mountsdb]# ls
8 example.txt  lost+found
9 [root@localhost mountsdb]#

 

posted on 2017-10-03 20:39  iaknehc  阅读(331)  评论(0编辑  收藏  举报

导航