Linux新增磁盘分区

磁盘的分区

       主分区与扩展分区最多可以有4个(分区表64字节,每分区占16字节);

       扩展分区最多只能有一个;

       逻辑分区是由扩展分区持续分出来的分区;

       能够被格式化后作为数据访问的分区为主要分区与逻辑分区,扩展分区无法格式化;

       逻辑分区的数量以操作系统而不同,在Linux系统中,IDE硬盘最多有59个逻辑分区(5-63),SATA硬盘则有11个逻辑分区(5-15);

各接口的磁盘在Linux中的文件名分别为

       /dev/sd[a-p][1-15]:为SCSI,SATA,USB,Flash等接口的磁盘文件名;

      /dev/hd[a-d][1-63]:为IDE接口的磁盘文件名;

文件系统分类

       Windows :NTFSFAT32

       Linux:ext2、ext3ext4xfsreiserfsnfsiso9660jfsbrtfs


 小结:通过以上内容,我们简单了解了磁盘的组成、分区、接口的磁盘命名及文件系统的分类。下面我们来具体看下磁盘分区、格式化及磁盘挂载所使用到的命令。


[root@ti0203a400-1401 /]# fdisk -l              //查看磁盘


Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000152be


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        5125    40960000   83  Linux

/dev/sda3            5125        5380     2048000   82  Linux swap / Solaris


[root@ti0203a400-1401 /]# fdisk /dev/sda                    //开始创建磁盘分区


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): p                   //显示分区表


Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000152be


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        5125    40960000   83  Linux

/dev/sda3            5125        5380     2048000   82  Linux swap / Solaris


Command (m for help): n                        //新建一个分区

Command action

   e   extended

   p   primary partition (1-4)

p                                                        //创建主分区

Selected partition 4                         //分区号

First cylinder (5380-6527, default 5380):                //(开始柱面-可默认)                 

Using default value 5380

Last cylinder, +cylinders or +size{K,M,G} (5380-6527, default 6527): +5G                   //磁盘大小


Command (m for help): p                       //显示分区表


Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000152be


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        5125    40960000   83  Linux

/dev/sda3            5125        5380     2048000   82  Linux swap / Solaris

/dev/sda4            5380        6033     5246248+  83  Linux


Command (m for help): w                       //保存退出

The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@ti0203a400-1401 /]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2        39G  3.3G   34G   9% /

tmpfs           491M   92K  491M   1% /dev/shm

/dev/sda1       190M   55M  126M  31% /boot

[root@ti0203a400-1401 /]# cat /proc/partitions            //查看分区表是否加载

major minor  #blocks  name


   8        0   52428800 sda

   8        1     204800 sda1

   8        2   40960000 sda2

   8        3    2048000 sda3

   8        4    5246248 sda4                                             //如果没有加载就执行下面指令重新读取加载

[root@ti0203a400-1401 /]# partx -a /dev/sda          // RHEL6让内核重新读取硬盘分区表:

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

BLKPG: Device or resource busy

error adding partition 3

BLKPG: Device or resource busy

error adding partition 4

[root@ti0203a400-1401 /]# mkfs -t ext4 /dev/sda4              //格式化新建磁盘

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

328000 inodes, 1311562 blocks

65578 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1346371584

41 block groups

32768 blocks per group, 32768 fragments per group

8000 inodes per group

Superblock backups stored on blocks: 

    32768, 98304, 163840, 229376, 294912, 819200, 884736


Writing inode tables: done                            

Creating journal (32768 blocks): 

done

Writing superblocks and filesystem accounting information: 

done


This filesystem will be automatically checked every 20 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@ti0203a400-1401 /]# 

[root@ti0203a400-1401 /]# mkdir -p /testdir                                             //创建磁盘挂载目录

[root@ti0203a400-1401 /]# mount -t ext4  /dev/sda4 /testdir/                 //挂载磁盘

[root@ti0203a400-1401 /]# df -h                                                               //查看磁盘是否识别并挂载

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2        39G  3.3G   34G   9% /

tmpfs           491M   92K  491M   1% /dev/shm

/dev/sda1       190M   55M  126M  31% /boot

/dev/sda4       4.8G   11M  4.6G   1% /testdir

[root@ti0203a400-1401 /]# ls /testdir/

lost+found

[root@ti0203a400-1401 /]# 






转载:

http://miclesvic.blog.51cto.com/2152735/1344202











原创文章,作者:jxmsn,如若转载,请注明出处:http://www.178linux.com/16100

(0)
jxmsnjxmsn
上一篇 2016-05-29 15:23
下一篇 2016-05-29 15:23

相关推荐

  • N22-第五周作业-冥界之王

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;    [root@CentOS6 ~]# cat /boot/grub/grub.conf | grep -E  "^[[:space:]]{1,}"…

    Linux干货 2016-09-19
  • Linux磁盘分区创建及bash 简单应用

    1、创建一个10G分区,并格式为ext4文件系统; (1)要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl; (2)挂载至/data/mydata目录,要求挂载是禁止程序自动运行,并且更新文件的访问时间戳; [root@danry ~]# fdisk /dev/sdb Welcome to fdisk (util…

    2017-09-11
  • Linux基础知识(五)

    1、显示当前系统上root、fedora或user1用户的默认shell [root@server01 ~]# cat /etc/passwd | grep –color=auto -E "^root|fedora|user1" | cut -d : -f 1,7 2、找出/etc/rc.d/init.d/functions文…

    Linux干货 2016-10-25
  • 作业——拷贝命令及其链接库

    1),提示用户输入一个可执行命令的名称 2),获取此命令所依赖额所有库文件列表 3),复制命令至某目标目录(/mnt/sysroot,即把此目录当做根)下的对的路径中 bash,/bin/bash ===> /mnt/sysroot/bin/bash useradd, /usr/sbin/useradd ===> /mnt/sysroot/usr…

    Linux干货 2017-02-04
  • tar ,cpio打包解压. shell脚本for,while,until循环. rpm包管理,循环的特殊用法. select循环菜单,函数function,rpm包查询,yum

    tar  tar -cf 路径+文件名字后续.tar  +路径 创建归档压缩 tar cf /testdir/etc.tar /etc/ tar cvf 可以查看解压过程 tar tvf 预览作用 tar xvf 解压文件  tar zcvf /testdir/etc2.tar.gz /etc/ 解压再压缩到指定路径,文件格式 …

    Linux干货 2016-08-21
  • SSH——安全的通信

    SSH ·ssh:secure shell, protocol, 22/tcp,  安全的远程登录 ·OpenSSH:ssh协议的开源实现 ·dropbear:另一个开源实现 ·SSH协议版本:          v1:基于CRC-32做MAC,不安全;man-in-m…

    Linux干货 2016-09-25