CSA笔记8-磁盘管理(1)

磁盘管理(上)

添加磁盘

Linux查看磁盘和分区:

lsblk #查看的磁盘和分区

 lsblk -p #查看的磁盘和分区,并且显示完整的路径

磁盘分区

MBR:最多只能有四个主分区或者三个主分区+1个扩展分区【在扩展分区上划分逻辑分区,逻辑分区的数量没有限制。】;分区的最大空间不能超过2.2T。

注意:

主分区+扩展分区 最多只能有4

扩展分区可以是0个,最多是1

扩展分区不能直接使用,扩展分区必须首先创建成逻辑分区才能使用

逻辑分区可以是0个 1个 多个

GPT:最多可以有128个分区,分区的空间可以大于2.2T。 

fdisk 分区

fdisk : 磁盘分区

fdisk帮助信息解释:

[root@localhost ~]# fdisk /dev/sda

DOS (MBR)

a toggle a bootable flag

b edit nested BSD disklabel

c toggle the dos compatibility flag

Generic

d delete a partition #删除分区

F list free unpartitioned space #列出未分区的剩余空间,一般不用

l list known partition types #列出已有的分区类型

n add a new partition #添加新分区

p print the partition table #打印分区表

t change a partition type #修改分区类型

v verify the partition table #确认分区表,一般不用

i print information about a partition #打印分区信息,一般不用

Misc

m print this menu #打印帮助

u change display/entry units

x extra functionality (experts only)

Script

I load disk layout from sfdisk script file

O dump disk layout to sfdisk script file

Save & Exit

w write table to disk and exit #保存分区表并退出

q quit without saving changes #退出且不保存

Create a new label

g create a new empty GPT partition table #创建一个空的 GPT 分区表

G create a new empty SGI (IRIX) partition table

o create a new empty DOS partition table #创建一个空的mbr分区表

s create a new empty Sun partition table

示例1:创建mbr格式的分区(创建一个主分区,一个扩展分区,一个逻辑分区。)

#1、创建mbr格式的分区(创建一个主分区,一个扩展分区,一个逻辑分区。)

[root@localhost ~]# fdisk /dev/sda

Command (m for help): n #输入n创建新分区

p primary (0 primary, 0 extended, 4 free) #输入p创建主分区

e extended (container for logical partitions) #输入e创建扩展分区

Select (default p): p #输入p创建主分区

Partition number (1-4, default 1): #选择主分区号,输入1表示第一个主分区

First sector (2048-20971519, default 2048): #直接按回车从当前第2048个扇区开始分区

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519):

+2g #设置第一个分区为2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): p #打印分区表

Select (default p): e #输入e创建扩展分区

Partition number (2-4, default 2):

First sector (4196352-20971519, default 4196352):

Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-20971519, default

20971519): +3g

Created a new partition 2 of type 'Extended' and of size 3 GiB.

Command (m for help): p

Select (default p): l #输入l创建逻辑分区

Command (m for help): w #输入w是保存并退出,输入q是不保存退出。

[root@localhost ~]# fdisk -l

示例二:创建gpt格式的分区

#2、创建gpt格式的分区(创建一个分区)

[root@localhost ~]# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors

Disk model: VMware Virtual S

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x40c16d66

Device Boot Start End Sectors Size Id Type

/dev/sda1 2048 4196351 4194304 2G 83 Linux

/dev/sda2 4196352 10487807 6291456 3G 5 Extended

/dev/sda5 4198400 6295551 2097152 1G 83 Linux

Command (m for help): d #输入d删除分区

Partition number (1,2,5, default 5): #直接回车删除默认分区5

Partition 5 has been deleted.

Command (m for help): d

Partition number (1,2, default 2):

Partition 2 has been deleted.

Command (m for help): d

Selected partition 1

Partition 1 has been deleted.

Command (m for help): p

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors

Disk model: VMware Virtual S

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x40c16d66

Command (m for help): g #输入g,创建GPT 分区表

Created a new GPT disklabel (GUID: E16AB0ED-D6E0-384B-9AB3-C258E54B52EC).

The device contains 'dos' signature and it will be removed by a write command.

See fdisk(8) man page and --wipe option for more details.

Command (m for help): p

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors

Disk model: VMware Virtual S

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt #类型为gpt

Disk identifier: E16AB0ED-D6E0-384B-9AB3-C258E54B52EC

Command (m for help): n

Partition number (1-128, default 1): #选择区号,默认是1

First sector (2048-20971486, default 2048):

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971486, default 20971486):

+5g

Created a new partition 1 of type 'Linux filesystem' and of size 5 GiB.

Command (m for help): n

Partition number (2-128, default 2):

First sector (10487808-20971486, default 10487808):

Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-20971486, default

20971486): +4g

Created a new partition 2 of type 'Linux filesystem' and of size 4 GiB.

Command (m for help): p

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors

Disk model: VMware Virtual S

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: E16AB0ED-D6E0-384B-9AB3-C258E54B52EC

Device Start End Sectors Size Type

/dev/sda1 2048 10487807 10485760 5G Linux filesystem

/dev/sda2 10487808 18876415 8388608 4G Linux filesystem

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]#

分区格式化(创建文件系统)(笔试面试)

格式化:给存储设备创建文件系统。

注意:格式化后原来的存储设备里面的东西会丢失。

文件系统:是操作系统用于明确存储设备或分区上的文件的方法和数据结构。

mkfs : 创建文件系统

blkid : 打印块设备属性

#1、创建ext4类型的文件系统

[root@localhost ~]# mkfs.ext

mkfs.ext2 mkfs.ext3 mkfs.ext4

[root@localhost ~]# mkfs.ext4 /dev/sda1

mke2fs 1.46.5 (30-Dec-2021)

Creating filesystem with 1310720 4k blocks and 327680 inodes

Filesystem UUID: fa8deaaa-e831-4a1b-9c8f-35316cd9f454

Superblock backups stored on blocks:

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

Allocating group tables: done

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

[root@localhost ~]#

#2、创建xfs类型的文件系统

[root@localhost ~]# mkfs.xfs /dev/sda2

meta-data=/dev/sda2 isize=512 agcount=4, agsize=262144 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=1, sparse=1, rmapbt=0

= reflink=1 bigtime=1 inobtcount=1

data = bsize=4096 blocks=1048576, 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

#blkid命令:定位/打印块设备属性

[root@localhost ~]# blkid

/dev/mapper/rhel-swap: UUID="e05fe288-94fb-43ce-8d68-4705b1a60ed0" TYPE="swap"

/dev/nvme0n1p3: UUID="4frIy0-wWVy-qyyL-2Ys6-30Ie-sDTu-dDsAoS" TYPE="LVM2_member"

PARTUUID="c1652267-fc6b-415c-8460-e2d191e3c3f8"

/dev/nvme0n1p1: UUID="C35F-305F" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI

System Partition" PARTUUID="89ef4947-c9a5-4fff-98c1-4074bc3e2a82"

/dev/nvme0n1p2: UUID="baedb9f9-324c-4a00-b508-cc5d7254885e" BLOCK_SIZE="512"

TYPE="xfs" PARTUUID="c2458b1b-52e1-41a2-b541-036e0af11154"

/dev/sr0: BLOCK_SIZE="2048" UUID="2022-04-19-20-42-48-00" LABEL="RHEL-9-0-0-

BaseOS-x86_64" TYPE="iso9660" PTUUID="3a60e52f" PTTYPE="dos"

/dev/mapper/rhel-root: UUID="8ecc40f2-ba4c-41d9-b291-7688afd14b08"

BLOCK_SIZE="512" TYPE="xfs"

/dev/sda2: UUID="de382d11-2d8f-4d73-8f04-819f3d4f6cea" BLOCK_SIZE="4096"

TYPE="xfs" PARTUUID="a1fef3ac-9c9f-1d47-8679-8d5f750028e7"

/dev/sda1: UUID="a6362efd-bb56-4ce5-ab9c-238ccfd66ed1" BLOCK_SIZE="512"

TYPE="ext4" PARTUUID="7aa97558-4881-cb4e-860c-8fc5381b5ace"

  • 17
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值