Linux磁盘分区(一):添加

***********************************************声明************************************************

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/huangyanlong)。

表述有错误之处,请您留言或邮件([email protected])指明,不胜感激。

*****************************************************************************************************

*****************************************************************************************************

Linux硬盘分区(一):添加

*****************************************************************************************************

*************************

过程简述

*************************

--添加磁盘
# fdisk -l                --查看磁盘情况
# fdisk /dev/sdb          --为/dev/sdb设备分区
n                         --添加分区
p/e			  --主分区/逻辑分区
w			  --保存退出
# mkdir /data		  --创建挂载目录
# mkfs.ext3 /dev/sdb      --格式化磁盘为ext3文件系统
# fdisk -l                --再次查看磁盘情况
# mount /dev/sdb /data    --挂载磁盘到创建的挂载目录下
# vi /etc/fstab           --修改启动自动挂载项
/dev/sdb    /data      ext3    defaults     0 0

*************************

说明

*************************

1、以上操作为精炼总结,若如可以看懂,下面内容无需浏览;

2、以下简单列举两例,细化操作过程。

*****************************************************************************************************

举例1:添加1块90G磁盘,将其分为1个分区

*****************************************************************************************************

*************************

查看磁盘情况

*************************

[[email protected] /]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      514048+  83  Linux
/dev/sda2              65         586     4192965   82  Linux swap / Solaris
/dev/sda3             587       15665   121122067+  83  Linux

Disk /dev/sdb: 96.6 GB, 96636764160 bytes
255 heads, 63 sectors/track, 11748 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

*************************

磁盘分区

*************************

[[email protected] /]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 11748.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
--输入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)

Command (m for help): n
--添加新分区
Command action
   e   extended
   p   primary partition (1-4)
p
--输入p添加主分区
Partition number (1-4): 1
--填写分区号
First cylinder (1-11748, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-11748, default 11748):
Using default value 11748

Command (m for help): p
--打印分区列表
Disk /dev/sdb: 96.6 GB, 96636764160 bytes
255 heads, 63 sectors/track, 11748 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       11748    94365778+  83  Linux

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

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

*************************

创建挂载目录

*************************

[[email protected] /]# mkdir /data

*************************

格式化磁盘

*************************

[[email protected] /]# mkfs.ext3 /dev/sdb
--格式化sdb1,格式成ext3格式文件系统
mke2fs 1.39 (29-May-2006)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
11796480 inodes, 23592960 blocks
1179648 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
720 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000

Writing inode tables: done
Creating journal (32768 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.
[[email protected] /]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      514048+  83  Linux
/dev/sda2              65         586     4192965   82  Linux swap / Solaris
/dev/sda3             587       15665   121122067+  83  Linux

Disk /dev/sdb: 96.6 GB, 96636764160 bytes
255 heads, 63 sectors/track, 11748 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

*************************

挂载磁盘到指定路径下

*************************

[[email protected] /]# mount /dev/sdb /data
[[email protected] /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             112G  4.3G  102G   5% /
/dev/sda1             487M   17M  445M   4% /boot
tmpfs                1006M     0 1006M   0% /dev/shm
/dev/sdb               89G  184M   84G   1% /data

*************************

修改启动磁盘自动挂载

*************************

[[email protected] ~]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
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
LABEL=SWAP-sda2         swap                    swap    defaults        0 0
/dev/sdb                /data                   ext3    defaults        0 0
~
~
"/etc/fstab" 8L, 608C written

--格式说明
/dev/sdb1       /u01          ext3       defaults           0              0
要挂载的对象    挂载的目录    系统类型   文件系统访问权限   开机后是否检测 出问题后是否转储

*****************************************************************************************************

举例2:

1、添加1块10G磁盘;

2、将其分为六个分区;

3、三个主分区分别为2G;

4、剩余空间分为扩展分区,具体分为两个逻辑分区分别为1G,剩余空间单独分为一个逻辑分区。

*****************************************************************************************************

*************************

查看磁盘情况

*************************

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.7G  5.4G  3.9G  59% /
/dev/sda3              35G   17G   17G  50% /home
tmpfs                1006M     0 1006M   0% /dev/shm
[[email protected] ~]# fdisk -l

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1305    10482381   83  Linux
/dev/sda2            1306        1827     4192965   82  Linux swap / Solaris
/dev/sda3            1828        6527    37752750   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

*************************

为/dev/sdb设备分区

*************************

[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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)

*************************

创建第一个主分区:大小2G

*************************

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +2048M

*************************

创建第二个主分区:大小2G

*************************

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +2048M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (251-1305, default 251):
Using default value 251
Last cylinder or +size or +sizeM or +sizeK (251-1305, default 1305): +2048M

*************************

创建第三个主分区:大小2G

*************************

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (501-1305, default 501):
Using default value 501
Last cylinder or +size or +sizeM or +sizeK (501-1305, default 1305): +2048M

*************************

先打印分区列表看一下

*************************

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         250     2008093+  83  Linux
/dev/sdb2             251         500     2008125   83  Linux
/dev/sdb3             501         750     2008125   83  Linux

*************************

创建扩展分区

*************************

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (751-1305, default 751):
Using default value 751
Last cylinder or +size or +sizeM or +sizeK (751-1305, default 1305):
Using default value 1305

*************************

创建第一个逻辑分区:大小1G

*************************

Command (m for help): n
First cylinder (751-1305, default 751):
Using default value 751
Last cylinder or +size or +sizeM or +sizeK (751-1305, default 1305): +1024M

*************************

创建第二个逻辑分区:大小1G

*************************

Command (m for help): n
First cylinder (876-1305, default 876):
Using default value 876
Last cylinder or +size or +sizeM or +sizeK (876-1305, default 1305): +1024M

*************************

剩余容量创建最后一个逻辑分区

*************************

Command (m for help): n
First cylinder (1001-1305, default 1001):
Using default value 1001
Last cylinder or +size or +sizeM or +sizeK (1001-1305, default 1305):
Using default value 1305

*************************

打印分区列表

*************************

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         250     2008093+  83  Linux
/dev/sdb2             251         500     2008125   83  Linux
/dev/sdb3             501         750     2008125   83  Linux
/dev/sdb4             751        1305     4458037+   5  Extended
/dev/sdb5             751         875     1004031   83  Linux
/dev/sdb6             876        1000     1004031   83  Linux
/dev/sdb7            1001        1305     2449881   83  Linux

*************************

保存退出

*************************

Command (m for help): w
The partition table has been altered!

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

*************************

查看磁盘划分

*************************

[[email protected] ~]# fdisk -l

Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1305    10482381   83  Linux
/dev/sda2            1306        1827     4192965   82  Linux swap / Solaris
/dev/sda3            1828        6527    37752750   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         250     2008093+  83  Linux
/dev/sdb2             251         500     2008125   83  Linux
/dev/sdb3             501         750     2008125   83  Linux
/dev/sdb4             751        1305     4458037+   5  Extended
/dev/sdb5             751         875     1004031   83  Linux
/dev/sdb6             876        1000     1004031   83  Linux
/dev/sdb7            1001        1305     2449881   83  Linux
--由此可以看出,sdb1、sdb2、sdb3为主分区,sdb5、sdb6、sdb7为逻辑分区

*************************

举例:将sdb1格式化为ext3文件系统

*************************

[[email protected] ~]# cd /
[[email protected] /]# mkdir data1
[[email protected] /]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
251392 inodes, 502023 blocks
25101 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=515899392
16 block groups
32768 blocks per group, 32768 fragments per group
15712 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 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

*************************

举例:为sdb1设置开机自动挂载

*************************

[[email protected] /]# vi /etc/fstab
--设置开机自动挂载
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/home             /home                   ext3    defaults        1 2
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
LABEL=SWAP-sda2         swap                    swap    defaults        0 0
/dev/sdb1               /data1                  ext3    defaults        0 0
~
~
~
"/etc/fstab" 8L, 608C written
[[email protected] /]# mount /dev/sdb1 /data1
[[email protected] /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.7G  5.4G  3.9G  59% /
/dev/sda3              35G   17G   17G  50% /home
tmpfs                1006M     0 1006M   0% /dev/shm
/dev/sdb1             1.9G   35M  1.8G   2% /data1

***********************************************声明************************************************

原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/huangyanlong)。

表述有错误之处,请您留言或邮件([email protected])指明,不胜感激。

提醒:点击目录,更有助于您的查看。

*****************************************************************************************************

时间: 2024-10-30 09:03:58

Linux磁盘分区(一):添加的相关文章

linux 磁盘分区 fdisk

linux磁盘分区:fdisk(小于2T的分区工具) [[email protected] ~]# fdisk -l            #####查看磁盘空间 Disk /dev/sda: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 5

linux磁盘分区格式化、挂载,文件系统

一.硬盘分区&格式化&挂载 RHEL5强制刷新分区表 partprobe /dev/sdb RHEL6强制刷新分区表 partx -a /dev/sdb 1.创建文件系统:挂载分区&格式化 mkfs.TAB 查看当前系统可创建分区类型 [[email protected] ~]# mkfs. mkfs.cramfs  mkfs.ext3    mkfs.vfat    mkfs.ext2    mkfs.msdos 格式化第一个分区   mkfs.ext3 /dev/sdb1 创建

Linux fdisk命令参数及用法详解---Linux磁盘分区管理命令fdisk

fdisk 命令 linux磁盘分区管理 用途:观察硬盘之实体使用情形与分割硬盘用. 使用方法: 一.在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形. 二.在 console 上输入 fdisk /dev/sda,可进入分割硬盘模式. 1. 输入 m 显示所有命令列示. 2. 输入 p 显示硬盘分割情形. 3. 输入 a 设定硬盘启动区. 4. 输入 n 设定新的硬盘分割区. 4.1. 输入 e 硬盘为[延伸]分割区(extend). 4.2. 输入 p

Linux磁盘分区与LVM详解

内容大纲: 一.磁盘分区是怎样表示的? 二.Linux磁盘分区与文件系统类命令 三.LinuxLVM逻辑卷管理 四.磁盘分区相关命令操作演示 五.磁盘分区及LVM操作演示 一.磁盘分区是怎样表示的? IDE磁盘的设备文件采用/dev/hdx 来命名,分区则采用/dev/hdxy来命名,其中想表示磁盘(a是第一块磁盘,b是第二块磁盘,以此类推),与代表分区的号码(由1开始,1,2,3,以此类推) SCSI设备和分区采用/dev/sdx和/dev/sdxy来命名(x和y的命名规则与IED磁盘命名规则

大数据学习之_01_Linux学习_02_组管理和权限管理+定时任务调度+linux磁盘分区、挂载+linux的网络配置+进程管理(重点)+软件包管理+大厂面试题+感悟分享+资料附录

10 组管理和权限管理10.1 Linux组的基本介绍10.2 文件/目录的所有者10.3 文件/目录的所在组10.4 权限的基本介绍10.5 rwx权限详解10.6 修改权限指令-chmod10.7 修改文件所有者-chown10.8 修改文件所在组-chgrp10.9 最佳实践-警察和土匪游戏11 定时任务调度11.1 crond任务调度12 linux磁盘分区.挂载12.1 分区的基本知识12.2 Linux分区12.3 挂载的经典案例12.4 查询系统整体磁盘使用情况12.5 查询指定目

shell 脚本实战笔记(4)--linux磁盘分区重新挂载

背景: Hadoop的HDFS文件系统的挂载, 默认指定的文件目录是/mnt/disk{N}. 当运维人员, 不小心把磁盘挂载于其他目录, 比如/mnt/data, /mnt/disk01, /mnt/diska时, HDFS会选择根分区, 当往HDFS里灌数据时, 导致的结果往往是根分区被快速的消耗尽, 而其他分区未见使用. 在CDH版本中, HDFS的配置如下所示: dfs.datanode.data.dir => /mnt/disk{N}/dfs/dn dfs.datanode.data.

linux磁盘分区知识

linux磁盘分区知识 目录 一.         硬盘存储逻辑结构.... 1 1.硬盘存储逻辑结构图:... 1 2.16字节分区表的内容.... 2 3.主引导记录MBR .... 2 二.磁盘分区.... 2 1.磁盘分区的重点.... 2 2.补:(企业面试题:一台服务器6块600G的磁盘,raid5后,总大小3T,此时无法装系统?请问为什么?     3 3.主分区Primary. 4 4.扩展分区Extended.. 4 5.逻辑分区logical 6.磁盘分区注意事项要点...

张明贵-Linux磁盘分区方案

[听课保持最大化的输入,分享交流保持最大化的输出] 服务器选择软RAID还是硬RAID? 应该选择硬RAID,软RAID多了一层软件,性能受到了一定程度上的限制 LVM卷,可以对磁盘空间进行动态调整 但是不建议使用这种方式,多了一层软件,应该提前规划好空间 硬盘使用前 要分区,格式化(创建文件系统) 硬盘分区 主分区 扩展分区 逻辑分区 主分区+逻辑分区 <= 4 可以不要扩展分区 直接将磁盘分为4个主分区 三个主分区 一个扩展分区(扩展分区里再划分逻辑分区,就是扩展分区包含逻辑分区,且逻辑分区

linux 磁盘分区及常用linux命令

磁盘分区实际就是改变DPT-磁盘分区表(64Bytes,每个分区表占16字节)的内容. linux fdisk 交互式分区测试(注意主分区不可超过4个-磁盘要求,扩展分区只有一个-): 1.给虚拟机添加一个虚拟磁盘,假设为scsi磁盘,其设备为  /dev/sdb 2.执行命令  : fdisk /dev/sdb  进行分区 按提示使用相关命令进行分区. n  - 创建新分区 q - 退出不保存 w - 将分区信息写入磁盘分区表 3.通知操作系统,磁盘分区表发生变动 命令 : partprobe