linux--系统中的简单分区和管理

一、添加文件系统空间

简单分区和文件系统
1.认识
1> 存储是每个计算机系统的基本需求。 Red Hat EnterpriseLinux 提供了一些强大的工具 , 它们能在大量的场景中管理多种类型的存储设备

2> disk 是用于管理磁盘分区的实用程序。您可以通过选择 -l选项和指定磁盘名称 ( fdisk -cul /dev/vda ) 运行该实用程序 , 以查看磁盘及其分区。您可以通过交互式地运行该实用程序 , 并选择相应的菜单选项 ( fdisk -cu /dev/vda ) 进行更改。 -c 禁用旧的 DOS 兼容模式 , -u 以扇区 ( 而不是柱面 , 已经过时 ) 的格式显示输出
xiaot

3> 查看系统设备信息
fdisk -l
显示系统中所有可以使用的设备信息
blkid
显示系统正在使用的设备 id

2.添加新设备
1> 新建分区
[[email protected] ~]# fdisk /dev/vdb   ##进入/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 0x115e3020.

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): p                                         ##建立新的主分区
Partition number (1-4, default 1): 1               ##选择建立1号主分区
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: 0x115e3020

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

Command (m for help): n                      ##再次建立新的分区
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e                            ##选择建立新的扩展分区
Partition number (2-4, default 2): 2
First sector (206848-20971519, default 206848): 
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +200M
Partition 2 of type Extended and of size 200 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: 0x115e3020

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      616447      204800    5  Extended

Command (m for help): n                    
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l                           ##新建逻辑分区
Adding logical partition 5
First sector (208896-616447, default 208896): 
Using default value 208896
Last sector, +sectors or +size{K,M,G} (208896-616447, default 616447): +100M
Partition 5 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: 0x115e3020

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      616447      204800    5  Extended
/dev/vdb5          208896      413695      102400   83  Linux

Command (m for help): w                             ##设置完毕后保存以上所有设置
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# partprobe                      ##更新分区系统文件
[[email protected] ~]# cat /proc/partitions       ##查看分区系统文件内分区情况
major minor  #blocks  name

253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     102400 vdb1
 253       18          1 vdb2
 253       21     102400 vdb5
[[email protected] ~]#

图示:fdisk显示当前存在设备

[[email protected] ~]# blkid                          ##当前可以使用的设备,因为新建的分区内被数据占用,未被系统认为可以使用的设备,所以没有刚才新建的设备
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"

2> 格式新建分区,激活设置可被使用
文件系统:
##mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat    
##mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs     

#
# /etc/fstab
# Created by anaconda on Wed May  7 01:22:57 2014
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /                       xfs     defaults        1 1 
/dev/vdb1 /mnt      xfs         defaults    0       0
设备       挂载位置   文件系统类型             0备份  0检查

二、添加swap交换分区

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

1.添加分区方式相同,在建立新的分区后,进行设置

示图:t添加分区功能id,l查看分区功能各id

示图:设置分区的swap功能id,将修改保存进硬盘,刷新

示图:swap型文件格式化设备,成为可用的swap设备

2.管理交换分区
使用 fdisk 创建新分区。此外 , 在用 fdisk 保存更改之前 , 将分区类型更改为 “ 0x82 LinuxSwap”
mkswap /dev/vdaN 会准备好将分区用作交换区
blkid /dev/vdaN 将确定 UUID
将新交换空间添加到 /etc/fstab :UUID=uuid swap swap defaults 0 0
swapon -a 将激活新交换区
swapon -s 将显示当前交换区的状态
swapoff /dev/vdaN 将停用该特定交换区
[[email protected] ~]# swapon -a /dev/vdb[1,2]  ##激活/dev/vdb1和vdb2交换区
[[email protected] ~]# swapon -s                ##显示当前交换区的状态
Filename                Type        Size    Used    Priority   ##Filename文件名,Type类型, Size大小, Used被使用大小, Priorty优先级
/dev/vdb1                                  partition    102396    0    -1
/dev/vdb2                                  partition    102396    0    -2

三、磁盘加密保护

1.认识
LUKS ( Linux 统一密钥设置 ) 是标准的设备加密格式
LUKS 可以对分区或卷进行加密
必须首先对加密的卷进行解密 , 才能挂载其中的文件系统

2.步骤
1> 使用 fdisk 创建新分区

2> cryptsetup luksFormat /dev/vdaN 可对新分区进行加密 ,并设置解密密码

[[email protected] ~]#  cryptsetup luksFormat /dev/vdb1

WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase:

3> 您输入正确的解密密码之后 , cryptsetup luksOpen /dev/vdaN name 会将加密的卷 /dev/vdaN 解锁为/dev/mapper/name
示图:

4> 解密的卷上创建 xfs 文件系统 : mkfs -t xfs /dev/mapper/name
示图:

5> 创建目录挂载点 , 并挂载文件系统 : mkdir /mnt
– mount /dev/mapper/name /mnt

6> 完成之后 , umount /dev/mapper/name 并运行cryptsetup luksClose name 以锁定加密的卷

时间: 2024-08-29 05:30:08

linux--系统中的简单分区和管理的相关文章

Linux系统中程序的安装及管理、创建私有yum仓库实验

各位小伙伴今天要和大家分享的是Linux系统中程序的安装及管理,以及创建私有yum仓库的操作实验.本次我们会从以下几个部分进行说明: Linux应用程序基础 查询RPM软件包信息 安装.升级.卸载.RMP软件包.yum仓库 源代码编译安装 应用程序与系统命令的关系:1.文件位置? 系统命令:一般在/bin和/sbin目录中? 应用程序:通常在/usr/local目录中2.主要用途? 系统命令:完成对系统的基本管理工作,例如IP配置工具? 应用程序:完成相对独立的其它辅助任务,例如网页浏览3.适用

linux--系统中的简单分区和管理储存

一.设备的查看 1.发现系统中的设备 fdisk -l cat /proc/partitions图示:发现设备 2.系统发现的,但是没用投入使用,随时可以使用设备  blkid #查看设备的id信息3.发现并且在使用的设备 df -h #2的n次方 df -H #10的n次方图示:正在使用的设备 **两者的区别:统计的计算方法不同 二.设备名称的读取/dev/xd*x=s  /dev/sd*        #sata硬盘,过着iscsi网络储存x=v  /dev/vd*        #虚拟硬盘

学习Linux系统中命令的简单方法

如果说如何快速学习.了解Linux的话,我的答案是学命令.背命令!为何呢?对于一名新手来说,去学习Linux的思想.了解Linux的架构.明白Linux中"一切皆文件"概念虽然说是没有错,是对的.但是个人认为去学习这些"高大上"的东西不是一时半会的事儿,它需要一定的时间和经验去沉淀才能掌握.那么如何最快速了解Linux并使用呢?我依然觉得学命令.背命令,掌握命令是比较笨但却是比较快的方式. 我开始学习Linux的时候,问了前辈:我入门Linux需要掌握哪些命令呢?前

linux中对swap分区的管理

一:swap分区概念原理 swap分区:(存放内存溢出来的数据) 从功能上讲,交换分区主要是在内存不够用的时候,将部分内存上的数据交换到swap空间上,以便让系统不会因内存不够用而导致oom或者更致命的情况出现. 一:swap基本概念 前提:知道内存回收概念 为什么要进行内存回收? 1:内核需要为任何时刻突发到来的内存申请提供足够的内存.所以一般情况下保证有足够的free空间对于内核来说是必要的.所以内核有必要设计一个周期性回收内存的机制,以便cache的使用和其他相关内存的使用不至于让系统的剩

在Linux系统中文件(资源)和用户的管理

一个可执行二进制程序,被加载到内存,被内核调度到CPU上运行,这时候,就表现了一个进程.也可以说进程是程序的一个实例,是程序的动态表现. 在 Linux 系统中进程(process)是有属主的,也就是该进程以哪个用户的身份运行的.大家都知道,程序有输入和输出,也称这为程序IO.如果我们程序数据输入是磁盘.如,Web 服务器,接收用户的请求之后,把网页数据从磁盘中读入加工之后再把数据响应给用户.如果,发起Web 服务进程的用户没有读取该用户请求网页文件的权限.则无法响应用户的请求了.所以,文件(资

每天进步一点点——Linux系统中的异常堆栈跟踪简单实现

转载请说明出处:http://blog.csdn.net/cywosp/article/details/25002201 在Linux中做C/C++开发经常会遇到一些不可预知的问题导致程序崩溃,同时崩溃后也没留下任何代码运行痕迹,因此,堆栈跟踪技术就显得非要重要了.本文将简单介绍Linux中C/C++程序运行时堆栈获取,首先来看backtrace系列函数--使用范围适合于没有安装GDB或者想要快速理清楚函数调用顺序的情况 ,头文件execinfo.h int backtrace (void **

用于管理Linux系统中的各种服务的命令service命令

我们知道service命令是用于管理Linux系统中的各种服务的命令.其实service是位于系统中/usr/sbin/service的一个可执行的脚本,其内容如下: #!/bin/sh ########################################################################### # /usr/bin/service # # A convenient wrapper for the /etc/init.d init scripts.  #

##II 第四单元##管理系统中的简单分区和文件系统

简单分区和文件系统 存储是每个计算机系统的基本需求. Red Hat EnterpriseLinux 提供了一些强大的工具 , 它们能在大量的场景中管理多种类型的存储设备 disk 是用于管理磁盘分区的实用程序.您可以通过选择 -l选项和指定磁盘名称 ( fdisk-cul /dev/vda ) 运行该实用程序 , 以查看磁盘及其分区.您可以通过交互式地运行该实用程序 , 并选择相应的菜单选项 (fdisk -cu /dev/vda ) 进行更改. -c 禁用旧的 DOS 兼容模式 ,-u 以扇

管理系统中的简单分区和文件系统

管理系统中的简单分区和文件系统 一.简单分区和文件系统 存储是每个计算机系统的基本需求. Red Hat Enterprise Linux 提供了一些强大的工具 , 它们能在大量的场景中管理多种类型的存储设备 disk 是用于管理磁盘分区的实用程序.您可以通过选择 -l选项和指定磁盘名称 ( fdisk -cul /dev/vda ) 运行该实用程序 , 以查看磁盘及其分区.您可以通过交互式地运行该实用 程序 , 并选择相应的菜单选项 ( fdisk -cu /dev/vda ) 进行更改. -