磁盘的分区、格式化、与挂载

摘要:
1.磁盘分区:fdisk设备名称-l:输出以下设备的所有分区内容。

1、磁盘分区:fdisk 【-l】 设备名称

-l:输出后面接的设备所有的分区内容。

1 [root@iZ255cppmtxZ ~]# fdisk -l
2 
3 Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080sectors
4 Units = sectors of 1 * 512 = 512bytes
5 Sector size (logical/physical): 512 bytes / 512bytes
6 I/O size (minimum/optimal): 512 bytes / 512bytes
7 Disk label type: dos
8 Disk identifier: 0x0009e68a
9 
10 Device Boot      Start         End      Blocks   Id  System
11 /dev/xvda1   *        2048    83884031    41940992   83Linux
12 
13 Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560sectors
14 Units = sectors of 1 * 512 = 512bytes
15 Sector size (logical/physical): 512 bytes / 512bytes
16 I/O size (minimum/optimal): 512 bytes / 512 bytes

从查询结果中可以看出多了一个/dev/xvdb

用fdisk分区

1 [root@iZ255cppmtxZ ~]# fdisk /dev/xvdb
2 Welcome to fdisk (util-linux 2.23.2).
3 
4 Changes will remain in memory only, until you decide to writethem.
5 Be careful before using the writecommand.
6 
7 Device does not contain a recognized partition table
8 Building a new DOS disklabel with disk identifier 0x25a2caf5.
9 
10 Command (m for help): 

输入“m”

1 Command (m forhelp): m
2 Command action
3 a   toggle a bootable flag
4 b   edit bsd disklabel
5 c   toggle the dos compatibility flag
6 d   delete a partition                            <==删除一个分区
7 g   create a new empty GPT partition table
8 G   create an IRIX (SGI) partition table
9 l   list known partition types
10 m   print this menu
11 n   add a new partition                           <==新建一个分区
12 o   create a new empty DOS partition table
13 p   print the partition table                     <==在屏幕上显示分区表
14 q   quit without saving changes                   <==不存储,离开fdisk程序
15 s   create a new empty Sun disklabel
16    t   change a partition's system id
17    u   change display/entry units
18 v   verify the partition table
19    w   writetable to disk and exit                  <==将刚才的操作写入分区表
20 x   extra functionality (experts only)
21 
22 Command (m for help): 

接下来正式分区

1 Command (m forhelp): n
2 Partition type:
3    p   primary (0 primary, 0 extended, 4 free)
4 e   extended
5 Select (default p): p
6 Partition number (1-4, default 1): 1
7 First sector (2048-62914559, default 2048): 
8 Using default value 2048
9 Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): 
10 Using default value 62914559
11 Partition 1 of type Linux and of size 30GiB is set
12 
13 Command (m for help): w
14 The partition table has been altered!
15 
16 Calling ioctl() to re-read partition table.
17 Syncing disks.

有fdisk -l查看下现在分区情况

1 [root@iZ255cppmtxZ ~]# fdisk -l
2 
3 Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080sectors
4 Units = sectors of 1 * 512 = 512bytes
5 Sector size (logical/physical): 512 bytes / 512bytes
6 I/O size (minimum/optimal): 512 bytes / 512bytes
7 Disk label type: dos
8 Disk identifier: 0x0009e68a
9 
10 Device Boot      Start         End      Blocks   Id  System
11 /dev/xvda1   *        2048    83884031    41940992   83Linux
12 
13 Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560sectors
14 Units = sectors of 1 * 512 = 512bytes
15 Sector size (logical/physical): 512 bytes / 512bytes
16 I/O size (minimum/optimal): 512 bytes / 512bytes
17 Disk label type: dos
18 Disk identifier: 0x25a2caf5
19 
20 Device Boot      Start         End      Blocks   Id  System
21 /dev/xvdb1            2048    62914559    31456256   83  Linux

可以从上图看出多了一个/dev/xvdb1,之所以是xvdb1是因为我们前面指定了1,要是指定2就应该为xvdb2

如果创建完以后,/proc/partitions查看不到对应的分区,使用parprobe命令刷新一下就可以了。

2、用mkfs命令格式化分区/dev/xvdb1

1 [root@iZ255cppmtxZ ~]# mkfs -t ext4 /dev/xvdb1 
2 mke2fs 1.42.9 (28-Dec-2013)
3 Filesystem label=
4 OS type: Linux
5 Block size=4096 (log=2)
6 Fragment size=4096 (log=2)
7 Stride=0 blocks, Stripe width=0blocks
8 1966080 inodes, 7864064blocks
9 393203 blocks (5.00%) reserved forthe super user
10 First data block=0
11 Maximum filesystem blocks=4294967296
12 240 block groups
13 32768 blocks per group, 32768fragments per group
14 8192inodes per group
15 Superblock backups stored on blocks: 
16     32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
17     4096000
18 
19 Allocating group tables: done                            
20 Writing inode tables: done                            
21 Creating journal (32768 blocks): done
22 Writing superblocks and filesystem accounting information:        
23 done

3、创建挂载目录并挂载

1 [root@iZ255cppmtxZ /]# mkdir /data
2 [root@iZ255cppmtxZ /]# mount /dev/xvdb1 /data/
3 [root@iZ255cppmtxZ /]# df -h
4 Filesystem      Size  Used Avail Use%Mounted on
5 /dev/xvda1       40G  1.5G   36G   5% /
6 devtmpfs        489M     0  489M   0% /dev
7 tmpfs           497M     0  497M   0% /dev/shm
8 tmpfs           497M  6.5M  490M   2% /run
9 tmpfs           497M     0  497M   0% /sys/fs/cgroup
10 /dev/xvdb1       30G   44M   28G   1% /data

4、设置开机自动挂载。

1 [root@iZ255cppmtxZ /]# vi /etc/fstab 
2 
3 
4 #
5 # /etc/fstab
6 # Created by anaconda on Fri Nov 21 18:16:53 2014
7 #
8 # Accessible filesystems, by reference, are maintained under '/dev/disk'
9 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
10 #
11 UUID=6634633e-001d-43ba-8fab-202f1df93339 / ext4 defaults,barrier=0 1 1
12 /dev/xvdb1                 /data            ext4           defaults 0 0

注:自动挂载6个字段意义为

第一列:磁盘设备文件名或设备的Label。

第二列:挂载点。

第三列:磁盘分区的文件系统。

第四列:文件系统参数。基本上,默认情况使用defaults设置即可。。

第五列:能否被dump设备命令作用。0代表不做dump备份,1代表每天进行dump的操作,2也代表其他不定日期的dump备份操作,通常这个数值不是0就是1.

第六列:是否已fsck检验扇区。0是不要检验,1表示最早检验(一般只有根目录会设置为1),2也是要检验,不过1会比较早被检验。一般来说根目录设置为1其他的要检验的文件系统都设置为2就好了。

/etc/fstab是开机时的配置文件,不过,实际文件系统的挂载是记录到/etc/mtab 与/proc/mounts这两个文件当中的。每次我们在改动文件系统的挂载时,也会同时改动这两个文件。但是万一发生你在/etc/fstab中输入的数据有误,导致无法顺利开机成功,而进入单用户维护模式当中,那时候的/可是readonly的状态,当然你就无法修改/etc/fstab,也无法更新/etc/mtab。那怎么办?没关系,可以利用下面这一招:

1 [root@iZ255cppmtxZ local]# mount -n -o remount,rw /

免责声明:文章转载自《磁盘的分区、格式化、与挂载》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇实现自定义的小程序底部tabbarMongoDb问题集下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Git建立独立分支

前言 在码云建立git项目后默认分支是master, 这里如果直接在码云新建分支, 会指定默认分支; 所以通过git 命令 git checkout --orphan 新分支名 创建独立分支 创建 创建独立分支dev git checkout --orphan dev xiaom@DESKTOP-739JJPH MINGW32 /d/Java/Git/g...

VUE内使用RSA加解密

说明:为防止私钥泄漏,由服务端生成两对密钥,分别是(前端公钥+私钥,后端公钥加私钥),采用加解密模式为:前端使用后台公钥加密,使用前端私钥解密;后端使用前端公钥加密,使用后端私钥解密。前后端统一使用公钥加密,私钥解密 一、现在vue项目中安装依赖包jsencrypt   npm install jsencrypt --save-dev 二、在项目中新建js...

使用dd命令备份Linux分区

为了备份分区,开始使用的是Remastersys,但最终生成的iso文件仅有几十K,应该是软件bug,且此软件不再更新,后尝试使用Linux Respin,但github一直连接不上。 其实可以尝试使用dd命令,使用的命令如下: sudo dd if=/dev/sda1 of=/media/gavin/d/file/deepin.img if=后面接的是原...

BLDC开发笔记4.转速的计算

以下结合自己的理解,如有错误请帮忙及时指正。 转速公式 转速的计算我现在是通过一定时间内,霍尔信号的边沿数量来计算的。这里每隔50ms在滴答定时器中断服务函数里面计算一次。霍尔信号每变化一次,就产生一次霍尔触发中断。因为我的电机是2对极,所以在一圈内有12个霍尔状态,即电机转动一圈会触发12次中断。假设在50ms内,霍尔触发了 n 次中断,我们可以得到转速...

umount:将文件设备卸载

[root@centos57 ~]# umount /dev/hda1 用设备文件名来卸载          [root@centos57 ~]# umount /aixi                     用挂载点来卸载          umount: /aixi: device is busy                      如果提示...

esxi中CentOS7不停机加磁盘并扩容现有分区

linux的磁盘容量扩容,基于lvm,即逻辑卷管理。具体是什么请百度,这里不细述。 此次操作的目的是为了给已存在的linux主机的其中一个数据分区扩容。 环境:esxi6.5  虚拟机系统centos7 简单来说,扩容这件事分三步 一、从esxi中为此虚拟机增加硬盘,并让centos系统识别出此硬盘 二、将此硬盘进行分区、格式化(重点是这里的分区不是类似...