Thursday, April 25, 2013

Parted : How to create partitions?


Important: This is not a definite guide. Use parted with caution and always have a backup before you modify anything. Improper use of parted may destroy all your data and I do not take any responsibility of that. You were warned.

Print available devices

[root@cmstorm home]# parted /dev/sda print devices
/dev/sda (2000GB)   - we will use this disk
/dev/sdb (500GB)
/dev/sdc (250GB)
/dev/sdd (1000GB)
/dev/mapper/vg_home-home (250GB)
/dev/mapper/luks-e78b92c8-26a5-415b-9f95-c56aa9e511ca (250GB)
/dev/mapper/vg_root-root (373GB)
/dev/mapper/vg_root-swap (18.9GB)


Display free space on a disk

[root@cmstorm home]# parted /dev/sda print free
Model: ATA WDC WD2002FAEX-0 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
        17.4kB  2000GB  2000GB  Free Space
 

Create or change the label if needed
 
(parted) mklabel
New disk label type?    - press Tab key twice here
aix    amiga  bsd    dvh    gpt    loop   mac    msdos  pc98   sun   
New disk label type? gpt
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes                                                              

(parted) print                                                           
Model: ATA WDC WD2002FAEX-0 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt    
Disk Flags:

Number  Start  End  Size  File system  Name  Flags



Create new partition(s)
 

(parted) mkpart
Partition name?  []? 1                                                   
File system type?  [ext2]?                                               
Start? 1                                                                 
End? 50%                                                                 
(parted) print                                                           
Model: ATA WDC WD2002FAEX-0 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  1000GB  1000GB  ext4         1

(parted) mkpart                                                          
Partition name?  []? 2                                                   
File system type?  [ext2]?                                               
Start? 50%
End? 100%                                                                
(parted) print                                                           
Model: ATA WDC WD2002FAEX-0 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  1000GB  1000GB  ext4         1
 2      1000GB  2000GB  1000GB               2

(parted) quit


Check partition alignment

[root@cmstorm home]# parted /dev/sda align-check
alignment type(min/opt)  [optimal]/minimal? optimal                      
Partition number? 1                                                      
1 aligned
[root@cmstorm home]# parted /dev/sda align-check
alignment type(min/opt)  [optimal]/minimal?                              
Partition number? 2                                                      
2 aligned
[root@cmstorm home]#


How to remove partition(s)

[root@cmstorm home]# parted /dev/sda
GNU Parted 3.0
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                           
Model: ATA WDC WD2002FAEX-0 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  1000GB  1000GB  ext4         1
 2      1000GB  2000GB  1000GB               2

(parted) rm 2
(parted) rm 1                                                            
(parted) print                                                           
Model: ATA WDC WD2002FAEX-0 (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted) quit


Tip: fdisk (util-linux 2.21.2) does not support GPT.

[root@cmstorm home]# fdisk -l /dev/sda
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


No comments:

Post a Comment