分享
 
 
 

用gdisk调整gpt/ext4分区大小

王朝学院·作者佚名  2016-05-26
窄屏简体版  字體: |||超大  

用gdisk调整gpt/ext4分区大小主机: 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): ?

bback up GPT data to a file

cchange a partition's name

ddelete a partition

ishow detailed information on a partition

llist known partition types

nadd a new partition

ocreate a new empty GUID partition table (GPT)

pprint the partition table

QQuit without saving changes

rrecovery and transformation options (experts only)

ssort partitions

tchange a partition's type code

vverify disk

wwrite table to disk and exit

xextra 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 WILLOVERWRITE 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 Linuxfilesystem

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 WILLOVERWRITE 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 mountsor

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

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/vmext4defaults12

reboot.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有