系统设备类型
Linux中,设备是以文件的形式存放在/etc目录下,其中磁盘文件一般命名为/etc/xdxn
第一个x:磁盘类型(s:sata硬盘、u盘等 h:IDE硬盘 v:虚拟硬盘)
第二个x:a...z 第几块硬盘
n为数字,表示分区所在的个数
硬盘分区命令:fdisk
[root@server ~]# fdisk -l ##-l参数,列出指定设备的分区,如果没有指定,使用/proc/patitions的内容
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors ##v虚拟磁盘,a第一块磁盘
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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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
这个测试环境是一台虚拟机,有两块硬盘,第一块安装了操作系统,我们用第二块硬盘来进行测试
[root@server ~]# fdisk /dev/vdb ##fdisk磁盘分区工具来编辑第二块硬盘:/dev/vdb
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 0x5ebdcaac.
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 ##删除设备
g create a new empty GPT partition table ##创建一个GPT分区表
G create an IRIX (SGI) partition table ##创建一个IRIX分区表
l list known partition types ##列出设备类型
m print this menu ##打印这个菜单
n add a new partition ##新建一个分区
o create a new empty DOS partition table ##创建一个dos分区表
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): g ##测试就选最新的,创建一个GPT分区表
Building a new GPT disklabel (GUID: 7AC1B0AC-BCB7-4F21-9ED0-A9A1A03D20A0)
Command (m for help): n ##创建一个新的分区
Partition number (1-128, default 1): ##分区号
First sector (2048-20971486, default 2048): ##分区起始扇区
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971486, default 20971486): +1G ##分区结束扇区,+大小直接指定分区大小
Created partition 1 ##创建成功
Command (m for help): p ##p打印分区表查看
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: gpt
# Start End Size Type Name
1 2048 2099199 1G Linux filesyste ##被划分出来的分区
Command (m for help): w ##保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
系统能够识别的
mount
分区/etc/patririons
[root@server ~]# cat /proc/partitions
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 1048576 vdb1 ##vdb1就是我们新建的分区
分区建立以后,如果我们需要使用,还需要进行格式化和挂载操作
Linux中的文件系统有vfat、ext2、ext4、xfs等
xfs是RHEL7的标准文件系统:支持最大分区9EB、传输效率可达7G/s
格式化:
[root@server ~]# mkfs.xfs /dev/vdb1 ##将vdb1分区格式化为xfs格式
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=262144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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
###查看可用分区:blkid###
[root@server ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="8eacbc25-87a4-4ed6-9400-040491ded23a" TYPE="xfs" PARTUUID="d32de79e-e1f0-4f08-ae0e-fe749a9ed052"
挂载mount:
[root@server ~]# mount /dev/vdb1 /mnt ##挂载/dev/vdb1到/mnt下
[root@server ~]# df [root@server ~]# fdisk /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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.
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted[root@server ~]# fdisk /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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.
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
##显示目前系统中文件系统的使用情况
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3160848 7313052 31% /
devtmpfs 469332 0 469332 0% /dev
tmpfs 484920 140 484780 1% /dev/shm
tmpfs 484920 12796 472124 3% /run
tmpfs 484920 0 484920 0% /sys/fs/cgroup
/dev/vdb1 1038336 32928 1005408 4% /mnt ##挂载点
[root@server ~]# touch /mnt/file1 ##写入成功
###我们可以通过添加参数来控制挂载的文件系统的权限###
[root@server ~]# mount -o ro /dev/vdb1 /mnt ##-o ro只读,rw可读写
###挂载后修改参数###
[root@server ~]# mount -o remount,ro /dev/vdb1 /mnt
swap分区的建立
[root@server ~]# fdisk /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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.
Command (m for help): n ##创建一个分区
Partition number (2-128, default 2): ##分区号2
First sector (2099200-20971486, default 2099200):
Last sector, +sectors or +size{K,M,G,T,P} (2099200-20971486, default 20971486): +1G ##大小1G
Created partition 2
Command (m for help): t ##改变分区标签
Partition number (1,2, default 2):
Partition type (type L to list all types): l ##列出分区标签
1 EFI System C12A7328-F81F-11D2-BA4B-00A0C93EC93B
2 MBR partition scheme 024DEE41-33E7-11D3-9D69-0008C781F39F
......................................................................
12 Linux filesystem 0FC63DAF-8483-4772-8E79-3D69D8477DE4
13 Linux RAID A19D880F-05FC-4D3B-A006-743F0F84911E
14 Linux swap 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
15 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF928
16 Linux reserved 8DA63339-0007-60C0-C436-083AC8230908
17 FreeBSD data 516E7CB4-6ECF-11D6-8FF8-00022D09712B
18 FreeBSD boot 83BD6B9D-7F41-11DC-BE0B-001560B84F0F
.......................................................................
Partition type (type L to list all types): 14 ##14 Linux swap
Changed type of partition 'Linux filesystem' to 'Linux swap'
##### w保存退出
[root@server ~]# cat /proc/partitions ##查看系统可识别的分区
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 1048576 vdb1
未显示我们刚刚创建的swap分区,可以使用partprobe命令同步分区表
[root@server ~]# partprobe ##同步分区表
[root@server ~]# cat /proc/partitions ##重新查看
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 1048576 vdb1
253 18 1048576 vdb2 ##vdb2分区
swap分区的管理
[root@server ~]# swapon -s ##查看系统中的swap分区
[root@server ~]# mkswap /dev/vdb2 ##格式化/dev/vdb2分区为swap分区格式
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=62d5d396-bd15-439b-a7c4-a07970410a8e
[root@server ~]# swapon -a /dev/vdb2 ##激活swap分区
[root@server ~]# swapon -s ##再次查看,swap分区生效
Filename Type Size Used Priority
/dev/vdb2 partition 1048572 0 -1
上面挂载分区,激活swap分区都是临时性的操作,如果想要自动挂载,需要修改fstab文件
文件位置:/etc/fstab
##设备 挂载点 文件系统 挂载参数默认 不备份 不检测
/dev/vdb1 /mnt xfs defaults 0 0
/dev/vdb2 swap swap defaults 0 0
清理实验环境
[root@server ~]# vim /etc/fstab ##删除fstab中的自动挂载内容
[root@server ~]# umount /dev/vdb1 ##卸载vdb1分区
[root@server ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb2 partition 1048572 0 -1
[root@server ~]# swapoff /dev/vdb2 ##关闭激活的swap分区
[root@server ~]# swapon -s
[root@server ~]# fdisk /dev/vdb ##删除创建的vdb1、vdb2分区
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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.
Command (m for help): d ##选项d 删除分区
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): w ##写入硬盘并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.