Creating ext4 partition from console

I have a volume /dev/sda1 (1.2 TB) containing an NTFS partition using 0.6 TB space.

I want to make an ext4 partition in the remaining 0.6 TB space.

I have not tried anything yet because I don't want to risk losing data if I hit a wrong command. (I cannot use gparted as I don't have GUI.)

Can you provide me with the correct command, or at least the right parameters for mkfs.ext4.

root@rasp:~# fdisk -l /dev/sda

Disk /dev/sda: 1500.3 GB, 1500299395072 bytes
255 heads, 63 sectors/track, 182401 cylinders, total 2930272256 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000303ee

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  2930272255  1465135104    7  HPFS/NTFS/exFAT

First of all you need to create a partition, then you can make the filesystem.

  1. Create a new partition

     sudo fdisk /dev/sda
    

This will bring up the fdisk menu. You should familiarize yourself with it, search for tutorials (here's one). The basic options are:

    Command action
       a   toggle a bootable flagL
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)

If all goes well, by pressing n, you will be given the option of creating a new partition in the empty space. If the only unallocated space is the one you want to use, the default choices should be fine and you can just let fdisk choose.

  1. Since you want to create an ext partition, you don't need to do anything. If you wanted to create a different type (swap or NTFS or whatever) you would need to use t to change the partition type. I am mentioning this just in case.

  2. Check that your changes are what you expected by hitting p to print the partition table.

  3. If everything is OK, write the new partition table to the disk (w) and exit (q).

Now that you have your new, empty partition, you can create its filesystem. So, if you just created /dev/sdaX (where X is the number of the partition you created, for example /dev/sda2), run this:

sudo mkfs.ext4 /dev/sdaX

The syntax is mkfs.ext4 *partition*

An example would be mkfs.ext4 /dev/sda2 where /dev/sda2 is the unformatted partition in question.

You can get information about your filesystem by executing lsblk or lsblk --fs for more information.

The last 2 partitions are empty and have no filesystems as yet:

root@augur:/# lsblk --fs --ascii 
NAME        FSTYPE LABEL MOUNTPOINT
mmcblk0                  
|-mmcblk0p1 vfat   boot  /boot
|-mmcblk0p2 ext4         /
|-mmcblk0p3              
`-mmcblk0p4