Use gdisk to adjust the size of the gpt/ext4 partition and gdiskgptext4 Partition

Source: Internet
Author: User
Tags apm hex code

Use gdisk to adjust the size of the gpt/ext4 partition and gdiskgptext4 Partition

Host: CentOS release 6.4 (Final)

Purpose: GB from the/home partition to create a new partition/vm

Reference:

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.View Current partition information

[Root @ tanghuimin/] # df-Th

Filesystem Type Size Used Avail Use % Mounted on

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

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

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

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

/Home partition in/dev/sda1.


2. gdisk/dev/sda

? : Print command usage in gdisk

P: View partition tables

B: Back up the partition table so that the partition table can be restored due to subsequent operation errors.

[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.Unmount the Shard to be adjusted/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 1.8G 296 K 1.8G 1%/dev/shm

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


4.Detect file system errors

[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.UseResize2fsResize a File System

[Root @ tanghuimin ~] # Resize2fs/dev/sda1 326G

Resize2fs 1.41.12 (17-May-2010)

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

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


6.UseGdiskAdjust the partition size. UseDDelete a partition and then useNCreate a partition

[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.

The partition size has been adjusted.


7.Set/Dev/sda1Mount/Home

[Root @ tanghuimin ~] # Df-Th

Filesystem Type Size Used Avail Use % Mounted on

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

Tmpfs 1.8G 296 K 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 1.8G 296 K 1.8G 1%/dev/shm

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

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

Reboot.


8.In/Dev/sdaAllFreeTo create a new partition.

[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.Set the file system type of the new partitionExt4

[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,983 04, 163840,229 376, 294912,819 200, 884736,160 5632,2654208,

4096000,796 2624, 11239424,204 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.Add new partition/Dev/sda5Mount/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 1.8G 224 K 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 188 M 99G 1%/vm


11.In/Etc/fstabTo enable/Dev/sda5Mounted/Vm

/Dev/sda5/vmext4defaults12

Reboot.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.