Showing posts with label parted. Show all posts
Showing posts with label parted. Show all posts

parted partition alignment

I just tested in a vm with centos 6.7:
# parted /dev/sdb 
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label                                  
(parted) mklabel gpt                                                      
(parted) mkpart primary 1m 100%
(parted) quit                                                             
Information: You may need to update /etc/fstab.                           

[root@localhost ~]# parted /dev/sdb print 
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1073MB  1072MB               primary

[root@localhost ~]# parted /dev/sdb "unit s print"
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 2097152s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End       Size      File system  Name     Flags
 1      2048s  2095103s  2093056s               primary

parted extend the expanded disk

root@server:# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print free                                                  
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start End Size File system  Name Flags
2   17.4kB  1049kB 1031kB                  bios_grub
1   1049kB  25.8GB 25.8GB  zfs
    25.8GB  25.8GB 3584B   Free Space
3   25.8GB  36.5GB 10.7GB  zfs
4   36.5GB  47.2GB 10.7GB  zfs
5   47.2GB  1100GB 1052GB  zfs
9   1100GB  1100GB 8392kB
    1100GB  2199GB 1100GB  Free Space

(parted) mkpart
Partition name?  []? <you can leave it blank>                                           
File system type?  [ext2]? zfs                                       
Start? 1100GiB                                                       
End? 100%                                                            
(parted) print                                                       
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start End Size File system  Name Flags
2   17.4kB  1049kB 1031kB                  bios_grub
1   1049kB  25.8GB 25.8GB  zfs
3   25.8GB  36.5GB 10.7GB  zfs
4   36.5GB  47.2GB 10.7GB  zfs
5   47.2GB  1100GB 1052GB  zfs
9   1100GB  1100GB 8392kB
6   1181GB  2199GB 1018GB  zfs # this is the new one created

(parted) quit
Information: You may need to update /etc/fstab.


UEFI/GPT examples

In every instance, a special bootable EFI System Partition is required.
If creating a new EFI System Partition, use the following commands (the recommended size is 512MiB):
(parted) mkpart ESP fat32 1MiB 513MiB
(parted) set 1 boot on
The remaining partition scheme is entirely up to you. For one other partition using 100% of remaining space:
(parted) mkpart primary ext4 513MiB 100%
For separate / (20GiB) and /home (all remaining space) partitions:
(parted) mkpart primary ext4 513MiB 20.5GiB
(parted) mkpart primary ext4 20.5GiB 100%
And for separate / (20GiB), swap (4GiB), and /home (all remaining space) partitions:
(parted) mkpart primary ext4 513MiB 20.5GiB
(parted) mkpart primary linux-swap 20.5GiB 24.5GiB
(parted) mkpart primary ext4 24.5GiB 100%

Case vmware expanded

There's a difference between rescanning for new disks at the adapter level and rescanning for update size information at the disk level.
echo "- - -" > /sys/class/scsi_host/host#/scan
Sending "- - -" to /sys/class/scsi_host/host[012]/scan is telling the SCSI host adapter to look for new disks on every channel "(-)", every target "(-)", and every lun "(-)". - this is the right thing to do if you add a new disk to the system while it's powered on.
echo “1” > /sys/class/block/sdc/device/rescan
Sending a "1" to /sys/class/block/sdc/device/rescan is telling the SCSI block device to refresh it's information about where it's ending boundary is (among other things) to give the kernel information about it's updated size. - this is the right thing to do if you change the size of an existing disk while it's powered on.



Came back to using parted again today and this is how to properly create a partition using parted and getting rid of the alignment error:

Code:
root@loadtest01:~# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt                                                      
(parted) mkpart                                                           
Partition name?  []? primary                                        
File system type?  [ext2]? linux-swap                                    
Start? 0%                                                                 
End? 100%                                                                 
(parted) print                                                            
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start End     Size File system  Name Flags
1      1049kB 17.2GB  17.2GB     primary

(parted) align-check                                                      
alignment type(min/opt)  [optimal]/minimal? optimal                       
Partition number? 1                                                       
1 aligned