Pages

Tuesday, March 25, 2014

Parted Partitioning Tool


Parted Installation
-----------------------
You can install parted using yum
#yum -y install parted
How to Viewing the Current Partition Layout?
------------------------------------------------------------
You can use either 'p' or 'print' to view the current partition layout
[root@localhost ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
(parted)
Mklabel
-------------
NOTE: One of the major advantage over fdisk is, we can create huge partitions (2GB and more)
To accomplish this, you must use a gpt label (the GUID Partition Type) for your disk.
[root@localhost ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
NOTE: Changing the partition type will remove all partitions from your disk. All data on the disk
will be lost.
How to create an ext4 partition?
------------------------------------------
Create an ext4 parttion using the remaining space on a HDD
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512BPartition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
(parted) mkpart primary ext4 92.3GB -1s
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
After the reboot:
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
408GB primary
(parted)
How to create a swap parttion?
-------------------------------------
(parted) mkpart primary linux-swap 92.3GB 100G
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 100GB
(parted) quit
[root@localhost ~]#
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
7724MB primaryHow to convert to LVM partition?
--------------------------------------------
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
408GB primary
(parted) set 3 lvm on
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
After the reboot:
[root@localhost ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST3500418AS (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
408GB primary
lvm
(parted)
How to create RAID partition using parted?
--------------------------------------------------------
Create an ext4 for partition with the desired space and set the raid flag on it.
Creating the partition:
[root@localhost ~]# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 100GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
7724MB primary
(parted) mkpart primary ext4 100G -1s
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
(parted)
(parted)
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
92.3GB 100GB
4
100GB 500GB
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
7724MB primary
400GB primary
How to set the raid flag?
(parted) set 4 raid on
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource
busy). As a result, it may not reflect all of your changes until
after reboot.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
3
92.3GB 100GB 7724MB primary
4
100GB 500GB 400GB primary
raid
(parted)How to Remove a partition?
-------------------------------------
You can remove the parttion using the parttion number.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1
1049kB 83.9GB 83.9GB primary ext4
boot, raid
2
83.9GB 92.3GB 8389MB primary
raid
3
92.3GB 100GB 7724MB primary
4
100GB 500GB 400GB primary
(parted)
(parted) rm 3
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or
resource busy). As a result, it may not reflect all of your changes until
after reboot.
(parted) p
Model: ATA ST500DM002-1BC14 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End
1
1049kB 83.9GB
2
83.9GB 92.3GB
3
100GB 500GB
(parted)
Size Type File system Flags
83.9GB primary ext4
boot, raid
8389MB primary
raid
400GB primary

1 comments:

  1. is it possible to make a new partition in VPS (ovz) with parted ??
    I have 100GB I want to divide it to 20gb and 80gb.

    ReplyDelete