Format ssd in Linux

In this tutorial, we go through the steps to format a Solid State Drive (SSD) on a Linux system. This can be done via GUI or command line, and we will cover the process for both. The guide will be applicable regardless of what Linux distribution you’ve decided to use, especially the command line method.

This will wipe all the data from your SSD disk and get it ready for use under Linux or another system. This method can also be used to securely wipe all data from your drive.

In this tutorial you will learn:

  • How to format a solid state drive in Linux via GUI
  • How to format a solid state drive in Linux via command line
Format ssd in Linux
Format ssd in Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software fdisk
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to format a solid state drive in Linux via GUI



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

DID YOU KNOW?
If your intention is to use the solid state drive as a primary disk for a Linux installation, then no partitioning is required as any decent Linux operating system will do the job for you during the installation process.

Depending on what Linux distribution you are using, the screenshots below may not match up with exactly what you see on your own screen. We are using Ubuntu Linux in these steps and the GNOME desktop environment, but the process should be mostly the same no matter what distro you are on. The key point is that you will need to find and open your operating system’s disk utility software.

  1. Get started by opening your system’s disk management application.

    Open the disk utility software from the application launcher
    Open the disk utility software from the application launcher
  2. You should see your solid state drive listed among the other storage devices on your system. Make sure you select the one that you wish to format.

    The disk is listed among the other storarge devices on the system
    The disk is listed among the other storarge devices on the system
  3. You will have several options on what to do with this drive. Click the one that says “Format Disk” or something similar.

    Select to format disk
    Select to format disk
  4. On our test system, we have a few different options for erasing and partitioning our solid state drive. A quick format will not securely erase the current data on the disk but it will perform the formatting very quickly, as the name implies. The other option is to rewrite the disk with all zeros (not necessary in the majority of situations). You can also create a MBR or GPT table, or apply no partitioning. If you are not sure, just leave the defaults selected and click “Format.”

    Choose formatting options
    Choose formatting options
  5. As mentioned earlier in the guide, this process will completely erase the contents in your solid state drive. The formatting software warns us once again to make sure we are aware, then it wipes the drive completely.

    Confirmation box about wiping the solid state drive
    Confirmation box about wiping the solid state drive

That’s all there is to it. If you chose the quick format option, the whole process should only take a matter of seconds. If you woud like to learn how to do this via command line, which is more universal across all Linux systems, we cover that in the next section.

How to format a solid state drive in Linux via command line




Open a terminal and type the following commands to format your solid state drive:

  1. First, let’s figure out how to identify the solid state drive we wish to format. The name should start with /dev/sd and then a letter. Type the following command in terminal to see:
    $ sudo fdisk -l
    

    Find your device name in the fdisk output
    Find your device name in the fdisk output
  2. In our example, the solid state drive has been assigned /dev/sdb device path. To create a new partition on the empty disk, we’ll provide it as argument to fdisk:
    $ sudo fdisk /dev/sdX
    
  3. The fdisk utility awaits our commands. We would like to create a new partition, so we press “n”.
    Command (m for help): n
    
  4. We are to create a primary partition, so the answer to the next question is “p”.
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    
  5. The next questions are about partition number, first and last sector, which will determine the actual size of the partition. In our example we are creating a single partition that will cover the disk, and default values are first partition, first available sector to start, and last sector to end with, which is just what we need. So we’ll accept the defaults for these questions.
    Partition number (1-4, default 1): 
    First sector (2048-104857599, default 2048): 
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-104857599, default 104857599): 
    
    Created a new partition 1 of type 'Linux' and of size 50 GiB.
    



  6. The partition is now complete, but as the utility points out on start, the changes are in-memory only until we write them out to the disk. This is on purpose and the warning is in place for a good reason: by writing out the changes to the disk, we destroy anything that resided on the sector range we cover with our new partition. We are sure there will be no data loss, so we write the changes to disk:
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    We are finished partitioning the solid state drive with fdisk utility
    We are finished partitioning the solid state drive with fdisk utility
  7. Next, we still need to add a file system to our solid state drive. Our new partition is under the device path of /dev/sdb1 (use fdisk -l command to see your own). Use the mkfs command to format the disk with any file system you would like. In this example, we are using ext4, which is the recommended file system for an SSD on Linux:
    $ sudo mkfs -t ext4 /deb/sdX1
    

    Formatting our solid state drive with the ext4 file system
    Formatting our solid state drive with the ext4 file system
  8. We will now use the mount command to mount the newly formatted partition on our system. We will mount our solid state drive to the /media/ssd directory.
    $ sudo mkdir -p /media/ssd
    $ sudo mount /dev/sdb1 /media/ssd
    



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


That’s all there is to it. You can now access your newly formatted solid state drive under the /mount/ssd directory or where ever you decided to mount it. To make the drive get mounted automatically, see our guide on configuring the /etc/fstab file.

Closing Thoughts

In this tutorial, we saw how to format a solid state drive on a Linux system. We used the ext4 file system to complete the job, which is the recommended configuration that you use for optimal performance. The GUI method of formatting a solid state drive proves a bit easier, as the program does some of the legwork for us. However, manually formatting a drive from the command line gives us more control and really isn’t that hard either.



Comments and Discussions
Linux Forum