Thursday, April 6, 2017

Partitioning in Linux

Description:
  • This section shows you how to actually partition your hard drive with the fdisk utility. Linux allows only 4 primary partitions. You can have a much larger number of logical partitions by sub-dividing one of the primary partitions. Only one of the primary partitions can be sub-divided.
  • If partition size is more than 2 TB than you need to gdisk instead of fdisk. You need to convert from MBR to GPT you can do so (use caution with this) using gdisk.
Fdisk usage
  • fdisk is started by typing (as root) fdisk device at the command prompt. device might be something like /dev/hda or /dev/sda
  • The basic fdisk commands you need are:
  1. pprint the partition table
  2. ncreate a new partition
  3. ddelete a partition
  4. qquit without saving changes
  5. wwrite the new partition table and exit
  • Create New Partition on Linux
  1. Start a terminal.
  2. Start fdisk using the following command:
    # fdisk /dev/sda
  3. In fdisk, to create a new partition, type the following command:
    n
          1. When prompted to specify the Partition type, type p to create a primary partition or e to create an extended one. There may be up to four primary partitions. If you want to create more than four partitions, make the last partition extended, and it will be a container for other logical partitions
          2. When prompted for the Number, in most cases, type 3 because a typical Linux virtual machine has two partitions by default.
          3. When prompted for the Start cylinder, type a starting cylinder number or press Return to use the first cylinder available.
          4. When prompted for the Last cylinder, press Return to allocate all the available space or specify the size of a new partition in cylinders if you do not want to use all the available space.
          5. By default, fdisk creates a partition with a System ID of 83. If you're unsure of the partition's System ID, use the
            l
            Command to check it.
          6. Use the
            w
            Command to write the changes to the partition table.
             
  1. Create a file system on the new partition. We recommend that you use the same file system as on the other partitions. In most cases it will be either the Ext4 or ReiserFS file system. For example, to create the Ext4 file system, enter the following command:
    # mkfs.ext4 /dev/sda3
       Or
    # mkfs -t ext4 /dev/sda3
  2. Create a directory that will be a mount point for the new partition and mount partition in that directory. For example, to name it data, enter:
    # mkdir /data
    # mount /dev/sda3  /data
  3. Make changes in your static file system information by editing the /etc/fstab file in any of the available text editors. For example, add the following string to this file:
    /dev/sda3 /data ext4 defaults 0 0
    Save /etc/fstab file after making changes
Gdisk Usage:
  • Gdisk is use to create more than 2 TB partition because fdisk support up to 2 TB.
  • The basic fdisk commands you need are:
  1. pprint the partition table
  2. ncreate a new partition
  3. ddelete a partition
  4. qquit without saving changes
  5. wwrite the new partition table and exit
  • Method of create new partition will be same as fdisk.

No comments:

Post a Comment