1,磁盘分区的概念
分区其实就是将一块磁盘划分出一部分空间出来,成为一个独立的区域,然后单独管理。
2,磁盘分区的步骤(fdisk)
1,关闭虚拟机,进入设置界面,点击硬盘,添加一块新的虚拟机。
2,开启虚拟机,查看磁盘
[root@localhost ~]# fdisk -l
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000057c4
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
磁盘 /dev/sdb:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x27c67b1a
3,/dev/sdb磁盘就是我们刚刚安装的磁盘,输入命令开始分区
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x27c67b1a 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):
4,我们可以输入m查看命令。
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):m
命令操作
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
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)
5,开始分区(只能有四个主分区,扩展分区占一个主分区,逻辑分区没有上限)
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-209715199,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-209715199,默认为 209715199):+10G
分区 1 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
6,格式化磁盘,并挂载
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount /dev/sdb1 /book
7,自动挂载,进入/etc/fatab文件在最后加入配置 xfs是格式化文件系统类型
defaults 挂载后的分区的选项(ro,rw等)
0 表示代表不要做dump备份
1代表要每天进行dump的操作
0 开机的过程中,系统默认会以fsck检验我们的这个文件系统 fsck是一个文件系统检测的命令
0 表示不检测
1 表示检测
2 表示1级别检测完后,再进行检测
/dev/sdb1 /book xfs defaults 0 0
3,parted磁盘分区步骤
1,命令进入分区,可以使用help查看命令
.
[root@localhost ~]# parted /dev/sdc
GNU Parted 3.1
使用 /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for
TYPE(min|opt) alignment
help [COMMAND] print general help, or
help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel
(partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER
as NAME
print [devices|free|list,all|NUMBER] display the partition
table, available devices, free space, all found
partitions, or a particular partition
quit exit program
rescue START END rescue a lost
partition near START and END
resizepart NUMBER END resize partition
NUMBER
rm NUMBER delete partition
NUMBER
select DEVICE choose the device to
edit
disk_set FLAG STATE change the FLAG on
selected device
disk_toggle [FLAG] toggle the state of
FLAG on selected device
set NUMBER FLAG STATE change the FLAG on
partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of
FLAG on partition NUMBER
unit UNIT set the default unit
to UNIT
version display the version
number and copyright information of GNU Parted
2,开始分区(注意parted分区是立马生效请谨慎)
(parted) mkpart liao3 200001 300000
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 1074GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 10.0GB 9999MB liao
2 10.0GB 200GB 190GB liao1
3 200GB 300GB 100GB liao3
3,下面步骤与fdisk一致
4,parted和fdisk的区别
磁盘分区工具:
1.fdisk --》安全
优点:分区的时候,先缓存在内存里,输入w保存后,才去修改分区表
输入q可以不保存
缺点:不能分超过2T的分区(dos分区表)
gpt分区表可以分超过2T的分区
2,parted
缺点:直接修改分区表,不先缓存到内存里,立马生效 --》更加危险
优点:可以分超过2T的分区,适合大磁盘的分区
磁盘阵列:N块磁盘组成一个逻辑的磁盘 20块2T磁盘