您的位置:首页 > 其它

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

2016-03-25 17:57 411 查看
1、磁盘分区:fdisk 【-l】 设备名称

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

[root@iZ255cppmtxZ ~]# fdisk -l

Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009e68a

Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    83884031    41940992   83  Linux

Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


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

用fdisk分区

[root@iZ255cppmtxZ ~]# fdisk /dev/xvdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x25a2caf5.

Command (m for help):


输入“m”

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                            <==删除一个分区
g   create a new empty GPT partition table
G   create an IRIX (SGI) partition table
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                   <==不存储,离开fdisk程序
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):


接下来正式分区

Command (m for help): n
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-62914559, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
Using default value 62914559
Partition 1 of type Linux and of size 30 GiB is set

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

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


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

[root@iZ255cppmtxZ ~]# fdisk -l

Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009e68a

Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    83884031    41940992   83  Linux

Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x25a2caf5

Device Boot Start End Blocks Id System
/dev/xvdb1 2048 62914559 31456256 83 Linux


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

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

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

[root@iZ255cppmtxZ ~]# mkfs -t ext4 /dev/xvdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1966080 inodes, 7864064 blocks
393203 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
240 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done


3、创建挂载目录并挂载

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


4、设置开机自动挂载。

[root@iZ255cppmtxZ /]# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Nov 21 18:16:53 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=6634633e-001d-43ba-8fab-202f1df93339 / ext4 defaults,barrier=0 1 1
/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。那怎么办?没关系,可以利用下面这一招:

[root@iZ255cppmtxZ local]# mount -n -o remount,rw /
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: