博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux磁盘管理
阅读量:5059 次
发布时间:2019-06-12

本文共 8423 字,大约阅读时间需要 28 分钟。

1.MBR:共512字节

446字节bootloader主引导程序

64字节磁盘分区表

2字节魔数

2.主分区和逻辑分区

主分区最多是4个

扩展分区最多一个,另外扩展分区不能被直接使用而是制作成逻辑分区使用

逻辑分区序列号是从5开始的

逻辑分区可以有很多个,取决于扩展分区大小

 

3.fdisk管理分区

n:添加新的分区

p:查看分区信息

w:保存退出

q:不保存退出

d:删除分区

t:改变分区类型

 

4.新建分区的使用

1)在虚拟机上添加一块硬盘

2)fdisk创建新分区:+500M选择大小

[root@li ~]# fdisk /dev/sdbWelcome 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 tableBuilding a new DOS disklabel with disk identifier 0xe140b235. Command (m for help): n                          #新建分区Partition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): p                            #选择主分区Partition number (1-4, default 1):First sector (2048-41943039, default 2048):    #分区磁盘起始位,默认值,回车即可Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G    #磁盘大小选择,加号不能省略,回车即可Partition 1 of type Linux and of size 5 GiB is set Command (m for help): P                      #查看分区是否建立 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xe140b235 Device Boot Start End Blocks Id System/dev/sdb1 2048 10487807 5242880 83 Linux Command (m for help): W    #w保存退出,q是不保存退出The partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.

 

3)格式化

[root@li ~]# mkfs.xfs /dev/sdb1     #格式化成centos7系统默认的文件系统类型XFSmeta-data=/dev/sdb1 isize=512 agcount=4, agsize=327680 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data = bsize=4096 blocks=1310720, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0

 

4)挂载使用

mount /dev/sdb1 /test

 

5)开机自启

echo "/dev/sdb1 /test xfs defaults 0 0" >> /etc/fstab echo "mount/dev/sdb1/test" >> /etc/rc.localchmod +x /etc/rc.d/rc.local

 

 

5.fdisk创建逻辑分区

1)fdisk添加扩展分区

[root@li ~]# fdisk /dev/sdbWelcome 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 type:p primary (1 primary, 0 extended, 3 free)e extendedSelect (default p): e     #选择扩展分区Partition number (2-4, default 2):First sector (10487808-41943039, default 10487808):Using default value 10487808Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G    #5G大小Partition 2 of type Extended and of size 5 GiB is set Command (m for help): P   #查看分区 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xe140b235 Device Boot Start End Blocks Id System/dev/sdb1 2048 10487807 5242880 83 Linux/dev/sdb2 10487808 20973567 5242880 5 Extended Command (m for help): w   #保存退出The partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.

 

2)创建逻辑分区

[root@li ~]# fdisk /dev/sdbWelcome 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): nPartition type:p primary (1 primary, 1 extended, 2 free)l logical (numbered from 5)Select (default p): l    #创建逻辑分区Adding logical partition 5First sector (10489856-20973567, default 10489856):Using default value 10489856Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +10G   #逻辑分区大小不能超过扩展分区大小Value out of range.Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +2gUnsupported suffix: ‘g’.Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)2^N: K (KibiByte), M (MebiByte), G (GibiByte)Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +2GPartition 5 of type Linux and of size 2 GiB is set Command (m for help): P Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xe140b235 Device Boot Start End Blocks Id System/dev/sdb1 2048 10487807 5242880 83 Linux/dev/sdb2 10487808 20973567 5242880 5 Extended/dev/sdb5 10489856 14684159 2097152 83 Linux Command (m for help): WThe partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.

 

3)创建文件系统

同上

4)开机自动挂载

同上

 

6.LVM逻辑卷

功能/命令 物理卷管理 卷组管理 逻辑卷管理
扫描 pvscan vgscan lvscan
建立 pvcreate vgcreate lvcreate
显示 pvdisplay vgdisplay lvdisplay
删除 pvremove vgremove lvremove
扩展   vgextend lvextend
缩小   vgreduce lvreduce

物理卷 - ->卷组 - ->逻辑卷

1)创建物理卷

pvcreate /dev/sd{b,c}

 

2)创建卷组

vgcreate vg_li /dev/sd{b,c}

 

3)创建逻辑卷

lvcreate –n lv_li –L 500M vg_li

 

4)格式化

mkfs.xfs /dev/vg_li/lv_li

 

5)挂载使用

mount /dev/vg_li/lv_li /test

 

注意:卸载命令umount

后面跟挂载点或者磁盘都可以

 

7.LVM扩容

lvextend –L +300M /dev/vg_li/lv_lilvextend –L 800M /dev/vg_li/lv_li xfs_growfs /dev/vg_li/lv_li

 

 

8.交换分区SWAP

1)创建分区

[root@li ~]# fdisk /dev/sdbWelcome 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): nPartition type:p primary (1 primary, 1 extended, 2 free)l logical (numbered from 5)Select (default p): pPartition number (3,4, default 3):First sector (20973568-41943039, default 20973568):Using default value 20973568Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2GPartition 3 of type Linux and of size 2 GiB is set Command (m for help): P Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xe140b235 Device Boot Start End Blocks Id System/dev/sdb1 2048 10487807 5242880 83 Linux/dev/sdb2 10487808 20973567 5242880 5 Extended/dev/sdb3 20973568 25167871 2097152 83 Linux/dev/sdb5 10489856 14684159 2097152 83 Linux/dev/sdb6 14686208 18880511 2097152 83 Linux/dev/sdb7 18882560 20973567 1045504 83 Linux Command (m for help): WThe partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.

 

2)识别新创建的分区

[root@li ~]# ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6 /dev/sdb7[root@li ~]# partprobe     #加载新建分区Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.[root@li ~]# ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb5 /dev/sdb6 /dev/sdb7

 

3)格式化为swap类型

[root@li ~]# mkswap /dev/sdb3Setting up swapspace version 1, size = 2097148 KiBno label, UUID=b184f890-2ec4-417d-9aef-1ac87a78464b

 

4)启动swap

[root@li ~]# free -htotal used free shared buff/cache availableMem: 974M 89M 751M 7.6M 133M 733MSwap: 2.0G 0B 2.0G[root@li ~]# swapon /dev/sdb3[root@li ~]# free -htotal used free shared buff/cache availableMem: 974M 90M 750M 7.6M 133M 732MSwap: 4.0G 0B 4.0G

 

5)开机自启

echo “/dev/sdb3 swap swap defaults 0 0”  >> /etc/fstabecho “swapon /dev/sdb3” >> /etc/rc.local

 

9.创建交换分区SWAP–本地文件

 

1)创建目录

[root@li ~]# mkdir /swap

 

2)创建文件

[root@li ~]# dd if=/dev/zero of=/swap/swap bs=2M count=20142014+0 records in2014+0 records out4223664128 bytes (4.2 GB) copied, 29.3039 s, 144 MB/s

 

3)格式化

[root@li ~]# mkswap /swap/swapSetting up swapspace version 1, size = 4124668 KiBno label, UUID=211cb23a-49b5-46fc-b568-f167d4b6d06a

 

4)写入文件

[root@li ~]# echo “/swap/swap swap swap defaults 0 0” >> /etc/fstab[root@li ~]# mount -a[root@li ~]# free -htotal used free shared buff/cache availableMem: 974M 85M 69M 7.6M 819M 712MSwap: 4.0G 0B 4.0G[root@li ~]# swapon -aswapon: /swap/swap: insecure permissions 0644, 0600 suggested.[root@li ~]# free -htotal used free shared buff/cache availableMem: 974M 88M 66M 7.6M 819M 709MSwap: 7.9G 0B 7.9G

 

5)修改权限

[root@li ~]# chmod 0600 /swap/swap

 

转载于:https://www.cnblogs.com/Agnostida-Trilobita/p/11142004.html

你可能感兴趣的文章
ios封装静态库技巧两则
查看>>
Educational Codeforces Round 46 (Rated for Div. 2)
查看>>
Abstract Factory Pattern
查看>>
C# 实现Bresenham算法(vs2010)
查看>>
基于iSCSI的SQL Server 2012群集测试(一)--SQL群集安装
查看>>
list 容器 排序函数.xml
查看>>
存储开头结尾使用begin tran,rollback tran作用?
查看>>
Activity启动过程中获取组件宽高的五种方式
查看>>
java导出Excel表格简单的方法
查看>>
SQLite数据库简介
查看>>
利用堆实现堆排序&优先队列
查看>>
Mono源码学习笔记:Console类(四)
查看>>
Android学习路线(十二)Activity生命周期——启动一个Activity
查看>>
《Genesis-3D开源游戏引擎完整实例教程-跑酷游戏篇03:暂停游戏》
查看>>
CPU,寄存器,一缓二缓.... RAM ROM 外部存储器等简介
查看>>
windows下编译FreeSwitch
查看>>
git .gitignore 文件不起作用
查看>>
Alan Turing的纪录片观后感
查看>>
c#自定义控件中的事件处理
查看>>
App.config自定义节点读取
查看>>