[clug] partition tables in memory

Steve Walsh steve at nerdvana.org.au
Sat Apr 16 07:11:53 GMT 2005

You could try making a call to the ioctl facility provided by the kernel
re-read the partition table.
Be careful and make sure no filesystem or other process is mounted on,
accessing or
going to use anything on the device in the meantime (code below won't

I'm not a kernel or C programmer. I can't remember where I got this code
from, but it's in a closed case marked "reloading partition tables", so if
this doesn't work, and b0rks your box, I'm sorry, I'll buy you a beer to cry
into, but that's as far as willing to wave various parts of the anatomy in
the direction of liability I will go.
********End Big Arse Disclaimer********

/* Assume this source file is named reread.c and you use GCC as your
   C compiler...  commands:

    Replace /dev/hdb below with the proper device
    gcc -o reread reread.c
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/fs.h>
#include <fcntl.h>

#define DEVICE_NODE "/dev/hdb"

int main()
   int fd;

   sync (); /* Sync disks */

   if ((fd = open(DEVICE_NODE, O_RDONLY)) < 0) { perror("open");
           close(fd); return 0; }
   if (ioctl(fd, BLKRRPART) < 0)
           perror("unable to reload table");



-----Original Message-----
From: Kim Holburn
Sent: Saturday, 16 April 2005 2:37 PM
To: CLUG List
Subject: [clug] partition tables in memory


I have a linux server which needed more swap.  I added a new swap
partition wrote the new partition table but it doesn't show up in
/proc/partitions so I can't mkswap etc.
# mkswap  /dev/sda8
/dev/sda8: No such device or address

Is there any way to get the kernel to reread the partition table or do
I have to do the windows thing and reboot (and lose my uptime;-( )?

Dell debian stable kernel 2.4.26 #1 SMP

Kim Holburn
Network Manager,  National ICT Australia Ltd.
Ph: +61 2 61258620 M: +61 417820641 F: +61 2 6230 6121 aim://kimholburn
Email: kim.holburn at anu.edu.au  - PGP Public Key on request
Cacert Root Cert: http://www.cacert.org/index.php?id=16 ->
Aust. Spam Act: To stop receiving mail from me: reply and let me know.

Use ISO 8601 dates [YYYY-MM-DD]
Democracy imposed from without is the severest form of tyranny.
                           -- Lloyd Biggle, Jr. Analog, Apr 1961

linux mailing list
linux at lists.samba.org

More information about the linux mailing list