From: Michael Tokarev <mjt@tls.msk.ru>
To: Rob Bray <raid@bymeinc.com>
Cc: linux-raid@vger.kernel.org
Subject: Re: Move superblock on partition resize?
Date: Wed, 07 Feb 2007 21:50:14 +0300 [thread overview]
Message-ID: <45CA1F66.4080907@tls.msk.ru> (raw)
In-Reply-To: <44918.192.168.0.1.1170871062.squirrel@bymeinc.com>
[-- Attachment #1: Type: text/plain, Size: 936 bytes --]
Rob Bray wrote:
> I am trying to grow a raid5 volume in-place. I would like to expand the
> partition boundaries, then grow raid5 into the newly-expanded partitions.
> I was wondering if there is a way to move the superblock from the end of
> the "old" partition to the end of the "new" partition. I've tried dd
> if=/dev/sdX1 of=/dev/sdX1 bs=512 count=256
> skip=(sizeOfOldPartitionInBlocks - 256) seek=(sizeOfNewPartitionInBlocks -
> 256) unsuccessfully. Also, copying the last 128KB (256 blocks) of the old
> partition before the table modification to a file, and placing that data
> at the tail of the new partition also yields no beans. I can drop one
> drive at a time from the group, change the partition table, then hot-add
> it, but a resync times 7 drives is a lot of juggling. Any ideas?
The superblock location is somewhat tricky to calculate correctly.
I've used a tiny program (attached) for exactly this purpose.
/mjt
[-- Attachment #2: mdsuper.c --]
[-- Type: text/x-csrc, Size: 2092 bytes --]
/* mdsuper: read or write a linux software raid superbloc (version 0.90)
* from or to a given device.
*
* GPL.
* Written by Michael Tokarev (mjt@tls.msk.ru)
*/
#define _GNU_SOURCE
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/raid/md_p.h>
#include <linux/fs.h>
int main(int argc, char **argv) {
unsigned long long dsize;
unsigned long long offset;
int mdfd;
int n;
mdp_super_t super;
const char *dev;
if (argc != 3) {
fprintf(stderr, "mdsuper: usage: mdsuper {read|write} mddev\n");
return 1;
}
if (strcmp(argv[1], "read") == 0)
n = O_RDONLY;
else if (strcmp(argv[1], "write") == 0)
n = O_WRONLY;
else {
fprintf(stderr, "mdsuper: read or write arg required, not \"%s\"\n",
argv[1]);
return 1;
}
dev = argv[2];
mdfd = open(dev, n, 0);
if (mdfd < 0) {
perror(dev);
return 1;
}
if (ioctl(mdfd, BLKGETSIZE64, &dsize) < 0) {
perror(dev);
return 1;
}
if (dsize < MD_RESERVED_SECTORS*2) {
fprintf(stderr, "mdsuper: %s is too small\n", dev);
return 1;
}
offset = MD_NEW_SIZE_SECTORS(dsize>>9);
fprintf(stderr, "size=%Lu (%Lu sect), offset=%Lu (%Lu sect)\n",
dsize, dsize>>9, offset * 512, offset);
offset *= 512;
if (n == O_RDONLY) {
if (pread64(mdfd, &super, sizeof(super), offset) != sizeof(super)) {
perror(dev);
return 1;
}
if (super.md_magic != MD_SB_MAGIC) {
fprintf(stderr, "%s: bad magic (0x%08x, should be 0x%08x)\n",
dev, super.md_magic, MD_SB_MAGIC);
return 1;
}
if (write(1, &super, sizeof(super)) != sizeof(super)) {
perror("write");
return 1;
}
}
else {
if (read(0, &super, sizeof(super)) != sizeof(super)) {
perror("read");
return 1;
}
if (pwrite64(mdfd, &super, sizeof(super), offset) != sizeof(super)) {
perror(dev);
return 1;
}
}
return 0;
}
prev parent reply other threads:[~2007-02-07 18:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-07 17:57 Move superblock on partition resize? Rob Bray
2007-02-07 18:50 ` Michael Tokarev [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45CA1F66.4080907@tls.msk.ru \
--to=mjt@tls.msk.ru \
--cc=linux-raid@vger.kernel.org \
--cc=raid@bymeinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).