Linux创建主分区扩展分区fdisk,格式化分区mkfs,挂载分区mount

这里对Linux创建扩展分区和逻辑分区,以及格式化分区和挂载分区进行一个详细的介绍,希望能帮助到你们!

1.Linux 创建扩展分区以及逻辑分区

[root@localhost ~]# fdisk /dev/sdb //进入要分配的磁盘

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)
e //创建扩展分区
Partition number (1-4): 4 //分区号
First cylinder (5121-10240, default 5121): //分区开始柱面,enter默认
Using default value 5121
Last cylinder, +cylinders or +size{K,M,G} (5121-10240, default 10240): //分区结束柱面
Using default value 10240

Command (m for help): p //打印分区情况

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb92c060c

Device Boot Start End Blocks Id System
/dev/sdb1 1 5120 5242864 83 Linux
/dev/sdb4 5121 10240 5242880 5 Extended

Command (m for help): n //创建分区

Command action
l logical (5 or over)
p primary partition (1-4)
l //创建逻辑分区
First cylinder (5121-10240, default 5121): //分区开始柱面,enter默认

Using default value 5121
Last cylinder, +cylinders or +size{K,M,G} (5121-10240, default 10240): 8192

Command (m for help): n //再创建一个分区

Command action
l logical (5 or over)
p primary partition (1-4)
l //再创建一个逻辑分区

First cylinder (8193-10240, default 8193): //分区开始柱面,enter默认

Using default value 8193
Last cylinder, +cylinders or +size{K,M,G} (8193-10240, default 10240): //分区结束柱面

Using default value 10240

Command (m for help): p //打印分区表进行查看

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb92c060c

Device Boot Start End Blocks Id System
/dev/sdb1 1 5120 5242864 83 Linux
/dev/sdb4 5121 10240 5242880 5 Extended
/dev/sdb5 5121 8192 3145712 83 Linux
/dev/sdb6 8193 10240 2097136 83 Linux

Command (m for help): w //w保存上面设置,q退出而不报错
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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.

2.Linux 格式化分区

[root@localhost ~]# mkfs.ext4 /dev/sdb5 //格式化
mke2fs 1.41.12 (17-May-2010)
Could not stat /dev/sdb5 — No such file or directory //这里注意一下,先执行partprobe命令让系统内核重读分区表,如果报错要reboot一下

[root@localhost ~]# mkfs.ext4 /dev/sdb5 //格式化/dev/sdb5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786428 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkfs.ext4 /dev/sdb6 //格式化/dev/sdb6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524284 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

3.Linux 进行分区挂载

先创建两个挂载点disk01,disk02

[root@localhost var]# mkdir /disk01
[root@localhost var]# mkdir /disk02
[root@localhost var]# mount /dev/sdb5 /disk01 //挂载分区
[root@localhost var]# mount /dev/sdb6 /disk02
[root@localhost var]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 3.9G 43G 9% /
tmpfs 940M 72K 940M 1% /dev/shm
/dev/sda1 485M 38M 423M 9% /boot
/dev/mapper/VolGroup-lv_home
45G 532M 43G 2% /home
/dev/sdb5 3.0G 69M 2.8G 3% /disk01
/dev/sdb6 2.0G 35M 1.9G 2% /disk02

  • 【注】这里会发现如果电脑重新启动之后,挂载的分区都会消失,所以必须在配置文件中加入配置
    [root@localhost var]# vi /etc/fstab //添加到配置文件,这里略
    最后ESC Shift+: wq 保存退出即可

再重启系统看看吧!希望能帮助到你哦!!!

具体的可以到http://c.biancheng.net/view/887.html详细查看

猜你喜欢

转载自blog.csdn.net/Number_oneEngineer/article/details/84027180