Useful Tips

Adding a new disk in Ubuntu


In a previous article, how to create partitions on a hard disk in Ubuntu, we examined. Now, to continue, we need to format the newly created partitions on the hard drive by installing the file system we need there.

The following is a way to format a disk in Ubuntu through the command line.

We use the team mkfs

Its simple format mkfs.file system device

For example, we need to format our / dev / sdd1 at ext4, to do this, run the following command:

To see what other file systems can be used, type mkfs and double-click the tab. It will output something like the following:

# mkfs (+2 TAB characters)
mkfs mkfs.ext2 mkfs.ext4dev mkfs.vfat
mkfs.bfs mkfs.ext3 mkfs.minix mkfs.xfs
mkfs.cramfs mkfs.ext4 mkfs.msdos

Some file systems such as the XFS mkfs command do not support by default; for this I had to deliver xfsprogs

So, we created the partitions, formatted the disk, now we need to mount it on our system. We read the given links how to do it :)

2. Partitioning the HDD in Ubuntu

To partition the disks, we will again use the program fdisk. We launch fdisk indicating the HDD on which to create the partition:

fdisk will start in command mode. To see a list of all available commands you need to enter m. But for our purposes only a few basic commands are needed:

p - view the current partition table of the disk,
n - create a new partition,
d - delete an existing partition,
w - write the partition table to disk and subsequent exit,
q - exit without writing a new table to the hard drive.

We check the presence of partitions on the disk with the command pif they are not, then create a new section with the command n. When creating a section, you will have to answer several questions, if you plan to create no more than 4 sections, then create the main section. Next, indicate the section number - 1. And at the end you need to specify the start and end cylinders of the section, you can simply click Enter, the program itself will ask everything. Again, check the list section and see the newly created section, which is indicated / dev / sdb1. Be sure to save the changes with the w command.

Formatting hard drives in Linux + mount

Sooner or later, anyone who switched to Linux, most often Ubuntu, is faced with the need to install, split, and format the disk in Linux.

All the steps to install a new disk described below - creating a partition, formatting and mounting the HDD were performed on Ubuntu Linux, but it is equally true for any other Linux distribution.

All the commands below are designed for a user who has superuser access to the file system - root or sudo.

Creating a partition on a hard disk in Linux

cfdisk - A utility for creating partitions on a Linux hard disk.
We start cfdisk, specifying the name of the drive we are going to work with:

Click on Newcreate a section. Choose Primary (main)

Create, click Bootableif you want it to be bootable. By the way, in Ubuntu, if this option is not selected, then it won’t go any further.

Push Write and write yes

As already mentioned, creating a partition in Linux is quite simple, and it has just been done. Everything, sections are created, exit the program, choosing Quit.
If you need to re-partition partitions on a used disk without wasting time deleting existing ones, you can run cfdisk with a key -z :

Parameter -z creates a zero partition table, and allows you to immediately start forming a new one.

You can also use the utility to create and delete rezdels on your hard drive. parted, and in the GNOME environment its graphical version gparted.

Formatting a disk or partition in Linux

First you need to decide what is the linux file system more suitable for a specific task.

- Ext4: journaling file system used by Linux. It is based on the ext3 file system, which is the default file system on many Linux distributions.

Ext3: a reliable, tested and repeatedly tested file system of Linux systems does not set speed records, in most cases it is the best choice.

Xfs: The best choice for file storages, especially huge files (iso-images of distributions and movies).

So, create a file system:

mkfs -t where

- one of the types available to the system, for example ext4, ext3, jfs, xfs ...

- The name of the formatted partition, for example / dev / sdb1. In our example, it looks like this:

sudo mkfs -t ext4 / dev / sdb1

Something like this will happen on the screen:

For drives up to 150GB, the process takes several minutes. For large disks (a few Terabytes), the process first goes fast, then it slows down and continues at a constant speed.

Disk mount

After formatting, the partition can be mounted and used right away. Create a mount point (directory on disk):

mkdir / photos

and give the directory full rights:

chmod 770 / photos

mount -t ext4 / dev / sdb1 / photos

Everything, sections are created and formatted.

It should be noted that the partition mounted in this way will be available until the next reboot of the system.

To make the drive permanent, you need to write a line with the partition identifier and other parameters to the / etc / fstab file.

We recognize the device identifier with the command:


Next, open the / etc / fstab file with a familiar editor, for example, like this:

vi / etc / fstab

and write a line like this:

The Linux auto-mount process is described in more detail in this article.

File system setup

ATTENTION! All of the following is done on the UNMANTED file system!
It should also be noted here that when formatting in ext3 and ext4, 5% of the space is reserved for the root user. To remove the 5 percent reservation of space for root in ext3 and ext4, you need to give the command:

tune2fs -m 0 / dev / sdb1

After that, a simple user will have access to the whole place.

Also, there is a forced check of the disk after a certain number of downloads. If you do not need this, you can cancel the procedure with the command:

tune2fs -c 0 / dev / sda1

Or, make the check less frequent, for example, once every 100 downloads:

tune2fs -c 100 / dev / sda1

You can view file system properties using the command

tune2fs -l / dev / sda1

Winchester Partition Information

Sometimes you need to find out what partitions on the hard drive are and what file system is there. In order to find out information about hard disk partitions, we type from the root user:

fdisk -l / dev / sda

in response we get:

Disk / dev / sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors / track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xd0f4738c

Device Boot Start End Blocks Id System / dev / sda1 1 61 489951 82 Linux swap / Solaris / dev / sda2 * 15567 19457 31254457+ 83 Linux / dev / sda3 62 15566 124543912+ 83 Linux

From where we see: there are three partitions, the first of them (/ dev / sda1) is the swap partition (500 megabytes). The second partition (/ dev / sda2) is 30GB, the third partition (/ dev / sda3) is 120GB. The active partition (which is currently used by the operating system) is marked with an asterisk. To find out which section you are currently working on, use the command:

a point at the end is required, we get:

Filesystem 1K-blocks Used Available Use% Mounted on / dev / sda2 85864764 2733992 83130772 4% / home

actually the same as in the case of fdisk -l == information about the partition.

Linux disk formatting

Formatting a Linux disk is done using the mkfs command, the action of which is to create the specified file system on the selected disk or partition. An example of a command entry:

-text2 - a key indicating the type of file system,
/ dev / hda1 - the partition on which the file system is created.

The main keys of the mkfs command for formatting a Linux disk:

-v– displays detailed information about the progress of the command,
-t [file system type] - sets the file system, from the following possible values:

  • $ swap - file system section for linux swap file,
  • $ ext2 - file system ext2,
  • $ msdos - MS-Dos file system,
  • $ vfat - Fat-32 file system,
  • $ reiserfs - Reiserfs file system.

This is not a complete list of supported file systems, which can also be expanded by installing additional packages.

-c - search for bad blocks before formatting starts,

Also, to format the disk, you may need the following commands:

  • fdisk -l - view a list of disks, here you can find the name of the partition or media that you want to format,
  • umount– before formatting a Linux disk, you need to unmount it using this command,


  • mkfs-tvfat -v-c / dev / hdb1 - formats the partition of the second hard drive in the Fat-32 system, after checking it for the presence of unreadable blocks with the output of the progress,
  • mkfs -text3 -v / dev / hda1 - formatting the hda1 partition in the ext3 file system with the output of the execution process,

Linux formatting flash drives

Very often, mounting a USB flash drive occurs automatically when connected to a computer.

Before formatting, it must be unmounted (you can check whether the flash drive is mounted using the command - df-h).

Linux flash drive formatting is also done using the mkfs command. After determining the name of the USB flash drive, create the desired file system (in these examples, Fat-32 and Reiserfs):

where sdb is the name of the flash drive.

Linux Low Level Formatting

Low-level formatting boils down to writing zero bytes. To do this, run the command:

As a result of the low-level Linux formatting command, the disk or flash drive capacity will be shown. After that, you can check for physical errors:

N in the records above corresponds to the number of bytes written to disk when the dd command is executed.

Mismatch of the results of these commands means the presence of dead blocks on the disk.