linux添加新磁盘和创建分区_linux添加逻辑分区

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 33
  • 34
  • 35
  • 36
  • 37

3、有扩展分区和主分区,逻辑分区在扩展分区中建立。注意到括号中的1-4,最多只能建四个主分区(包括扩展分区)。先建一个主分区:

 #继续上面的操作
Command (m for help): n
Command action
   e   extended    //扩展分区
   p   primary partition (1-4)  //主分区

p   #输入p创建主分区
Partition number (1-4): 1   #分区号为1
First cylinder (1-2610, default 1):   #直接回车默认从第一个柱面开始划分
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G
#加空间大小,这里有很多种选择:+后面单位可以接M,G,K(记得要大写)表示划分你所加的空间,也可以是柱面数。不管怎样都不能超过该磁盘剩余的空间否则无效。

Command (m for help): p    #分好后查看分区信息,刚所做的所有一目了然。

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x1949791c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

4、同上所述建立扩展分区:

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (263-2610, default 263): 
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): +4G

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x1949791c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263         785     4200997+   5  Extended

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

5、扩展分区建好就可以在扩展分区建立逻辑分区了

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l   #创建逻辑分区
First cylinder (263-785, default 263): 
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-785, default 785): +2G

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x1949791c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263         785     4200997+   5  Extended
/dev/sdb5             263         524     2104483+  83  Linux

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

6、上面显示已经建好一个主分区,一个逻辑分区,但是这些现在还没有生效,需要保存退出。

Command (m for help): w  #保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

7、退出后查看:

[root@localhost Desktop]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00053377

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2358    18631680   83  Linux
/dev/sda3            2358        2611     2031616   82  Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x1949791c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263         785     4200997+   5  Extended
/dev/sdb5             263         524     2104483+  83  Linux

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

8、这时需要给它设置文件系统并进行格式化。 
mkfs -t ext3 /dev/sdb5 
给它设置ext3的文件系统,并格式化。

[root@localhost Desktop]# mkfs -t ext3 /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
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 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 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

9、在新建个目录,mkdir /data15 ; 
用来挂载这个分区。mount /dev/sdb5 /data15 ;

[root@localhost Desktop]# mkdir /data15;
[root@localhost Desktop]# mount /dev/sdb5 /data15;

   
   
  • 1
  • 2
  • 3

10、查看是否挂载成功:df -TH /data15/

[root@localhost Desktop]# df -TH /data15/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb5      ext3  2.2G   71M  2.0G   4% /data15

   
   
  • 1
  • 2
  • 3
  • 4

11、这样就可以正常使用了。可是重启之后又要手动挂载怎么办? 
很简单,我们只要配置一下就OK了。 
vim /etc/fstab 
编辑文件 将/dev/sdb5 /data15 ext3 defaults 0 0加入即可

#
# /etc/fstab
# Created by anaconda on Mon Oct 24 02:05:13 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=147a6e0f-8fa6-4bb5-a27a-91aaa7cf178f /                       ext4    defaults        1 1
UUID=410da4b5-ac87-43e3-ab4a-b33df31e38cf /boot                   ext4    defaults        1 2
UUID=d0c4ed83-d5d3-4245-af14-1434f4b3438f swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sdb5 /data15 ext3 defaults 0 0
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"/etc/fstab" 16L, 841C     
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

【o】 英文小写字母o,在目前光标所在行的下一行处插入新的一行并开始插入 
【O】 英文大写字母O,在目前光标所在行的上一行处插入新的一行并开始插入 
:wq保存退出

11、查看

[root@localhost Desktop]# ls /data\*
/data15:
lost+found

   
   
  • 1
  • 2
  • 3
  • 4

重复以上操作,对sdb1进行挂载

[root@localhost Desktop]# mkfs -t ext3 /dev/sdb1
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
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 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 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@localhost Desktop]# mount /dev/sdb1 /data5


[root@localhost Desktop]# df -TH /data5/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      ext3  2.2G   71M  2.0G   4% /data5
[root@localhost Desktop]# vim /etc/fstab
[root@localhost Desktop]# ls /data\*
/data15:
lost+found

/data5:
lost+found
[root@localhost Desktop]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        18G  4.0G   13G  24% /
tmpfs           491M  372K  491M   1% /dev/shm
/dev/sda1       291M   34M  242M  13% /boot
/dev/sdb5       2.0G   68M  1.9G   4% /data15
/dev/sdb1       2.0G   68M  1.9G   4% /data5

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

同上,又创建了一个逻辑分区

[root@localhost Desktop]# 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): 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


### 最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

### 资料预览

给大家整理的视频资料:

![](https://img-blog.csdnimg.cn/img_convert/2dcba36fac238c2aa42867d56755f6b3.png)

给大家整理的电子书资料:

  

![](https://img-blog.csdnimg.cn/img_convert/fd096b080f8ed03c7e86eb1de37696cf.png)



**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618635766)**


**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

ete a partition
 l list known partition types
 m print this menu
 n add a new partition


### 最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

### 资料预览

给大家整理的视频资料:

[外链图片转存中...(img-bNKmmAbJ-1715815142631)]

给大家整理的电子书资料:

  

[外链图片转存中...(img-8LnbgLK0-1715815142632)]



**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618635766)**


**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值