欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

详解linux添加硬盘分区挂载教程

程序员文章站 2023-10-13 10:14:47
基本步骤:分区——格式化——挂载——写入文件 1、首先用fdisk -l命令查看添加的硬盘名称,可以看到sdb为新增的硬盘 [root@oracle ~]# f...

基本步骤:分区——格式化——挂载——写入文件

1、首先用fdisk -l命令查看添加的硬盘名称,可以看到sdb为新增的硬盘

[root@oracle ~]# fdisk -l

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: 0x00000000

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: 0x0006b59c

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 

2、进行分区,输入m查看提示

[root@oracle ~]# fdisk /dev/sdb 

device contains neither a valid dos partition table, nor sun, sgi or osf disklabel

building a new dos disklabel with disk identifier 0x09f38795.

changes will remain in memory only, until you decide to write them.

after that, of course, the previous content won't be recoverable.

 

warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

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

  o  create a new empty dos partition table

  p  print the partition table

  q  quit without saving changes

  s  create a new empty sun disklabel

  t  change a partition's system id

  u  change display/entry units

  v  verify the partition table

  w  write table to disk and exit

  x  extra functionality (experts only) 

分析:主要参数的解析

1. 输入 m 显示所有命令列示。

2. 输入 p 显示硬盘分割情形,打印分区表。

3. 输入 a 设定硬盘启动区。

4. 输入 n 创建新的硬盘分割区。

  4.1. 输入 e 硬盘为[延伸]分割区(extend)。

  4.2. 输入 p 硬盘为[主要]分割区(primary)。

5. 输入 t 改变硬盘分割区属性。          

  1. t:分区系统id号
  2. l:82:linux swap
  3. 83:linux
  4. 86:ntfs window分区

6. 输入 d 删除硬盘分割区属性。

7. 输入 q 结束不存入硬盘分割区属性。

8. 输入 w 结束并写入硬盘分割区属性

3、输入n创建新的硬盘分区——输入p创建主分区——输入1设置一个分区——回车——回车(默认全部空间)

command (m for help): n

command action

  e  extended                                  ···扩展分区

  p  primary partition (1-4)                          ···主分区

p

partition number (1-4): 1

first cylinder (1-2610, default 1): 

using default value 1

last cylinder, +cylinders or +size{k,m,g} (1-2610, default 2610): 

using default value 2610 

4、输入p查看分区情况——输入w保存退出(一定要w保存不然无效)

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: 0x09f38795

 

  device boot   start     end   blocks  id system

/dev/sdb1        1    2610  20964793+ 83 linux

 

command (m for help): w

the partition table has been altered!

 

calling ioctl() to re-read partition table.

syncing disks. 

5、mkfs命令格式化磁盘

[root@oracle ~]# mkfs.ext4 /dev/sdb

mkfs.ext4: invalid fragment size - /dev/sdb 

6、mount命令挂载分区

[root@oracle ~]# mount /dev/sdb /oracle/

you have new mail in /var/spool/mail/root

[root@oracle ~]# df -th

filesystem   type  size used avail use% mounted on

/dev/sda2   ext4  19g  11g 7.3g 60% /

tmpfs     tmpfs 2.1g  74k 2.1g  1% /dev/shm

/dev/sda1   ext4  297m  29m 253m 11% /boot

/dev/sdb    ext4  22g  47m  20g  1% /oracle 

7、添加到/etc/fstab文件下保存退出否则重启后硬盘消失

/dev/sdb    /oracle     ext4  defaults,noatime    0 0 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。