您的位置:首页 > 运维架构 > Linux

linux中管理系统分区汇总

2017-11-07 18:01 316 查看

管理系统分区

添加文件系统空间

添加swap交换分区

对系统分区加密

常用命令格式:

fdisk       是用于管理磁盘分区的使用程序
fdisk -l    列出磁盘分区信息
blkid       列出系统中可以使用的设备id
df      查看系统中在使用的设备信息


文件系统比较

ext4 是 Red Hat Enterprise Linux 6 的标准文件系统。它非常强大可靠 , 具有多项可以提高现代工作量处理性能的功能

ext3是第三代扩展文件系统,是一个日志文件系统,采用简介影射地质,当操作大文件时,效率低于ext4。且只能容纳2TB的文件系统和16GB的文件。

ext2 是常用于 Linux 中的较旧的文件系统。它简单可靠 ,非常适合小型存储设备 , 但是效率低于 ext4。

vfat 支持包括一系列相关文件系统 ( VFAT/FAT1,FAT32 ), 这些文件系统针对较旧版本的 MicrosoftWindows 开发 , 在大量的系统和设备上受支持

xfs 在 Red Hat Enterprise Linux 7 的标准文件系统其具备数据完全、性能稳定、扩展性强 ( 8eb-1byte)、传输速率高(7G/s)

1.分区划分

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.

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  ##退出
s   create a new empty Sun disklabel
t   change a partition's system id   ##修改分区功能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): n         ##新建分区
Partition type:
p   primary (0 primary, 0 extended, 4 free)  ##分区类型位主分区
e   extended                 ##分区类型位扩展分区
Select (default p):                 ##默认位主分区
Using default response p
Partition number (1-4, default 1): 1        ##主分区id
First sector (2048-20971519, default 2048):     ##此分区起始位置
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M  ##分区大小
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): 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: dos
Disk identifier: 0x193488c3

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux

Command (m for help): wq        ##保存推出,如果安q表示放弃更改退出


partprobe ##同步分区表

cat /proc/partitions ##查看系统识别的分区信息

文件系统创建示例:

mkfs.xfs /dev/vdbx ##格式化指定分区

mount /dev/vdbx /mnt ##临时挂载

vim /etc/fstab ##永久挂载

devic   mountpoint  ftype   defaults(mountpoint)    0 0
/dev/vdbx   /mnt    xfs defaults    0 0


mount -a #使/etc/fstab中记录的挂载策略生效

umount /dev/vdbx | /mnt #卸载挂载

2.swap

swap 交换分区

交换区是磁盘驱动器上的空间,用作当前未使用部分内存的溢出。这样,系统就能在主内存中留出空间用于储存当前正在处理的数据,并在系统面临主内存空间不足的风险时提供应急溢出。

1.创建新的磁盘分区:

fdisk /dev/vdb  #分区编辑
Welcome to fdisk (util-linux 2.23.2)

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

Command (m for help): t
Partition number (1-3,defaule 3):
Hex code (type L to list all codes): 82     #修改swap分区标识为doc(gpt 14;doc 82)
Changed type of partition 'Liunx' to 'Linux swap / Solaris'

Command (m for help): wq            #保存退出


2.创建新的swap交换区

mkswap /dev/vdbx    #会将准备好的分区用作交换区


3.激活swap分区(临时):

swapon -a /dev/vdbx #将刚分好的swap交换区激活
swapon -s       #显示当前交换区的状态
swapoff /dev/vdbx   #停用指定交换区


4.激活swap分区(永久):

vim /etc/fstab

/dev/vdbx   swap    swap    defaults,pri=1  0 0


swapon -s #显示当前交换区的状态

swapoff /dev/vdbx #停用指定交换区

3.磁盘加密

1.创建新的磁盘分区并加密

1、使用fdisk创建新分区
fdisk  /dev/vdb
2、使用cryptsetup对新分区进行加密并设置密码
cryptsetup luksFormat /dev/vdb1
cryptsetup open /dev/vdb1 westos    #开启加密启动
3、格式化成为xfs格式
mkfs.xfs  /dev/mapper/westos
4、创建目录挂载点,并挂载
mount /dev/mapper/westos  /mnt/
5、卸载挂载,并关闭加密启动
umount /mnt/            #卸载
a08f
挂载目录
cryptsetup close westos     #关闭加密启动


2.加密磁盘的永久挂载

vim /etc/crypttab

解密后设备管理文件   设备      加密字符存放文件
redhat          /dev/vdbx   /root/lukspsfile


vim /root/lukspsfile

(输入加密磁盘的密码)


chmod 600 /root/lukspsfile

cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile

vim /etc/fstab

/dev/mapper/redhat  /mnt    xfs defaults    0 0


reboot


3.加密清除

vim /etc/fstab
> /etc/crypttab
rm -fr /root/lukspsfile
umount /mnt/
cryptsetup close redhat
mkfs.xfs  /dev/vdb1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: