Monday 29 January 2018

Fdisk and parted - creating partitions larger then 2TB - SOLVED

In case you don't know what parted is then I can only assume that you never worked with disks larger then 2 TB. Good for you.

If you do know what parted is that I also can assume that you came across problems with fdisk and disks larger then 2TB.

So what is parted?

Simple answer to this question is just another disks partitioning tool. What is so special about parted? When using parted you can create partitions that are larger then 2TB. Why? Because. Don't get to techical about it.

Can you use parted for partitions smaller then 2TB? Yes, you can! Do you use parted for partitions smaller then 2TB if you don't have partitions larger then 2TB? I don't think so. Why? Answer is pretty simple. Big disks are still expensive.

Fdisk limitations for large partitions 


Fdisk limitation is that it can't create partitions larger then 2TB. 
Example: you have a disk sdb that is 3TB. Do all things that you need for creating new partion on it.

fdisk /dev/sdb
(new primary partition, number 1, first block on disk, last block on disk)

When you are finish with creating partition, list info about it

fdisk /dev/sdb1

You will see that is it only 2TB big. Even if you did select last block on disk, you can get partition bigger then 2TB.

 

Can I still make partitions larger then 2TB with fdisk?  


Well, you can but ... you will need to to use LVM and make some tricks.
How to do it? Pretty simple really. Let's show this in an example.

If you can 3TB disks on your server,let's say it is sdb, you first create one partition. Then create second partition on save disk. So you will have sdb1 and sdb2 partition that are in total 3TB large.

Now, implement LVM on them.

Create PV on them:
pvcreate /dev/sdb1
pvcreate /dev/sdb2

Check PV
# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda2  rootvg lvm2 a-    40.00g     0
  /dev/sdb2  data_vg lvm2 a-   2.00t     0
  /dev/sdb1  data_vg lvm2 a-   1.00t  0

 

Create VG on them:
vgcreate data_vg /dev/sdb1
vgextend data_vg /dev/sdb2

You must use extend for second disks because you can't have to VG with same name.

So when you execute vgs command, you will see something like this

 # vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  data_vg   2   1   0 wz--n- 3.00tg   0 

 rootvg   1   3   0 wz--n-  90.00g 28.00g

Now you can create LV on VG data_vg that is 3TB big.

lvcreate -L3T -n data_lv data_vg

 # lvs
  LV     VG     Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  data_lv data_vg -wi-ao 3.00T 

  rootlv rootvg -wi-ao  20.00g
  varlv  rootvg -wi-ao  10.00g
 
Rest is easy, create file system on /dev/mapper/data_lv and mount it somewhere.

 

Making all this with parted


Same disk - sdb

# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes 
(parted) mkpart primary 65535s 100% 
(parted) q
Information: You may need to update /etc/fstab.
# parted /dev/sdb print
Model: Unknown (unknown)
Disk /dev/sdb: 3299GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      33.6MB  3299GB  3298GB               primary 
 
And now you can create file system on sdb1 or you can create LVM on sdb1.