Linux disk commands are important for formatting, modifying partitions, troubleshooting SATA issues, and interpreting system data. Because Linux is so reliant on use commands, the fdisk utility is a valuable tool for identifying partitions, creating new partitions, and setting up the disk the way that you want. In this article, we will discuss the significance of fdisk for Ubuntu systems and some of the basic commands that can be used when you are evaluating the SATA drives in your machine.
Fdisk stands for “format disk” or “fixed disk” and is a command-line based utility for modifying and diagnosing the drives in a Linux/Unix system. This is most helpful for when you need to modify a Linux partition command.
It is important to understand which Ubuntu partition type you want when you are using the Ubuntu format disk utility. You can use fdisk commands to view, resize, delete, copy, change, resize or move partitions, all using a text-based interface, but you can only use it to create a maximum of four new primary partitions and a variable number of logical partitions based on the size of your drive.
For example, you can use commands to find Linux hard disk info like listing all the partitions, or listing specific devices:
- List All: sudo fdisk –l
- List specific device: sudo fdisk –l /dev/sda
Notice that each of these commands has “sudo” in front of it. In order for you to make use of the fdisk utility, you must be accessing it from a root account in Linux, and we will cover that in more detail in the next section.
SATA Fdisk errors
One of the most common errors you are likely to encounter when running fdisk commands in Ubuntu is “Command not found” which can be very frustrating, particularly when you need to use these commands to get information on your hard disk drives.
One of the most common reasons that you could encounter a “command not found” error is if you are not accessing the command from an administrator authority, which you can only do if you use the “sudo” or “su” commands which we discuss in the next segment.
Sudo vs Su:
Using these commands in Linux is the “root” account, which is very similar to right clicking and running programs as an administrator in Windows.
If you are using Ubuntu, Linux Mint, or other Ubuntu-derived distributions, then every fdisk and mkfs command you enter must be prefixed by “sudo” for it to work. For Linux distributions which do not use “sudo” then you have to use the “su” command to enter a root shell (think of this like a Windows command prompt) and then once you are there you can enter all the commands without having to enter “sudo” first.
You have to be a root user in Linux in order to run fdisk commands. If you are not a root user and attempt to enter these commands, then you will get a “Command not found” error.
If you have a SATA hard drive running with a Linux operating system and have never experienced issues before, then consider the following:
- Linux Kernel
- Live CD
- SATA mode in BIOS
If you are running into SATA fdisk issues, make sure you have the latest version of the Linux kernel installed. If you have an older version of the kernel then there is the possibility you will have issues trying to run your commands. Likewise, make sure you have all the appropriate product updates, software and security patches installed so that all the available applicable code is on your machine.
If you are running your fdisk utility from a LiveCD, make sure you have all the drivers and chipsets necessary for operation on your machine. Not all of the drivers and chipsets are on the LiveCD by default, and some added customization may be required if you cannot see your drives when you are using the fidsk utility.
If fdisk on your version of Linux does not see your SATA disk, the most likely reason is that you do not have the right drivers.
SATA mode in BIOS:
If you have the option to change your SATA mode in your BIOS, made sure it is set to AHCI (Advanced Host Controller Interface) mode and not IDE (Integrated Drive Electronics). Integrated Drive Electronics will give you the greatest compatibility with older systems because it is considered the “old” version of AHCI, without the ability for hot-plugging and native command queueing.
Advanced Host Controller Interface is a hardware mechanism that allows your computer software to communicate with SATA (serial ATA) drives. SATA, or serial ATA, is the replacement for PATA or parallel ATA. As long as you are running the latest version of the Linux kernel, you will be able to use the AHCI mode when working with your SATA drives.
Sfdisk is very similar to Fdisk, but with more features. Fdisk is the most commonly used command for checking partitions on a drive, but it will not report the Linux partition size. For something like that, you need to use the sfdisk utility.
Sfdisk is another utility available from Linux with a purpose similar to the fdisk and has a feature to display the Linux partition size in megabytes. Sfdisk is part of the util-linux package you can download from the internet, or you can install it by running the following command: sudo apt-get install util-linux.
If you encounter an error after installing util-linux which includes this improved sfdisk utility, then you may need to troubleshoot and clean up your linux packages.
Linux Partition types:
There are two main types of partitions in a Linux system:
- Data partition – This is normal Linux system data, including the root partition containing all the data to boot and run the Linux system.
- Swap partition – An expansion of the computer’s physical memory, allowing for extra memory on the hard disk. This space is hidden from normal view, but is also the reason that you will hardly ever encounter an error in Linux telling you “out of memory”
The partition type is also known as the “system ID” and when you use the fdisk utility to mount a drive in linux and create a new partition it will usually default to the standard Linux partition type, or the “Data” partition type.
There are various linux format disk commands you can use including
p (as in print) to see the current existing partitions
n (as in new) to create a new partition
t (as in type) to change the type of the partition
Changing a partition type:
In order to change the partition type, you must enter the command mode and type “t” for changing the type, and then you have to specify the partition’s number. In order to modify the partition you need its number, and you can find it with the hex code of the type. L will let you view a list of the hex codes.
Changing the type of the partition does not automatically format it with the file system you select. You will have to make those modifications later with the corresponding mkfs command and specifying the partition you want to modify.
Because Linux is an operating system which allows for a high degree of user customization through the use of command line interface, there are a number of codes you can use to create partitions, change the type of the partitions, see the size of an existing partition, and troubleshoot issues with your SATA drives.
If you are encountering errors with your SATA drive after it is mounted, you may have to take a look at the codes you are using in your fdisk or sfdisk utility, or download a utility package from the internet that will allow you to better understand the errors you are seeing and provide you with the ability to modify your drives as necessary.
The main goal of this site has always been to provide accurate, understandable and easy to find information regarding Internet Technology.