QQ登录

只需一步,快速开始

登录 | 立即注册 | 找回密码

熊天琪游戏论坛 - 玩出名堂

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8|回复: 0

[文本教程] Linux 硬盘,格式化,分区 入门详解

[复制链接]
发表于 2018-9-14 02:11:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
disk是Linux自带的硬盘分区工具,可以对硬盘进行分区,或者对硬盘分区进行调整。
首先选择要进行操作的磁盘
[root@linuxidc ~]# fdisk /dev/sdb
输入m,列出可以执行的命令
Command (m for help): mCommand actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitionl list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)
输入p,列出磁盘目前的分区情况
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sdb1 1 1 8001 8e Linux LVM/dev/sdb2 2 26 200812+ 83 Linux
输入d,然后选择分区,删除现有分区
Command (m for help): dPartition number (1-4): 1
Command (m for help): dSelected partition 2
查看分区情况,确认分区已经删除
Command (m for help): print
Disk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help):
输入n,建立新的磁盘分区,首先建立两个主磁盘分区
Command (m for help): nCommand actione extendedp primary partition (1-4)p //建立主分区Partition number (1-4): 1 //分区号First cylinder (1-391, default 1): //分区起始位置Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区
Command (m for help): n //再建立一个分区Command actione extendedp primary partition (1-4)p Partition number (1-4): 2 //分区号为2First cylinder (101-391, default 101): Using default value 101Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M
确认分区建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sdb1 1 100 803218+ 83 Linux/dev/sdb2 101 125 200812+ 83 Linux
再建立一个逻辑分区
Command (m for help): nCommand actione extendedp primary partition (1-4)e //选择扩展分区Partition number (1-4): 3First cylinder (126-391, default 126): Using default value 126Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): Using default value 391
确认扩展分区建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sdb1 1 100 803218+ 83 Linux/dev/sdb2 101 125 200812+ 83 Linux/dev/sdb3 126 391 2136645 5 Extended
在扩展分区上建立两个逻辑分区
Command (m for help): nCommand actionl logical (5 or over)p primary partition (1-4)l //选择逻辑分区First cylinder (126-391, default 126): Using default value 126Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M
Command (m for help): nCommand actionl logical (5 or over)p primary partition (1-4)lFirst cylinder (176-391, default 176): Using default value 176Last cylinder or +size or +sizeM or +sizeK (176-391, default 391): Using default value 391
确认逻辑分区建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes255 heads, 63 sectors/track, 391 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System/dev/sdb1 1 100 803218+ 83 Linux/dev/sdb2 101 125 200812+ 83 Linux/dev/sdb3 126 391 2136645 5 Extended/dev/sdb5 126 175 401593+ 83 Linux/dev/sdb6 176 391 1734988+ 83 Linux
Command (m for help):
从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6)
注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。
最后对分区操作进行保存
Command (m for help): wThe partition table has been altered!
Calling ioctl() to re-read partition table.Syncing disks.
建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。
在sdb1上建立ext2分区
[root@linuxidc ~]# mkfs.ext2 /dev/sdb1mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)100576 inodes, 200804 blocks10040 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=2097152007 block groups32768 blocks per group, 32768 fragments per group14368 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840
Writing inode tables: done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
在sdb6上建立ext3分区
[root@linuxidc ~]# mkfs.ext3 /dev/sdb6mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)217280 inodes, 433747 blocks21687 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=44459622414 block groups32768 blocks per group, 32768 fragments per group15520 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Writing inode tables: done Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@linuxidc ~]#
建立两个目录/Oracle和/web,将新建好的两个分区挂载到系统
[root@linuxidc ~]# mkdir /oracle[root@linuxidc ~]# mkdir /web[root@linuxidc ~]# mount /dev/sdb1 /oracle[root@linuxidc ~]# mount /dev/sdb6 /web
查看分区挂载情况
[root@linuxidc ~]# df -h文件系统 容量 已用 可用 已用% 挂载点/dev/mapper/VolGroup00-LogVol006.7G 2.8G 3.6G 44% //dev/sda1 99M 12M 82M 13% /boottmpfs 125M 0 125M 0% /dev/shm/dev/sdb1 773M 808K 733M 1% /oracle/dev/sdb6 1.7G 35M 1.6G 3% /web
如果需要每次开机自动挂载则需要修改/etc/fstab文件,加入两行配置
[root@linuxidc ~]# vim /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1LABEL=/boot /boot ext3 defaults 1 2tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0/dev/VolGroup00/LogVol01 swap swap defaults 0 0/dev/sdb1 /oracle ext2 defaults 0 0/dev/sdb6 /web ext3 defaults 0 0
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
[table=98%][/table]
熊天琪的论坛真是太好啦, 我太喜欢熊天琪啦
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Loading...

QQ|小黑屋|Archiver|手机版|熊天琪 ( 鄂ICP备14006674号,鄂公网安备42020502000003号 

安全联盟

GMT+8, 2018-9-26 05:20 , Processed in 0.094926 second(s), 27 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表