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

in Categories last updated September 6, 2012

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.

This command doesn’t manipulate with partitions on hard drive. The syntax is as follows:
delpart /dev/sdX Number
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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 9 comments/add one below):

9 comment

  1. @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!

  2. @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.

  3. 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.

    Have a question? Post it on our forum!