How to Merge Multiple Disk Drive Partitions into One in Linux
Tags: howto, linux, ubuntu, diskdrives
Published: 2020-03-28 03:33:08

---
title: How to Merge Multiple Disk Drive Partitions into One in Linux
published: true
date: 2019-11-11 09:59:23 UTC
tags: HowTo,Linux,Ubuntu,disk drives
canonical_url: https://fossnaija.com/how-to-merge-multiple-disk-drive-partitions-into-one-in-linux/
---

#### _This tutorial shows you how you can create a single partition on a disk drive with many smaller fragmented partitions easily._

![disk drive partitioning](https://i2.wp.com/fossnaija.com/wp-content/uploads/2019/11/disk-drive-partitioning.jpg?resize=665%2C444&ssl=1)

There are many situations that can lead to the population of a disk drive by different fragmented partitions. For instance, you might want to repurpose a USB thumb drive that has been used to create a bootable medium for installation purposes, to be used as a drive for file storage/transfer.

But you find out that the thumb drive contains some partitions that are unusable taking a lot of space, or rather you just want the thumb drive to contain a single partition for easy management. Then this post is for you.

Let’sget started!

**NB:** The steps outlined here will work for any disk drives (HDD, SSD, etc)connected to Linux – either externally or internally.

And also note that this can also be achieved using graphical applications like _GParted_; a [command-line approach](https://fossnaija.com/the-anatomy-of-the-linux-command-line/) is not a bad skill to have in some serious desperate [situations](https://dev.to/xeroxism/why-these-5-myths-about-the-linux-command-line-are-false-i3a).

## THE fdisk COMMAND

There is a very useful command-line utility for doing this – `fdisk`. The `fdisk` is a very important tool for working with partitions of disk drives. It is interactive, accepting commands from the user to carry out its various functions.

I’m going to be illustrating this with a thumb drive with 8GB memory space, and contains an unwanted bootable hidden partition.

![disk with multiple parttions](https://i2.wp.com/fossnaija.com/wp-content/uploads/2019/11/image-0.png?w=665&ssl=1)<figcaption>IMAGE: FOSSNAIJA.COM</figcaption>

**STEP1 –** Get Root Access.

Subsequent steps after this require root (admin) access (or you’d have to be type `sudo` along with every command after). So switch to the root user. By entering this command and providing your password ;

```
sudo su
```

**STEP2** – Type the command tolocating the disk drive:

```
fdisk -l
```

![fdisk disk drive search](https://i1.wp.com/fossnaija.com/wp-content/uploads/2019/11/image1-fdisk-1.png?w=665&ssl=1)<figcaption>SEARCH FOR THE DRIVE</figcaption>

So as not to get confused, you can enter the command before inserting the USB drive and noting the output; then after connecting the drive enter the command again and then spot the difference. This is very important for you not to delete useful partitions in your computer hard drive (HDD).

**STEP 3** – Select the desired disk drive for manipulation ;

```
fdisk /dev/sdX
```

where **_X_** = the drive letter, like ‘b’, ‘c’, and so on.

```
fdisk /dev/sdb
```

![CHOOSING A DRIVE](https://i1.wp.com/fossnaija.com/wp-content/uploads/2019/11/image-2.png?w=665&ssl=1)<figcaption>FDISK – CHOOSING A DRIVE</figcaption>

Then the `fdisk` command prompt appears for you to enter commands.

**STEP 4 –** Enter the letter `d` to delete the partition(s)

If there are more than one partitions you can specify with numbers by enter code]_1_[/code] or `2` (for the first and second partitions respectively) as the case may be. Since my disk drive contained just one partition it was automatically deleted.

**STEP5 –** Createnew (single) partition; Enter: _ **n** _

**STEP6 –** Tomake it a primary partition, Type: _ **p** _

**STEP7 –** To make it the first partition, Type: _ **1** _

**STEP8 –** To accept the default first cylinder, press: **ENTER**.

**STEP9 –** Toaccept the default last cylinder, press: **ENTER**.

**STEP 10 –** To write the new partition to the disk, Type: _ **w**._

![commands steps](https://i0.wp.com/fossnaija.com/wp-content/uploads/2019/11/image-3.png?w=665&ssl=1)

_There!You now have a single partition in the entire disk drive._

**STEP 11 –** Create a new file -system;

If the disk is mounted, unmount it using _umount /dev/sdX._

And then create a new filesystem, since mine is a thumb drive, I’ll use FAT (the default for thumb drives.);

```
mkfs.vfat -F 32 /dev/sdb
```

![new single partition](https://i0.wp.com/fossnaija.com/wp-content/uploads/2019/11/image-5.png?w=665&ssl=1)<figcaption>NEW SINGLE PARTITION</figcaption>

DONE!!!

**HappyLinux’NG!**

The post [How to Merge Multiple Disk Drive Partitions into One in Linux](https://fossnaija.com/how-to-merge-multiple-disk-drive-partitions-into-one-in-linux/) appeared first on [Foss Naija](https://fossnaija.com).