linux add new disks and partitions

Hard disk partition device name

In linux system, it is to access the device by device name, device name stored in the "/ dev" directory.
Define the rules of device names as follows:

  • The first system is called an IDE hard disk interface "/ dev / hda"
  • System second IDE hard disk interface called "/ dev / hdb"
  • System of a SCSI (SATA, SAS) hard disk interface called "/ dev / sda"
  • A second system block SCSI (SATA, SAS) hard disk interface called "/ dev / sdb"

Each partition naming names, use the disk plus the corresponding figures, such as:

  • A first system of a hard disk partition IDE interface called "/ dev / hda1"
  • System IDE hard disk interface of a second partition called "/ dev / hda2"
  • System of a SCSI (SATA, SAS) interface referred to as the first partition of the hard drive "/ dev / sda1"
  • System of a SCSI (SATA, SAS) hard disk interface is called a second partition "/ dev / sda2"
  • System of a SCSI (SATA, SAS) interface, a first logical disk partition called "/ dev / sda5"

Added Disk

Here Insert Picture Description
The next step has been
Here Insert Picture Description
to reboot the system
Here Insert Picture Description

Partition

[root@root ~]# fdisk -l /dev/sdb 

磁盘 /dev/sdb:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@root ~]# fdisk /dev/sdb    
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xc87a2b68 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):
  • After the control input m
parameter Explanation
d Delete a partition
l Show known file system types
m Displays help information
n Create a new partition
p Displays the current disk's partition table information
q Exit without saving
t Modify the partition type
w Save changes to partition table and exit

Partitioning

  • Create partition primary
命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-4194303,默认为 2048):          / /这里直接回车默认即可
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-4194303,默认为 4194303):+100M    //设置分区大小为100M
分区 1 已设置为 Linux 类型,大小设为 100 MiB      

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xc87a2b68

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
分区号 (2-4,默认 2):2
起始 扇区 (206848-4194303,默认为 206848):
将使用默认值 206848
Last 扇区, +扇区 or +size{K,M,G} (206848-4194303,默认为 4194303):+100M
分区 2 已设置为 Linux 类型,大小设为 100 MiB
  • Create an extended partition
命令(输入 m 获取帮助):n  
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e    //表示穿件扩展分区
分区号 (3,4,默认 3):3
起始 扇区 (411648-4194303,默认为 411648):    //同样适用默认即可
将使用默认值 411648
Last 扇区, +扇区 or +size{K,M,G} (411648-4194303,默认为 4194303):  //将磁盘剩下大小都给扩展分区
将使用默认值 4194303
分区 3 已设置为 Extended 类型,大小设为 1.8 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xc87a2b68

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      411647      102400   83  Linux
/dev/sdb3          411648     4194303     1891328    5  Extended
  • Create logical partitions
命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l     //创建逻辑分区
添加逻辑分区 5
起始 扇区 (413696-4194303,默认为 413696):    //默认即可
将使用默认值 413696
Last 扇区, +扇区 or +size{K,M,G} (413696-4194303,默认为 4194303):+50M   //给50M大小
分区 5 已设置为 Linux 类型,大小设为 50 MiB

命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
添加逻辑分区 6
起始 扇区 (518144-4194303,默认为 518144):
将使用默认值 518144
Last 扇区, +扇区 or +size{K,M,G} (518144-4194303,默认为 4194303):
将使用默认值 4194303
分区 6 已设置为 Linux 类型,大小设为 1.8 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xc87a2b68

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      411647      102400   83  Linux             //主分区
/dev/sdb3          411648     4194303     1891328    5  Extended     //扩展分区
/dev/sdb5          413696      516095       51200   83  Linux             //逻辑分区
/dev/sdb6          518144     4194303     1838080   83  Linux         // 逻辑分区
  • Storage
命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@root ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 5月  22 03:03 /dev/sdb
brw-rw---- 1 root disk 8, 17 5月  22 03:03 /dev/sdb1
brw-rw---- 1 root disk 8, 18 5月  22 03:03 /dev/sdb2
brw-rw---- 1 root disk 8, 19 5月  22 03:03 /dev/sdb3
brw-rw---- 1 root disk 8, 21 5月  22 03:03 /dev/sdb5
brw-rw---- 1 root disk 8, 22 5月  22 03:03 /dev/sdb6
  • Tell the system / dev / sdb partition table has changed
[root@root ~]# partprobe /dev/sdb
  • format
[root@root ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

Here need to use that partition, format the

  • Close the disk check function
[root@root ~]# tune2fs -c 0 -i 0 /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
  • Mounting
[root@root ~]# mount /dev/sdb1 /mnt/
[root@root ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   18G  5.7G   12G   33% /
devtmpfs                 903M     0  903M    0% /dev
/dev/sda1                497M  125M  373M   26% /boot
tmpfs                    183M     0  183M    0% /run/user/0
/dev/sdb1                 93M  1.6M   85M    2% /mnt

Boot automatically mount

  • method one
[root@root ~]# echo "mount /dev/sdb1 /mnt/" >> /etc/rc.local

This method is suitable for Network File System: NFS, MFS, GFS

  • Method Two
[root@root ~]# echo "/dev/sdb1     /mnt/    ext4    defaults  0 0" >> /etc/fstab 

This method is suitable for the local disk

Guess you like

Origin blog.csdn.net/qq_33235529/article/details/90413651