HowTo: Linux Remove a Partition Name (/dev/sdXY entry) Temporarily

by on August 27, 2012 · 9 comments· LAST UPDATED September 6, 2012

in

I'd like to remove /dev/sdc5 temporarily without deleting partitions on hard drive /dev/sdc under Linux operating systems?

You can use old good rm command (make sure /dev/sdc5 is not mounted). Another option is to use the delpart command that asks the Linux kernel to remove a partition.

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsNone
Estimated completion timeN/A

This command doesn't manipulate with partitions on hard drive. The syntax is as follows:
delpart /dev/sdX Number
OR
rm /dev/sdXY

rm command example

Type the following rm command as root:
# umount /dev/sdc5
# rm /dev/sdc5
# ls /dev/sdc*

delpart command example

Type the following as root:
# umount /dev/sdc5
# delpart /dev/sdc 5
# ls /dev/sdc*

How do I re-read (or add) temporarily deleted partition?

Use partprobe command. It will informs Linux operating system kernel of partition table changes, by requesting that the operating system re-read the partition table:
# partprobe /dev/sdX
# partprobe /dev/sdc

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 9 comments… read them below or add one }

1 John August 28, 2012 at 3:04 am

I am really curious why someone would want to do this.

Reply

2 Sami August 28, 2012 at 5:56 am

Why would one do such a thing?

Reply

3 Marcello August 28, 2012 at 6:56 am

Can’t imagine a use case either…

Reply

4 punktyras August 28, 2012 at 8:40 am

And how to get deleted partition back?

Reply

5 nixCraft August 28, 2012 at 9:54 am

@punktyras

Use partprobe command.

I am really curious why someone would want to do this.
Why would one do such a thing?
Can’t imagine a use case either…

May be to avoid accidental mounting and deleting files. For example, boot embedded nas / router from /boot and run this command from /etc/rc.local. Now, apt-get or yum or ipkg will not able to update kernel and install at /boot.

Say are writing a script that modifies /boot or other part of fs. In that case you can delete /dev/whatever and use some image file on /boot and test your config without committing anything to real /dev/whatever and be done with testing.

Hope this helps!

Reply

6 mesuutt August 28, 2012 at 11:20 am

Good for hide a special partition from others :)

Reply

7 John August 28, 2012 at 1:02 pm

@Vivek

Wouldn’t you then use fstab to point /boot at another partition?

I fear that the person who submitted the question is trying to get something done at their job, and will screw something up because they are approaching the solution wrong.

Reply

8 Jeremy September 12, 2012 at 1:56 am

This could be used to test an application or something for disk failures. Like removing the drive suddenly to see what an application would do. As you can see partprobe would be able to get back the drive so no harm is done.

Reply

9 Lynx September 27, 2012 at 6:40 am

you can do this when you don’t want airport customs to see your files

Reply

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: