主机: CentOS release 6.4 (Final)

目的:从/home分区分出100G来创建新分区/vm

参考

http://ryanclouser.com/?p=66

http://falstaff.agner.ch/2013/12/22/online-resize-root-filesystem-on-a-gpt-partition/

http://blog.zepsikopat.net/2011/07/22/resize-an-ext4-partition-on-a-gpt-disk/

http://superuser.com/questions/660309/live-resize-of-a-gpt-partition-on-linux

1. 查看当前分区情况

[root@tanghuimin
/]# df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda3 ext4 9.7G 6.6G 2.6G 72% /

tmpfs tmpfs 1.8G 280K 1.8G 1% /dev/shm

/dev/sda1 ext4 426G 37G 368G 10% /home

/dev/sda2 ext4 20G 4.2G 15G 23% /opt

/home分区在/dev/sda1.

2. gdisk /dev/sda

?: 打印gdisk下命令的用法

p: 查看分区表

b:
备份分区表,以便后面操作失误可以恢复分区表

[root@tanghuimin
~]# gdisk /dev/sda

GPT fdisk (gdisk) version 0.8.10

Partition table scan:

MBR: protective

BSD: not present

APM: not present

GPT: present

Found valid GPT with protective MBR; using GPT.

Command (?
for help): ?

b back up GPT data to a file

c change a partition's name

d delete a partition

i show detailed information on a partition

l list known partition types

n add a new partition

o create a new empty GUID partition table (GPT)

p print the partition table

q quit without saving changes

r recovery and transformation options (experts only)

s sort partitions

t change a partition's type code

v verify disk

w write table to disk and exit

x extra functionality (experts only)

? print this menu

Command (?
for help): p

Disk /dev/sda: 976773168 sectors, 465.8 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): FB42D8BC-9B54-4B3B-A16C-A39A39B902FF

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 976773134

Partitions will be aligned on 2048-sector boundaries

Total free space is 2029 sectors (1014.5 KiB)

Number Start (sector) End (sector) Size Code Name

1 2048 907141119 432.6 GiB 0700

2 907141120 948101119 19.5 GiB 0700

3 948101120 968581119 9.8 GiB EF00

4 968581120 976773119 3.9 GiB 8200

Command (?
for help): b

Enter backup filename to save: /root/gpt.sda.bak

The operation has completed successfully.

3. 卸载即将被调整的分区/home

[root@tanghuimin
~]# umount /home/

[root@tanghuimin ~]# df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda3 ext4 9.7G 6.6G 2.6G 72% /

tmpfs tmpfs 1.8G 296K 1.8G 1% /dev/shm

/dev/sda2 ext4 20G 4.2G 15G 23% /opt

4. 检测文件系统错误

[root@tanghuimin
~]# e2fsck -f /dev/sda1

e2fsck 1.41.12 (17-May-2010)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/sda1: 268432/28352512 files (0.1% non-contiguous),
11359488/113392384 blocks

5. resize2fs调整文件系统大小

[root@tanghuimin
~]# resize2fs /dev/sda1 326G

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on /dev/sda1 to 85458944 (4k) blocks.

The filesystem on /dev/sda1 is now 85458944 blocks long.

6. gdisk调整分区大小,先用d删除分区,后用n创建分区

[root@tanghuimin ~]# gdisk /dev/sda

GPT fdisk (gdisk) version 0.8.10

Partition table scan:

MBR: protective

BSD: not present

APM: not present

GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p

Disk /dev/sda: 976773168 sectors, 465.8 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): FB42D8BC-9B54-4B3B-A16C-A39A39B902FF

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 976773134

Partitions will be aligned on 2048-sector boundaries

Total free space is 2029 sectors (1014.5 KiB)

Number Start (sector) End (sector) Size Code Name

1 2048 907141119 432.6 GiB 0700

2 907141120 948101119 19.5 GiB 0700

3 948101120 968581119 9.8 GiB EF00

4 968581120 976773119 3.9 GiB 8200

Command (?
for help): d

Partition number (1-4): 1

Command (? for help): p

Disk /dev/sda: 976773168 sectors, 465.8 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): FB42D8BC-9B54-4B3B-A16C-A39A39B902FF

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 976773134

Partitions will be aligned on 2048-sector boundaries

Total free space is 907141101 sectors (432.6 GiB)

Number Start (sector) End (sector) Size Code Name

2 907141120 948101119 19.5 GiB 0700

3 948101120 968581119 9.8 GiB EF00

4 968581120 976773119 3.9 GiB 8200

Command (?
for help): n

Partition number (1-128, default 1):

First sector (34-976773134, default = 2048) or {+-}size{KMGTP}:

Last sector (2048-907141119, default = 907141119) or
{+-}size{KMGTP}: 326G

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300):

Changed type of partition to 'Linux filesystem'

Command
(? for help): w

Final checks complete. About to write GPT data. THIS WILL
OVERWRITE EXISTING

PARTITIONS!!

Do you want to proceed? (Y/N): y

OK; writing new GUID partition table (GPT) to /dev/sda.

Warning: The kernel is still using the old partition table.

The new table will be used at the next reboot.

The operation has completed successfully.

分区大小调整完毕。

7. /dev/sda1挂载到/home

[root@tanghuimin ~]# df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda3 ext4 9.7G 6.6G 2.6G 72% /

tmpfs tmpfs 1.8G 296K 1.8G 1% /dev/shm

/dev/sda2 ext4 20G 4.2G 15G 23% /opt

[root@tanghuimin
~]# mount /dev/sda1 /home/

[root@tanghuimin ~]# df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda3 ext4 9.7G 6.6G 2.6G 72% /

tmpfs tmpfs 1.8G 296K 1.8G 1% /dev/shm

/dev/sda2 ext4 20G 4.2G 15G 23% /opt

/dev/sda1 ext4 321G 37G 269G 12% /home

reboot.

8. /dev/sda所有free的空间上创建新分区

[root@tanghuimin ~]# gdisk /dev/sda

GPT fdisk (gdisk) version 0.8.10

Partition table scan:

MBR: protective

BSD: not present

APM: not present

GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p

Disk /dev/sda: 976773168 sectors, 465.8 GiB

Logical sector size: 512 bytes

Disk identifier (GUID): FB42D8BC-9B54-4B3B-A16C-A39A39B902FF

Partition table holds up to 128 entries

First usable sector is 34, last usable sector is 976773134

Partitions will be aligned on 2048-sector boundaries

Total free space is 221374444 sectors (105.6 GiB)

Number Start (sector) End (sector) Size Code Name

1 2048 685768704 327.0 GiB 8300 Linux
filesystem

2 907141120 948101119 19.5 GiB 0700

3 948101120 968581119 9.8 GiB EF00

4 968581120 976773119 3.9 GiB 8200

Command (?
for help): n

Partition number (5-128, default 5):

First sector (34-976773134, default = 685770752) or
{+-}size{KMGTP}:

Last sector (685770752-907141119, default = 907141119) or
{+-}size{KMGTP}:

Current type is 'Linux filesystem'

Hex code or GUID (L to show codes, Enter = 8300):

Changed type of partition to 'Linux filesystem'

Command (?
for help): w

Final checks complete. About to write GPT data. THIS WILL
OVERWRITE EXISTING

PARTITIONS!!

Do you want to proceed? (Y/N): y

OK; writing new GUID partition table (GPT) to /dev/sda.

Warning: The kernel is still using the old partition table.

The new table will be used at the next reboot.

The operation has completed successfully.

9. 将新分区的文件系统类型设为ext4

[root@tanghuimin
~]# mkfs -t ext4 /dev/sda5

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=1 blocks, Stripe width=0 blocks

6922240 inodes, 27671296 blocks

1383564 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

845 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632,
2654208,

4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts
or

180 days, whichever comes first. Use tune2fs -c or -i to
override.

10. 将新分区/dev/sda5挂载到/vm

[root@tanghuimin
~]# mount /dev/sda5 /vm

[root@tanghuimin ~]# df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda3 ext4 9.7G 6.6G 2.6G 72% /

tmpfs tmpfs 1.8G 224K 1.8G 1% /dev/shm

/dev/sda1 ext4 321G 37G 269G 12% /home

/dev/sda2 ext4 20G 4.2G 15G 23% /opt

/dev/sda5 ext4 104G 188M 99G 1% /vm

11.
/etc/fstab中添加如下行,使在系统启动时/dev/sda5被挂载到/vm

/dev/sda5 /vm ext4 defaults 1
2

reboot.

用gdisk调整gpt/ext4分区大小的更多相关文章

  1. Linux调整lvm逻辑分区大小

    转载自:https://www.cnblogs.com/kevingrace/p/5825963.html  个人记录一下   Linux下对lvm逻辑卷分区大小的调整(针对xfs和ext4不同文件系 ...

  2. 调整分区大小(ext2\ext3\ext4)

    现在的时间是2017年5月27日 我想说调整分区大小没那么麻烦,至少我直接将一个ext3格式分区从50G减少到了30G. 步骤如下 1 首先确保那个分区是没被挂载的. 2 调整分区大小,但是其实并没有 ...

  3. 在不损坏数据的情况下调整分区大小(ext2\ext3\ext4)

    现在的时间是2017年5月27日 我想说调整分区大小没那么麻烦,至少我直接将一个ext3格式分区从50G减少到了30G. 步骤如下 1 首先确保那个分区是未挂载的. 2 调整分区大小,但是其实并没有实 ...

  4. UEFI+GPT模式下的Windows系统中分区结构和默认分区大小及硬盘整数分区研究

    内容摘要:本文主要讨论和分析在UEFI+GPT模式下的Windows系统(主要是最新的Win10X64)中默认的分区结构和默认的分区大小,硬盘整数分区.4K对齐.起始扇区.恢复分区.ESP分区.MSR ...

  5. 83 parrted-分区和分区大小的调整

    parted命令是由GNU组织开发的一款功能强大的磁盘分区和分区大小调整工具,与fdisk不同,它支持调整分区的大小.作为一种设计用于Linux的工具,它没有构建成处理与fdisk关联的多种分区类型, ...

  6. Cenots7对lvm逻辑卷分区大小的调整

    Cenots7对lvm逻辑卷分区大小的调整 (针对xfs和ext4不同文件系统) 1.支持的文件系统类型 特别注意的是: resize2fs命令            针对的是ext2.ext3.ex ...

  7. linux虚拟机磁盘扩展与分区大小调整

    有段时间觉得linux虚拟机上的磁盘不太够用,研究了下其磁盘扩展 1.linux虚拟机磁盘扩展 step1. 先关机在编辑虚拟机中,找到硬盘选项增加空间,进行扩展step2. 进入root fdisk ...

  8. Linux磁盘分区(四)之分区大小调整

    Linux磁盘分区(四)之分区大小调整在学习调整分区大小之前,先了解linx分区的概念.参考如下博客:[1]linux 分区 物理卷 逻辑卷 https://www.cnblogs.com/liuch ...

  9. 调整Linux磁盘分区的大小的方法

      昨天数据入库时,一直报错,说磁盘满了,,df -h    一看,发现/目录下只有50G空间,已使用49G:我的程序和dbss都安装在/目录下,ftp到的数据放在/data下的一个子目录下,分解完的 ...

随机推荐

  1. kohana nginx的配置

    kohana nginx的配置 location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php? kohana_uri=/$1 ...

  2. STL源代码分析--第二级空间配置器

    本文解说SGI STL空间配置器的第二级配置器. 相比第一级配置器,第二级配置器多了一些机制,避免小额区块造成内存的碎片.不不过碎片的问题,配置时的额外负担也是一个大问题.由于区块越小,额外负担所占的 ...

  3. layui-简单辅助元素 - 页面元素

    本篇主要集中罗列页面中的一些简单辅助元素,如:引用块.字段集区块.横线等等,这些元素都无需依赖任何模块 <!DOCTYPE html> <html> <head> ...

  4. Key-Value键值存储原理初识(NOSQL)

    NO-Sql数据库:Not Only不仅仅是SQL 定义:非关系型数据库:NoSQL用于超大规模数据的存储.(例如谷歌或Facebook每天为他们的用户收集万亿比特的数据).这些类型的数据存储不需要固 ...

  5. 一起学android之怎样设置TextView中不同字段的字体颜色(22)

    在这里先看看效果图: OK,有时候,在我们的项目中会要求TextView中文本有一部分的字体颜色不一样.这时我们应该使用 SpannableStringBuilder这个工具类,当然这个类的功能非常强 ...

  6. ubuntu16.04 下安装opencv2.4.9

    准备工作,安装环境 sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-nump ...

  7. android开发系列之视频断点续传

    今天在这篇博客里面,我想说说自己在这几天遇到的一个棘手的问题,就是视频断点续传的问题.其实这在我们开发中是一个很常见的应用场景,比如视频.音频.pdf等相关的文档.如果之前没有接触过的话,你也许会被这 ...

  8. c# .net 关于接口实现方式:隐式实现/显式实现!

    以前在用到接口时,从来没注意到接口分为隐式实现与显示实现.昨天在浏览博客时看到相关内容,现在根据自己的理解记录一下,方便日后碰到的时候温习温习.  通俗的来讲,“显示接口实现”就是使用接口名称作为方法 ...

  9. c# .net 我的Application_Error 全局异常抓取处理

    protected void Application_Error(object sender, EventArgs e)        {            //在出现未处理的错误时运行的代码   ...

  10. 在hibernate3中如何利用HQL语句查询出对象中的部分数据并且返回该对象?

    例如现在有一个Customer对象 public class Customer{ private Integer cid; private String cname; private Integer ...