- Re-read The Partition Table Without Rebooting Linux System
- Inform the OS of partition table changes
- Install parted
- Install kpartx
- 🌜 Как перезагрузить таблицу разделов в Linux без перезагрузки системы?
- Как перезагрузить таблицу разделов в Linux с помощью команды partprobe
- Как перезагрузить таблицу разделов в Linux с помощью команды blockdev
- Как перезагрузить таблицу разделов в Linux с помощью команды hdparm
- Как перезагрузить таблицу разделов в Linux с помощью команды partx
Re-read The Partition Table Without Rebooting Linux System
I If you are using hot swappable hard disk and created a new partition using the fdisk, then you need to reboot Linux based system to get partition recognized. Without reboot, you will NOT be able to create a filesystem on your newly created or modified partitions with the mke2fs command.
The kernel still uses the old table. The new table will be utilized at the next reboot or after you run partprobe or kpartx command. Both of these programs informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.
You will seen an error that read as follows:
Re-reading the partition table failed.: Device or resource busy
A sample session:
fdisk command in action
Inform the OS of partition table changes
The partprobe command is part of GNU parted software. parted is a disk partitioning and partition resizing program. It allows you to create, destroy, resize, move and copy ext2, ext3, linux-swap, FAT, FAT32, and reiserfs partitions. It can create, resize and move Macintosh HFS partitions, as well as detect jfs, ntfs, ufs, and xfs partitions. It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.
Install parted
To use partprobe command install parted. If you are using Debian / Ubuntu Linux, enter:
$ sudo apt-get install parted
OR if you are using RHEL version # up2date parted
OR if you are using CentOS / RHEL 5/6, enter:
# yum install parted
OR if you are Fedora, enter:
$ sudo dnf install parted
Now you can use the partprobe command.
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Install kpartx
The kpartx tool, derived from util-linux’ partx, reads partition tables on specified device and create device maps over partitions segments detected. It is called from hotplug upon device maps creation and deletion. To use kpartx command install kpartx. If you are using Debian / Ubuntu Linux, enter:
$ sudo apt install kpartx
To use, type:
# kpartx -u /dev/sdd2
See also:
- Man pages – partprobe(8)
- See official parted home page for download and other information.
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Its a very good tip that can be used in a production evironment without any downtime
partprobe won’t always work. If you are lucky hdparm -z will work, but again cannot be guartenteed. The problem with Linux and partition tables carries on into the 21st century’s second decade.
And to make this a bit more googlable:
fdisk printout: “Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy”
When partprobe isn’t available you can also (sometimes) use:
# hdparm -z /dev/sdX
which will re-read that device’s partition table.
BLKRRPART failed: Device or resource busy
You saved me from having to restart my server!
(restarting is a real pain in the neck)
And in order to install parted for gentoo users :
emerge -av parted
Thanks for the tips (LINUXTITLI, Jason) and also thanks domen for making this more googlable!
Created a new partition from unformatted disk space (got error in re-reading the partition table: device busy) , partprobed, mkfs.ext3’d, e2labeled and mounted!
No reboot needed, thanks again. 🙂
i am run this command in rhel6 .and i want without reboot update partition table.when i am use partprobe ,kpartx, and hdperm -z command .
system are given massage device or resource busy due to failed .
Try stopping services like samba and nfs. I found restarting nfs freed up my disk even after I used fdisk on it.
I found this website while I was trying to figure out what the difference between the three ways I’ve found so far (partprobe, hdparm -z /dev/disk, and blockdev –rereadpt /dev/disk) is.
According to ltrace and strace, hdparm and blockdev are basically the same(they all called ioctl(3, BLKRRPART, 0) to reread partition table).
partprobe is much complex the the above but I don’t know what they’re doing underhood.
Boy was I happy to find this post. Just added a new partition to my gentoo production server after 463 days uptime and stumbled across the above mentioned ioctl warning. Thanks guys for the post and the comments 🙂
Never was able to get the disk formatting re-read using partprobe. Had to reboot servers. May be to note that I am working on Redhat clusters with gfs. That shouldn’t matter much, as I run partprobe on both nodes.
on RH systems you may need to run udevstart after partprobe
i am run this command in rhel6 .and i want without reboot update partition table.when i am use partprobe ,kpartx, and hdperm -z command .
system are give massage device or resource busy due to failed .
so what are doing me pls help.
I found that even after all the fdisk’ing, the partition/disk was still in use. Ended up being nfs (even though I was not sharing that disk any more and had run exportfs -av a few times). I had to restart nfs server to free the disk, then partprobe worked.
I thought I was heading for a reboot.
echo 1 > /sys/block/sdc/device/rescan
And follow dmesg to see the kernel rescan the disk. I found this worked on a server that partprobe did not.
Thank you very much for this great advice.
Btw, if you want to know what partitions kernel sees, glance at the /proc/partitions file
Thank you, I was going crazy trying to figure out why my table was not refreshing. Thank you. thank you. thank you.
thank you very much!
Doesn’t seem to work for the disk that houses the root-partition or CentOS/RHEL machines. The resize2fs command simply stats the filesystem is already at maximum size. If I enter a value of 100 blocks less then available resize2fs tells me that the devices is not that big. Any hints?
– “partprobe” or “partprobe /dev/sda” does not provide any output and nothing is written in dmesg.
– “hdparm -z /dev/sda” throws me the same “device or resource busy” message as fdisk.
– “echo 1 > /sys/block/sda/device/rescan” doesn’t help either.
This is quite annoying as almost all of our machines are virtual machines which we can expand on-the-fly. Even more annoying is the fact that we can accomplish this with just a few clicks on a Windows machine…
I’m getting the exact same errors. If you run across a fix for centos 6 please let me know.
I am trying to add partprobe in a bash script after I format the disk.
but its not rereading the partition table, can you suggest me a way to achieve it?
For those on RH6/CentOS6 wondering why this does not work stop wondering, it never will. Due to stupid people frying their systems playing with partitions on the side the device will always block you with “BUSY” if there is even one active partition on a disk still in use. This was implemented by one of the developers, cant remember where I saw it but it was on BugZilla somewhere listed as a bug.
sda1 – In use
sda2 – Not in use
If you modify the partition data for sda2 and try to get it to reread in live without a reboot it will throw a device busy because sda1 is still active and in use. This at the end of the day is always going to lead to one of two paths, kill everything, unmount everything and try again or reboot. Both result in the same case scenario anyway, downtime of services.
You can rescan the bus for the devices but that wont reread in the partition information, only physical disk size. So you will have a disk that now accurately reflects the increase, say from 10GB to 20GB but you still wont be able to resize the partition to fill the space because the kernel cant reread in the changes to it you have made until after a reboot.
Please, if someone wants to point this out as being incorrect I beg of you please go right ahead because I seem to just keep running into dead ends.
The solution is rather simple: the 1st disk should have a small /boot partition, and the rest should be a single LVM physical volume. That’s why I’ve never bothered with that sort of a problem in years. LVM makes life quite wonderful, and offers features that don’t exist even on Windows 🙂
Further to my comment above here is the bug report I deduced this from:
@Jay Porter, your problem should be caused by old version parted . After I upgrade from 2.1 ( centos6.3 default ) to 3.1 (build from source). I can happily make/delete partitions without booting now!
Looks like it is problem with older version parted. So gist of the story if you don’t have parted 3.1 in your system be ready to reboot your system. As none of the technique seems to work on RHEL 6
@fubupc
new parted(3.1) cann’t reload partition table for me when some program use one partition.
Also check if any partition is not part of a logical volume. You can use the pvdisplay command, it helped a lot. This was on Centos.
Anyone else still having trouble with this, I found a solution for RHEL 6 somewhere else
Read the partition table with partx -a /dev/sda
It spits out an error but the second time I ran partx it showed the 3rd partition I created with cfdisk.
@Justin
Thx
i’ve solve my problem with
sudo partx -u /dev/sda (as -a reported some errors)
sudo resize2fs /dev/sda1
@HappyMike you have saved me.
I’ve tried all other ways listed above but none works in CentOS6.4
Using partx (twice) read the new partition.
Is there any equivalent for rereading the partition table without reboot on windows using an NTFS file system ?
If you are using RHEL/CENTOS6 with LVM do the following:
example:
-/dev/sdb1 was created and is LVM partition.
-In VMware I extended the Virtual Disk file an extra 100GB
-I added a new partition called /dev/sdb2
-OS states I need to run kpartx or partprobe
-OS states drive is busy and cannot continue
In order to get the drive working, I did the following;
umount /mnt/
vgchange -an vg_data
blockdev –rereadpt /dev/ (ex /dev/sdb not /dev/sdb1,2,3,4…)
vgchange -ay
pvcreate /dev/sdb2
Источник
🌜 Как перезагрузить таблицу разделов в Linux без перезагрузки системы?
Как администратор Linux, вы можете выполнять задачу разделения диска несколько раз в день.
В большинстве случаев таблица разделов успешно изменялась после разделения диска в виртуальных средах (таких как VMWare, Virtualbox и т. д.).
Но это не происходит на физических серверах, тогда какое решение сообщить ОС об изменениях таблицы разделов?
Тем не менее, мы не можем давать вам гарантию, что оно будет работать на 100%, но оно будет работать в большинстве случаев.
Я могу сказать другими словами. Это будет работать на 99% согласно моему опыту и знаниям.
Эти методы заставляют ядро перезагружать таблицу разделов и повторно заполнять ее идентификаторы в /dev.
Если вы ищете утилиты для разделов диска, вы можете попробовать одну из них.
Утилиты дискового разделения – это fdisk и parted.
Если вы хотите прочитать соответствующие статьи о разделах диска, вы можете перейти к следующим статьям.
Вы можете получить вывод, подобный приведенному ниже, в большинстве случаев в виртуальной среде, когда вы выполняете разделение диска.
Вы можете получить такой же вывод в большинстве случаев в физической среде, когда вы выполняете разделение диска.
Я протестировал приведенные ниже команды в системе Arch Linux, и они работали нормально, кроме команды partx.
Потому что я не вижу никаких логов журнале dmesg после запуска команды partx.
Однако он работал нормально, как и ожидалось в системах RHEL 7.
Я бы посоветовал вам выполнить любую из приведенных ниже команд после добавления раздела в систему Linux, чтобы проинформировать ОС об изменениях таблицы разделов.
Это можно сделать с помощью следующих четырех методов.
- partprobe: partprobe – это программа, которая информирует ядро операционной системы об изменениях таблицы разделов, запрашивая у операционной системы перечитывание таблицы разделов.
- blockdev: Утилита blockdev позволяет вызывать ioctl для блочных устройств из командной строки.
- hdparm: hdparm предоставляет интерфейс командной строки для различных интерфейсов ядра, поддерживаемых подсистемой «libata» Linux SATA / PATA / SAS и более старой подсистемой драйверов IDE.
- partx: partx сообщает ядру о наличии и нумерации разделов на диске.
Как перезагрузить таблицу разделов в Linux с помощью команды partprobe
partprobe – это программа, которая информирует ядро операционной системы об изменениях таблицы разделов, запрашивая у системы, чтобы она перечитала таблицу разделов.
Это стандартная и нативная команда для выполнения этой задачи.
В этом примере я собираюсь использовать /dev/sdb. Помните, что вам нужно ввести имя вашего устройства вместо нашего.
dmesg используется для проверки или управления кольцевым буфером ядра.
Итак, используйте следующую команду, чтобы увидеть изменения в ядре.
Да, я вижу изменения, потому что в dmesg есть новый лог для устройства SDB.
Как перезагрузить таблицу разделов в Linux с помощью команды blockdev
Утилита blockdev позволяет вызывать ioctl блочных устройств из командной строки.
Мы можем использовать команду blockdev для выполнения этой задачи.
Используйте следующую команду dmesg, чтобы увидеть изменения в ядре.
Да, я вижу изменения, потому что в dmesg снова появился новый лог для устройства sdb.
Как перезагрузить таблицу разделов в Linux с помощью команды hdparm
hdparm предоставляет интерфейс командной строки для различных интерфейсов ядра, поддерживаемых подсистемой «libata» Linux SATA / PATA / SAS и более старой подсистемой драйверов IDE.
В качестве альтернативы, мы можем использовать команду hdparm для выполнения этой задачи.
Используйте следующую команду dmesg, чтобы увидеть изменения в ядре.
Да, я вижу изменения, потому что в dmesg снова появился новый лог для устройства sdb.
Как перезагрузить таблицу разделов в Linux с помощью команды partx
partx сообщает ядру о наличии и нумерации разделов на диске.
Команда partx является частью пакета util-linux и доступна из архива ядра Linux.
В качестве альтернативы, мы можем использовать команду partx для выполнения этой задачи.
Вы можете дважды подтвердить это, выполнив следующую команду.
Если таблица разделов успешно перезагружена и видна ядру, вы можете увидеть эти новые разделы в этом месте.
Эту же информацию можно найти с помощью следующей команды ls.
Эту же информацию можно найти с помощью следующей команды partx.
Источник