我所接触的linux分区分为两种,一种是使用fdisk分区,另外一种是parted分区。前者是针对MBR模式分区的,后者是针对GPT模式分区的

    fdisk分区:    

fdisk -l  ---->查看磁盘信息
fdisk /dev/sdc --->选择需要操作的磁盘(eg:/dev/sdc)

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 (逻辑分区为8e)
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 ( primary, extended, free)
e extended
Select (default p): p
Partition number (-, default ): 1
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Linux and of size GiB is set Command (m for help): t
Selected partition
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

创建及扩展逻辑卷

[root@localhost ~]# pvcreate /dev/sdc1                ---->创建pv
Physical volume "/dev/sdc1" successfully created
[root@localhost ~]# vgextend rhel /dev/sdc1 ---->扩展vg卷组
Volume group "rhel" successfully extended
[root@localhost ~]# vgreduce rhel /dev/sdc1 --->如果不想再加入到已有的vg里面,想自己建一个vg卷组,将刚刚扩展进去的pv给移除出来,
Removed "/dev/sdc1" from volume group "rhel"
[root@localhost ~]# vgcreate vg2 /dev/sdc1 --->创建新的vg,并设置vg名为vg2
Volume group "vg2" successfully created
[root@localhost ~]# lvextend /dev/rhel/root /dev/sdc1
Physical Volume "/dev/sdc1" not found in Volume Group "rhel". --->没添加进vg组,直接扩展到逻辑卷会报错,如要扩展需,先vgextend到相应的vg组
[root@localhost ~]# pvremove /dev/sdc1 ---->移除pv
Labels on physical volume "/dev/sdc1" successfully wiped
如lvextend加入错入则如下解决
[root@localhost ~]# lvextend /dev/rhel/root /dev/sdc1                         ---->将扩展的/dev/sdc1扩展至/dev/rhe1/root中,随后感觉扩展错误,怎么退出,
Size of logical volume rhel/root changed from 90.46 GiB (23158 extents) to 92.46 GiB (23669 extents). --->记住该extents大小,是从23158变为了23669
Logical volume root successfully resized
[root@localhost ~]# lvreduce -l /dev/rhel/root ---->这里是将扩展进去的/dev/sdc1给退出来,-l参数 指定extents大小 ,指定缩减后/dev/rhel/root的大小
WARNING: Reducing active and open logical volume to 90.46 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]: y
Size of logical volume rhel/root changed from 92.46 GiB ( extents) to 90.46 GiB ( extents).
Logical volume root successfully resized ---->成功,之后可重新扩展

[root@localhost ~]# lvcreate -l +100%Free rhel /dev/sdc1 -n lv2                 ---->重新创建一个lv卷,-n参数 指定创建后的卷名字 rhel是卷组 , 
Logical volume "lv2" created.

parted分区:

[root@localhost ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) select /dev/sdc ---->选择要操作的分区,一定要注意所执行的磁盘
Using /dev/sdc
(parted) p ---->查看当前分区信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags
1049kB 2146MB 2145MB p lvm
(parted) mklabel GPT ---->磁盘格式化为GPT模式,之前是则不需要格式化
Warning: The existing disk label on /dev/sdc will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart name % % ---->name为自定义为该分区取名 % % 是磁盘/dev/sdc的区间作为该分区的大小
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: Number Start End Size File system Name Flags
1049kB 2146MB 2145MB name (parted) set lvm on ---->依据分区号1,将分区1设置为逻辑卷
(parted) rm 1 ---->删除分区号为1的分区
(parted) q ---->退出即保存

磁盘格式化后并挂载

 容量缩减,方式一
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs 93G 15G 78G % /
devtmpfs devtmpfs 904M 904M % /dev
tmpfs tmpfs 914M 80K 914M % /dev/shm
tmpfs tmpfs 914M 8.9M 905M % /run
tmpfs tmpfs 914M 914M % /sys/fs/cgroup
/dev/sda1 xfs 497M 124M 373M % /boot
/dev/mapper/rhel-home xfs .0G 65M .0G % /home
[root@localhost ~]# mkfs.ext4 /dev/mapper/rhel-home ---->缩减分区大小需要先将格式变为ext4格式,xfs格式不支持通过resize2fs缩减
mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# resize2fs /dev/mapper/rhel-home 2G ---->重新指定/rhel-home卷的大小,需要加单位,不加单位则默认为block块
resize2fs 1.42. (-Dec-)
Resizing the filesystem on /dev/mapper/rhel-home to (4k) blocks.
The filesystem on /dev/mapper/rhel-home is now blocks long.
[root@localhost ~]# lvreduce -L 2G /dev/rhel/home ---->2G与上相同
WARNING: Reducing active logical volume to 2.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
Size of logical volume rhel/home changed from 7.00 GiB ( extents) to 2.00 GiB ( extents).
Logical volume home successfully resized
[root@localhost ~]# mount /dev/mapper/rhel-home /home/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 93G 15G 78G % /
devtmpfs 904M 904M % /dev
tmpfs 914M 80K 914M % /dev/shm
tmpfs 914M 8.9M 905M % /run
tmpfs 914M 914M % /sys/fs/cgroup
/dev/sda1 497M 124M 373M % /boot
/dev/mapper/rhel-home .9G 21M .8G % /home
缩减容量:方式二(注:该系统卷root与卷home都为xfs文件系统,与上不同,但该操作与文件系统无关联)一定要慎用,因为操作几次都把home逻辑卷下的用户给搞坏了,后来还得重新建用户。
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 91G 15G 77G % /
devtmpfs 904M 904M % /dev
tmpfs 914M 276K 914M % /dev/shm
tmpfs 914M 9.1M 905M % /run
tmpfs 914M 914M % /sys/fs/cgroup
/dev/sda1 497M 124M 373M % /boot
/dev/mapper/rhel-home .0G 65M .0G % /home
/dev/sr0 .7G .7G % /media
[root@localhost ~]# lvreduce -L 88G /dev/rhel/root ---->对根目录操作一定要谨慎再谨慎
WARNING: Reducing active and open logical volume to 88.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]: y
Size of logical volume rhel/root changed from 90.46 GiB ( extents) to 88.00 GiB ( extents).
Logical volume root successfully resized
[root@localhost ~]# lvextend /dev/rhel/home /dev/sda2 /dev/sdb1 /dev/sd
/dev/sda2 /dev/sdb1
[root@localhost ~]# lvextend /dev/rhel/home /dev/sda2 /dev/sdb1 ---->将释放的空间扩展到home卷下
No free extents on physical volume "/dev/sda2".
Size of logical volume rhel/home changed from 7.00 GiB ( extents) to 9.46 GiB ( extents).
Logical volume home successfully resized
[root@localhost ~]# xfs_growfs /dev/mapper/rhel-home ---->xfs文件系统扩容,ext4使用resize2fs扩容
meta-data=/dev/mapper/rhel-home isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
data blocks changed from to
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 91G 15G 77G % /
devtmpfs 904M 904M % /dev
tmpfs 914M 276K 914M % /dev/shm
tmpfs 914M 9.1M 905M % /run
tmpfs 914M 914M % /sys/fs/cgroup
/dev/sda1 497M 124M 373M % /boot
/dev/mapper/rhel-home .5G 66M .4G % /home ---->这里扩容了2.5G
/dev/sr0 .7G .7G % /media
添加新卷
[root@localhost ~]# lvcreate -l +%Free rhel /dev/sda2 -n lv2 --->创建新的lv卷
Logical volume "lv2" created.
[root@localhost ~]# mkfs.xfs /dev/mapper/rhel-lv2 ---->将新的lv2卷格式化为xfs格式
meta-data=/dev/mapper/rhel-lv2 isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal log bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
[root@localhost ~]# mkdir /lv2 ---->创建目录
[root@localhost ~]# mount /dev/mapper/rhel-lv2 /lv2/ ---->挂载
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 93G 15G 78G % /
devtmpfs 904M 904M % /dev
tmpfs 914M 80K 914M % /dev/shm
tmpfs 914M 8.9M 905M % /run
tmpfs 914M 914M % /sys/fs/cgroup
/dev/sda1 497M 124M 373M % /boot
/dev/mapper/rhel-home .0G 33M .0G % /home
/dev/mapper/rhel-lv2 .0G 33M .0G % /lv2
扩展容量
[root@localhost ~]#xfs_growfs /dev/mapper/rhel-root ---->扩展xfs分区大小,这是扩展到root根下
[root@localhost ~]#resize2fs /dev/mapper/rhel-home 7G ---->扩展ext4分区大小。

    

fdisk与parted分区的更多相关文章

  1. fdisk 和 parted 分区工具

    fdisk 和 parted: fdisk 是用来对 Linux 下的 MBR 分区进行操作的一款分区工具, 由于 MBR 的设计缺陷导致 MBR 不能处理大于 2TB 的硬盘, 并且主分区个数不能超 ...

  2. (转)linux磁盘分区fdisk分区和parted分区

    linux磁盘分区fdisk分区和parted分区 原文:http://www.cnblogs.com/jiu0821/p/5503660.html ~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  3. parted 分区命令

    fdisk  是针对 MBR的分区 ,因为MBR分区空间最大不能超过2T  最多分4个主分区 , 所以parted可以修改磁盘为GPT  可以支持更大的分区,更多的分区 1  查看分区 : #part ...

  4. parted分区工具用法

    parted分区工具用法 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 随着生产环境中数据量的增大,我们对硬盘的容量也有很大的需求,当硬盘的容量大于2T(工业上的最大磁盘2.2TB ...

  5. parted分区命令

    Parted是一个比fdisk更高级的工具,它支持多种分区表格式,包括MS-DOS和GPT.它允许用户创建,删除,调整大小,缩小,移动和复制分区,重新组织磁盘使用,以及将数据复制到新硬盘,但在缩小分区 ...

  6. parted分区的步骤

    使用parted分区的步骤1. fdisk -l             ##查看一下当前的存储设备,这里可以看到新加入的磁盘,比如/dev/sdb2. parted /dev/sdb         ...

  7. 8.1 fdisk:磁盘分区工具

    fdisk 是Linux下常用的磁盘分区工具.受mbr分区表的限制,fdisk工具只能给小于2TB的磁盘划分分区.如果使用fdisk对大于2TB的磁盘进行分区,虽然可以分区,但其仅识别2TB的空间,所 ...

  8. parted分区和挂载及非交互式操作

    author : headsen  chen date : 2017-11-17  09:45:36 个人原创,转载请注明作者,出处,否则依法追究法律责任 1,将磁盘上原有的分区删除掉: 进入:#pa ...

  9. 文件系统之parted 分区

    parted分区命令 1.分区表区别 我们 Linux 系统中有两种常见的分区表 MBR 分区表(主引导记录分区表)和 GPT 分区表(GUID 分 区表) MBR 分区表:支持的最大分区是 2TB( ...

随机推荐

  1. github上手实践教程

    简介: SSH公私钥的使用 github的使用 git 工具的基本使用 基本步骤: 一.github的使用 1.github账号的创建[官网一步一步创建就行了,这一步骤省略] 2.创建远程仓库: 创建 ...

  2. .NET源代码已经下载,潜心研读…

    有兴趣的弟兄可以从这里下载:http://referencesource.microsoft.com

  3. CentOS7系列--1.1CentOS7安装

    CentOS7安装 1. 下载CentOS7 下载的网址为: http://isoredirect.centos.org/centos/7/isos/x86_64/ 2. CentOS7安装 2.1. ...

  4. linux 用户管理 groupadd、groupmod、groupdel、gpasswd

    添加用户组groupadd [选项] 组名 /usr/sbin/groupadd执行权限:root一个用户可以属于多个所属组,但有一个缺省组,和用户名同名-g GID:指定组ID 修改用户组 grou ...

  5. vmware centos 安装

    一.分区 一块硬盘主分区+扩展分区最多只能有4个,其中扩展分区最多只能有1个.扩展分区不能写入数据,只能包含逻辑分区.这些都不是linux的限制,而是硬盘结构的限制. 分区号 第一种分区法: |--- ...

  6. 前端构建工具 Gulp.js 上手实例

    在软件开发中使用自动化构建工具的好处是显而易见的.通过工具自动化运行大量单调乏味.重复性的任务,比如图像压缩.文件合并.代码压缩.单元测试等等,可以为开发者节约大量的时间,使我们能够专注于真正重要的. ...

  7. Swagger RESTful API文档规范

    *注意编写的关键词:“必须”.“不能”.“需要”.“应当”,“不得”.“应该”.“不应该”,“推荐”.“可能”和“可选的” 原文链接:http://swagger.io/specification/ ...

  8. winform listbox 使用DrawMode使用OwnerDrawVarialbe或OwnerDrawFixed无水平滚动条

    因为需要使用DrawMode自行DrawItem,所以需要将DrawMode设置为OwnerDrawVarialbe或OwnerDrawFixed模式,代码如下: private void listB ...

  9. Redis 处理客户端连接的一些内部实现机制

    本文主要介绍了 Redis 处理客户端连接的一些内部实现机制,包括连接处理.超时.缓冲区等一系列内容. 注:本文所述内容基于 Redis2.6 及以上版本. 连接的建立 Redis 通过监听一个 TC ...

  10. 常用CSS技术收藏

    常用CSS技术收藏 必须要掌握的技术 盒子模型 定位模型 定位模型 css sprite(雪碧/css精灵)相关 css sprite 坐标定位为何为负以及定位方法 布局 圣杯布局小结 规范 BEM ...