web analytics

Partitioning a new hard disk with parted

Fdisk is undoubtedly the most favorite disk partitioning tool for most linux savy peope. However fdisk has limitations when it comes to disk with space more than 2T. Redhat recommends parted now, starting from RHEL6. fdisk doesnt understand GUID partition table (GPT) and it is not suited for disk bigger than 2T. You will have to use a more advanced tool “parted” for that.

 

Let us see how a new 3T disk can be partitioned using parted command. I will be showing just 1 partition here, taking up all space rest can be done the same way. Normally, the disk will be labelled msdos, and you need to label it as GPT.

The list command will show you the current disks and their details.

[root@abc ~]# parted –list
Model: ATA ST33000650NS (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system     Name  Flags
5      1049kB  2097kB  1049kB                        bios_grub
1      2097kB  8592MB  8590MB  linux-swap(v1)
2      8592MB  9666MB  1074MB  ext3
3      9666MB  117GB   107GB   ext4
4      117GB   3001GB  2884GB  ext4

Model: ATA ST33000650NS (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

The disk which is new and which we are going to partition now is sdb which is a 3T disk. See the partition table which is msdos currently. Now, lets start partitioning. Here is a small description of what we will be doing, so that I can show all steps together.

  1. We will change the disk label on /dev/sdb from msdos to GPT.
  2. Then, for our easiness we are setting the unit to be used as TB. Otherwise we will have to calculate it in bytes which would be difficult.
  3. Now, we are going to create our first partition. Here I am using the entire space for this partition, hence I will be creating a primary partition of size 3T. We need to provide the starting and ending size along with partition.

[root@abc ~]# parted /dev/sdb
GNU Parted 2.1
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/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y

(parted) unit TB
(parted) mkpart primary 0.00TB 3.00TB
(parted) quit
Information: You may need to update /etc/fstab.

Now issue a parted list and see the new partition added there. It shows the size as 3000G which confirms that it is using the full disk.

[root@abc ~]# parted –list
Model: ATA ST33000650NS (scsi)
Disk /dev/sda: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system     Name  Flags
5      1049kB  2097kB  1049kB                        bios_grub
1      2097kB  8592MB  8590MB  linux-swap(v1)
2      8592MB  9666MB  1074MB  ext3
3      9666MB  117GB   107GB   ext4
4      117GB   3001GB  2884GB  ext4

Model: ATA ST33000650NS (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system     Name     Flags
1      1049kB  3001GB  3001GB  linux-swap(v1)  primary

Now we need to create a file system on this partition, just like the normal way.

[root@abc ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
183148544 inodes, 732566272 blocks
36628313 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
22357 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

That’s it and you can mount and use this partition as you like.

[root@abc ~]# mkdir /home2

[root@abc ~]# mount /dev/sdb1 /home2

Update /etc/fstab file with the new entry so that it will be automatically mounted when you reboot the machine.

 

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>