本篇文章给大家谈谈linux如何扩容分区,以及linux扩容分区 gpt对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
1、linux修改分区的大小
; 很多朋友都想知道linux如何修改分区的大小?下面就一起来看看吧!
linux修改分区的大小
1、使用ssh远程连接工具登录到系统,使用fdisk-l命令查看磁盘状态。
2、输入fdisk/dev/hdb然后回车,给硬盘进行分区
3、输入n回车新建分区,接着再输入p回车新建主分区。
4、使用Firstcylinder(1-20805,default1)修改分区起始的柱面。
5、最后可以输入p命令查看分区是否修改成功。
本文章基于ThinkpadE15品牌、centos7系统撰写的。
2、linux之lvm分区扩容
以下步骤的前提为磁盘lvm分区
1、加入新硬盘
2、分区
PV(physical volume)即物理卷,就是物理磁盘,可以通过fdisk -l 查看操作系统有几块硬盘
VG(volume group)即卷组,就是一组物理磁盘的组合,里面可以有一块硬盘也可以有多块硬盘
LV(logical volume)及逻辑卷,就是在VG(指定的物理磁盘组)里面划分出来的
可以说成是PV就是硬盘,而VG就是管理硬盘的操作系统,而LV就是操作系统分出来的各个分区.
PV-VG-LV- 文件系统使用(挂载到某个目录)
对新磁盘/dev/sdb进行分区
[root@xt-prod-mydb02 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
(parted) mkpart
Partition name? []?
File system type? [ext2]? xfs
Start? 1
End? 10G
(parted) q
Information: You may need to update /etc/fstab.
创建物理卷 pvcreate /dev/sdb1
创建卷组 并将物理卷加入其中 vgcreate data /dev/sdb1 (data为卷组名)
创建逻辑卷组并分配大小 lvcreate -l +100%FREE -n lvdata data
格式化 mkfs.xfs /dev/mappper/data-lvdata
开机挂载新硬盘 vi /etc/fstab
挂载 mount -a (先建data目录 mkdir /data)
查看 df -lh
卸载挂点 umount /dev/mapper/data-lvdata
3、扩容
磁盘/dev/sdb只分10个G。。还有10G没有分配。。所以继续进行分区
parted /dev/sdb
打印分区信息表可以看到有两个分区了。
创建物理卷 pvcreat /dev/sdb2
查看将要扩容的卷组信息 vgdisplay 可见可扩容大小为0
将物理卷扩展到卷组 #vgextend data /dev/sdb2 (此处‘cl’是卷组名称)
再次查看卷组信息 vgdisplay 可扩容空间变成10G
将卷组中空闲空间扩展到 /data #lvextend -l +100%FREE /dev/mapper/data-lvdata
.刷新文件系统是扩容生效 #xfs_growfs /dev/mapper/data-lvdata
查看结果 :df -lh 扩容成功
3、怎么给linux分区扩大容量'
这里以Red hat AS4 为例。当磁盘分区发现不够用时,能想道的第一个做法就是增加分区大小。但是一般Linux如果没有采用逻辑卷管理,则动态增加分区大小很困难,一个能想道的办法就是,备份分区文件系统数据,删除分区,然后再重新创建分区,恢复备份的文件系统,这个做法比较玄,可能删除分区后导致系统无法启动。
第二个做法就是,创建一个新的逻辑分区(当然必须有未使用的磁盘空间能分配),将文件系统从老分区拷贝到新分区,然后修改fstab,使用新分区/文件系统替换老的分区/文件系统
第三种做法是,创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用。
这里采用的是第三种方式:
sdb为第二个SCSI硬盘。
[root@hdp0 hadoop]# /sbin/fdisk /dev/sdb
The number of cylinders for this disk is set to 8942.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
可以看出sdb1,2,3为主分区,sdb4为扩展分区。后面的sdb5,6,7则为逻辑分区。柱面编号(Start,End)是连续的,sdb7只用道了1173,而从扩展分区看最大到8942,也就是说,还有7769个柱面是空闲的,一个柱面大小为8225280,约为8M大小。还剩7769*8225280bytes,约62G未使用。
新增加一个逻辑分区(注:若涉及到主分区和扩展分区,实际情况可能比这个复杂,这里4个主分区(包括扩展分区)都分过了,所以只能分逻辑分区)
Command (m for help): n
First cylinder (1174-8942, default 1174):
Using default value 1174
增加大小为10G
Last cylinder or +size or +sizeM or +sizeK (1174-8942, default 8942): +10240M
增加后看一下,多了一个逻辑分区/dev/sdb8
Command (m for help): p
Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
/dev/sdb8 1174 2419 10008463+ 83 Linux
可以看到,增加了一个sdb8的分区,柱面号从1174到2419.
写入分区表,执行分区操作
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
分区完后,是看不到文件系统的
[root@hdp0 hadoop]# df -m
Filesystem 1M-块 已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var
重启机器
reboot
格式化文件系统
[root@hdp0 hadoop]#/sbin/mkfs.ext3 /dev/sdb8
mount文件系统,/home/develop 为/home下一目录
[root@hdp0 hadoop]#mount /dev/sdb8 /home/develop
查看文件系统,可以看到新建立的分区/文件系统已经挂载上,能够使用了。
[root@hdp0 hadoop]# df -m
Filesystem 1M-块 已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var
/dev/sdb8 9621 54 9079 1% /home/develop
4、linux如何扩展主分区
这里以Red hat AS4 为例。当磁盘分区发现不够用时,能想道的第一个做法就是增加分区大小。但是一般Linux如果没有采用逻辑卷管理,则动态增加分区大小很困难,一个能想道的办法就是,备份分区文件系统数据,删除分区,然后再重新创建分区,恢复备份的文件系统,这个做法比较玄,可能删除分区后导致系统无法启动。
第二个做法就是,创建一个新的逻辑分区(当然必须有未使用的磁盘空间能分配),将文件系统从老分区拷贝到新分区,然后修改fstab,使用新分区/文件系统替换老的分区/文件系统
第三种做法是,创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用。
这里采用的是第三种方式:
sdb为第二个SCSI硬盘。
[root@hdp0 hadoop]# /sbin/fdisk /dev/sdb
The number of cylinders for this disk is set to 8942.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
可以看出sdb1,2,3为主分区,sdb4为扩展分区。后面的sdb5,6,7则为逻辑分区。柱面编号(Start,End)是连续的,sdb7只用道了1173,而从扩展分区看最大到8942,也就是说,还有7769个柱面是空闲的,一个柱面大小为8225280,约为8M大小。还剩7769*8225280bytes,约62G未使用。
新增加一个逻辑分区(注:若涉及到主分区和扩展分区,实际情况可能比这个复杂,这里4个主分区(包括扩展分区)都分过了,所以只能分逻辑分区)
Command (m for help): n
First cylinder (1174-8942, default 1174):
Using default value 1174
增加大小为10G
Last cylinder or +size or +sizeM or +sizeK (1174-8942, default 8942): +10240M
增加后看一下,多了一个逻辑分区/dev/sdb8
Command (m for help): p
Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522 8942 67641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 652 1173 4192933+ 83 Linux
/dev/sdb8 1174 2419 10008463+ 83 Linux
可以看到,增加了一个sdb8的分区,柱面号从1174到2419.
写入分区表,执行分区操作
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
分区完后,是看不到文件系统的
[root@hdp0 hadoop]# df -m
Filesystem 1M-块 已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var
重启机器
reboot
格式化文件系统
[root@hdp0 hadoop]#/sbin/mkfs.ext3 /dev/sdb8
mount文件系统,/home/develop 为/home下一目录
[root@hdp0 hadoop]#mount /dev/sdb8 /home/develop
查看文件系统,可以看到新建立的分区/文件系统已经挂载上,能够使用了。
[root@hdp0 hadoop]# df -m
Filesystem 1M-块 已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 494 11 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 494 87 382 19% /var
/dev/sdb8 9621 54 9079 1% /home/develop
5、linux系统标准分区如何扩容
硬盘快满了,加硬盘扩容,不管是独立的服务器,还是云空间新买的硬盘,扩容方式一样。下面以阿里VPS为例,详细说一下,挂载硬盘扩容的2种方法。
阿里VPS,个人觉得有以下二个方面需要改进
1,默认不是lvm,所以系统盘/dev/xvda1是不能扩容的,所以如果有大数据的东西,一开始就要考虑到扩容的问题。数据量越大,操作风险越大。
2,不能实现无缝扩容,也就是说,在后台扩容一下,不用登录到VPS,进行调整。非专业人士,扩容困难
关于linux如何扩容分区和linux扩容分区 gpt的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。