Remove file systems linux

Deleting All Partitions From the Command Line

How do you delete all partitions on a device from the command line on Linux (specifically Ubuntu)? I tried looking at fdisk, but it presents an interactive prompt. I’m looking for a single command, which I can give a device path (e.g. /dev/sda) and it’ll delete the ext4, linux-swap, and whatever other partitions it finds. Essentially, this would be the same thing as if I were to open GParted, and manually select and delete all partitions. This seems fairly simple, but unfortunately, I haven’t been able to find anything through Google.

9 Answers 9

dd if=/dev/zero of=/dev/sda bs=512 count=1 conv=notrunc 

This will not delete the partitions. By deleting the partitions he meant to preserve the MBR and just empty the partition table.

No, this appears to do exactly what I need. I don’t really care if the data is still there. GParted shows that the partitions are gone after running this, and that’s what I wanted.

To be fair, he said delete the partitions, not the partition table or data, so it wasn’t really clear. But I think we knew he just wanted the parts not to register, which makes this the correct answer. To delete the data would be uneccesary. IF you want to zero it, thats a different story, that’s deleting the data too.

The wipefs program lets you easily delete the partition-table signature:

wipefs can erase filesystem, raid or partition-table signatures (magic strings) from the specified device to make the signatures invisible for libblkid.

wipefs does not erase the filesystem itself nor any other data from the device. When used without any options, wipefs lists all visible filesystems and the offsets of their basic signatures.

wipefs calls the BLKRRPART ioctl when it has erased a partition-table signature to inform the kernel about the change.

Quick and Dirty: use gparted to delete the partitions, or if you’re in a hurry:

dd if=/dev/zero of=/dev/[disk device] bs=512 count=1 

This will zap the MBR of the drive (Data is still intact).

dd if=/dev/zero of=/dev/[disk device] 

to wipe the whole drive (write a single pass of zeros over everything. Not «secure» but usually good enough), or use a «disk shredder» tool for a secure wipe.

Читайте также:  Кодеки linux mint opera

Not secure because it’s possible that the disk’s contents could be partially recovered by someone with physical access to it. A secure wipe writes multiple passes of random data over the whole disk.

Use improved non-interactive version of fdisk, which is sfdisk

To erase partition table use this command:

Note: no confirmation will be thrown, the partitions will be deleted instantly and forever!

I think it’s worth making it clear that after running this command there won’t be any confirmation prompts whatsoever, the partition will be deleted instantly.

See man sfdisk , which is a non-interactive variant of fdisk. Other than that, you can delete the whole partition table with dd, as pk wrote.

You should be able to use parted for this aswell, although that may involve some scripting to loop through the partitions.

It may be worth to mention that e.g. parted /dev/mmcblk0 —script mklabel gpt deletes all existing partitions. For me it was parted /dev/mmcblk0 —script mklabel msdos

If we’re talking about MBR-style partitions.

dd if=/dev/zero of=/dev/[disk device] bs=1 count=64 seek=446 conv=notrunc 

This standard command copies bytes from a source and writes them to a destination. It’s the simplest flexible tool for this job.

Here, we specify that we’re reading from /dev/zero , which is a special device which emits NUL bytes—zeros.

Here, we specify which device we’re writing to.

dd thinks in terms of blocks. The default block size may be 512 bytes, 1024 bytes or 4096 bytes, depending on your system. However, we need to address things more precisely than that, so we tell dd to use a block size of 1 byte.

Here, we tell dd to write 64 blocks (or bytes, because of our bs=1 parameter), since the primary partition table consists of 4 16-byte partition entries, for a total of 64 bytes.

The primary partition table within the MBR (so, not talking about GPT here) is located 446 bytes in, so we instruct dd to seek 446 bytes in before writing.

Extended partitions are generally created by using a primary partition slot to point at the extended partition table, so if we erase the 4 primary partitions, we effectively wipe the extended partition table as well; the OS won’t be able to find it, so it won’t be able to read and interpret it. (If you want to wipe the extended partition table, you’ll need to know more about the operating system; different operating systems do extended partitions in different ways.)

Читайте также:  Calculate linux файловая система

I wanted to do the same thing (except in Slackware 14.2) but found I could not effect most of the solutions proposed here, with the most elaborate and well-documented solution creating new problems for making replacement partitions. That deleted the partition but some partitioning software apparently found the partition backups automatically.

I found f3probe (http://oss.digirati.com.br/f3) solved the problem of deleting all the partitions, quickly and easily, working with large capacity drives, and created exactly 1 partition spanning the whole drive, which was easy to delete.

It was also easy, from there to create new partitions, in a straight-forward way.

f3probe --destructive --time-ops /dev/sdb # Now we know only 1 partition exists on /dev/sdb # which is /dev/sdb1 # # Unmount that partition umount /dev/sdb1 # # Delete that single partition parted /dev/sdb rm 1 # # Now you can create new partitions # i.e. parted /dev/sdb mkpart primary fat32 1049K 15.8G # # Update /etc/fstab before rebooting. 

Источник

How to Delete Partition in Linux

Linux users create partitions to organize their data in an efficient manner. As easy as they are created, Linux partitions can be deleted to reformat a storage device and regain storage space.

In this step-by-step tutorial, you will learn how to delete a partition on a Linux system.

How to Delete Partition in Linux

  • A system running Linux
  • A user account with sudo or root privileges
  • Access to a terminal window / command line (Activities >Search >Terminal)
  • The fdisk command-line utility

Delete a Partition in Linux

Deleting a partition in Linux requires selecting the disk containing the partition and using the fdisk command-line utility to delete it.

Follow the steps outlined in the sections below to delete partitions in Linux.

Note: The fdisk command-line utility is a text-based partition table manipulator. It is used for partitioning and repartitioning storage devices.

Step 1: List Partition Scheme

Before deleting a partition, run the following command to list the partition scheme.

In our case, the terminal prints out information about two disks: /dev/sda and /dev/sdb . Disk /dev/sda contains the operating system, therefore its partitions should not be deleted.

Listing the partition scheme

On the /dev/sdb disk, there is a /dev/sdb1 partition which we are about to delete.

Note: The number 1 in /dev/sdb1 indicates the partition number. Make a note of the number of the partition you intend to delete.

Читайте также:  Командная строка mandriva linux

Step 2: Select the Disk

Select the disk that contains the partition you intend to delete.

Common disk names on Linux include:

Type of disk Disk names Commonly used disk names
IDE /dev/hd[a-h] /dev/hda, /dev/hdb
SCSI /dev/sd[a-p] /dev/sda, /dev/sdb
ESDI /dev/ed[a-d] /dev/eda
XT /dev/xd[ab] /dev/xda

To select a disk, run the following command:

Selecting storage disk with fdisk command.

Step 3: Delete Partitions

Before deleting a partition, back up your data. All data is automatically deleted when a partition is deleted.

To delete partition, run the d command in the fdisk command-line utility.

The partition is automatically selected if there are no other partitions on the disk. If the disk contains multiple partitions, select a partition by typing its number.

The terminal prints out a message confirming that the partition is deleted.

Deleting partition.

Note: If you wish to delete multiple partitions, repeat this step as many times as necessary.

Step 4: Verify Partition Deletion

Reload the partition table to verify that the partition has been deleted. To do so, run the p command.

The terminal prints out the partition structure of the disk selected in Step 2.

Partition table reload.

Step 5: Save Changes and Quit

Run the w command to write and save changes made to the disk.

Quitting fdisk command-line utility and saving changes to the disk.

After following the instructions in this tutorial, you should have learned how to delete a partition in Linux.

If you want to learn more about partition manipulation, we recommend reading our tutorial on creating partitions in Linux or if you are running NTFS partitions, check out our article on how to mount NTFS partitions in Linux.

Dejan is the Head of Content at phoenixNAP with over 8 years of experience in Web publishing and technical writing. Prior to joining PNAP, he was Chief Editor of several websites striving to advocate for emerging technologies. He is dedicated to simplifying complex notions and providing meaningful insight into data center and cloud technology.

In Linux systems, in order to use storage devices such as Hard Drives and USB drives, you need to understand.

sudo stands for SuperUser DO, and it’s used to temporarily elevate privileges in Linux. This guide will show.

The ls command (short for list) lists information about directories and any type of files in the working.

A list of all the important Linux commands in one place. Find the command you need, whenever you need it or.

Источник

Оцените статью
Adblock
detector