Parted Partition Resizing

HarkenBanks
HarkenBanks used Ask the Experts™
on
I have a new server running CentOS that I just got from 1and1.  It has what strikes me as a very odd (ie, stupid) partitioning scheme for CentOS (at least for a web server, which is presumably what these servers are by far most often being used for) in that the bulk of the drive is allocated to the /home dir while the / dir and (most notably) the /var dir are rather small:
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md1              950M  148M  755M  17% /
/dev/md5              4.7G  454M  4.3G  10% /usr
/dev/md6              4.7G   33M  4.7G   1% /var
/dev/md7              221G  4.6M  221G   1% /home
none                  990M     0  990M   0% /tmp
#

Now, there is a recovery tool which lets me boot the server into a rescue mode in which the server is running Debian (not CentOS).  My hope is to be able to use parted to resize these partitions to something more reasonable for a CentOS-based web server.  

However, maybe I should not do this, but rather create symlinks and keep the partioning scheme as is, but unless someone can explain to me that such is the better way to go (versus repartioning), I'm trying to go with repartitioning.  

Here's what a parted print shows me in the recovery mode:
(parted) print                                                            
Disk geometry for /dev/sda: 0.000-238475.179 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031    964.841  primary   ext3        raid
2        964.841   2878.835  primary   linux-swap  
4       2878.835 238472.688  extended              
5       2878.866   7655.976  logical   xfs         raid
6       7656.007  12433.117  logical   xfs         raid
7      12433.148 238472.688  logical   xfs         raid
(parted)

What I want to do is make 5 (/var) much bigger and 7 (/home) much smaller while also maybe increasing 1 (/) a bit as well.  Since we are dealing with partitioning here and I've never done this sort of resizing using parted, I'm rather gunshy.  Any advice or instructions are much appreciated.  

Thank you!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Do you want to keep the data or just reinstall the OS?

If you want to keep the data, you will need to backup everything first. I recommend using "tar" to another drive, such as an ext formated USB drive. Use the tar option, "--one-file-system" for the root filesystem if you want to back up each partition seperately.

Then, boot a rescue CD/DVD which has parted or fdisk. Delete all the partitions, create at least two partitions, one for the root filesystem and one for swap space. The swap space should be at least equal in size to the amount of RAM you have. Once you have done, make the root filesystem:
mke2fs -j -t ext3 /dev/md1, the recover the files using tar again.

Make sure you make set the bootable flag on the root partition and edit the /boot/grub menu to specify the partition you are going to boot, presumably '(hd0)'.

Author

Commented:
> Do you want to keep the data or just reinstall the OS?
I would like to keep the data, but not if it requires making a backup.  I can reinstall everything.  If I'm going to kill everything, then I will reinstall.  

> Then, boot a rescue CD/DVD which has parted or fdisk.
Note that the server is in 1and1's data center, so I can't do this.  

I do not have control over the partitioning scheme on install.  That is the crux of the problem.  


The thing I'm really concerned about here is issuing the correct set of parted commands to resize the partitions that I am stuck with as they are 1and1's defaults.  (Their partioning scheme just doesn't make sense, at least in the context of a CentOS-based webserver.)    
I think without physical access to the server, you are out of luck.
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Daniel McAllisterPresident, IT4SOHO, LLC
Commented:
Well, if you had physical access, you could use a GNU Partition Editor (see gparted.sourceforge.org)

However, so long as you're not changing the BOOT device or partition, you should be able to relocate and resize partitions "on the fly".

Post the output of fdisk -l /dev/sda here and tell me what you WANT to do, and I'll see what I can do (in so far as specific commands).

NOTE: You can easily change the END of a partition & run resize2fs to GROW a partition, or do it the other way around to SHRINK a filesystem... but (especially in the case of shrinking) you must be VERY CAREFUL!

Good luck & I'll be waiting! :-)

Dan
IT4SOHO
You can boot into a rescue CD via the 1&1 control panel.  Here are some good instructions on fixing the partitioning scheme:

http://www.devblog.co.uk/2008/09/23/1and1-dedicated-root-server-and-resizing-their-partitions/

Author

Commented:
Sorry for the delay on this one.  By the time the repartioning comments came in, I had already moved on using symlinks.

I should be getting another 1and1 server in the next 1-2 months and I will follow up then as I try to repartition that new server.  

Author

Commented:
OK, I have the server now and am working through the re-partitioning.

I looked at
http://www.devblog.co.uk/2008/09/23/1and1-dedicated-root-server-and-resizing-their-partitions/
and it's rather helpful.  

Note that this article puts everything into one ext3 root partition plus a swap partition, which raises two issues that you might want to consider:
1.  Do you want to use ext3?
2.  Do you want everything in one big partition.

But, the article seems close the the mark.  I couldn't actually get it to work, however, due to receiving the following error message:
"No Implementation: This ext2 filesystem has a rather strange layout!  Parted can't resize this (yet)."
Now, the partition is not an ext2 partition (rather, it's ext3) and "strange layout" is not very informative.

Here's what I tried to do with parted (while booted into rescue mode):
rescue:~# parted
GNU Parted 1.6.21 with HFS shrink patch 16
Copyright (C) 1998 - 2004 Free Software Foundation, Inc.
This program is free software, covered by the GNU General Public License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Using /dev/sda
(parted) print
Disk geometry for /dev/sda: 0.000-238475.179 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031    964.841  primary   ext3        raid
2        964.841   2878.835  primary   linux-swap
4       2878.835 238472.688  extended
5       2878.866   7655.976  logical   xfs         raid
6       7656.007  12433.117  logical   xfs         raid
7      12433.148 238472.688  logical   xfs         raid
(parted) resize 2 237475.179 238475.179
Warning: You requested to resize the partition to 237475.179-238475.179Mb. The
closest Parted can manage is 238472.688-238475.179Mb.
OK/Cancel? OK
(parted) print
Disk geometry for /dev/sda: 0.000-238475.179 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031    964.841  primary   ext3        raid
4       2878.835 238472.688  extended
5       2878.866   7655.976  logical   xfs         raid
6       7656.007  12433.117  logical   xfs         raid
7      12433.148 238472.688  logical   xfs         raid
2     238472.688 238475.179  primary   linux-swap
(parted) resize 1 0 238472.687
No Implementation: This ext2 filesystem has a rather strange layout!  Parted
can't resize this (yet).
(parted) resize 1 0 100000
No Implementation: This ext2 filesystem has a rather strange layout!  Parted
can't resize this (yet).

Any thoughts are much appreciated.  
Daniel McAllisterPresident, IT4SOHO, LLC
Commented:
OK... two issues you want to look at, and then apparently, you're looking for an explanation of the parted output.

1) Do you want to use ext3?

There is nothing wrong with letting everything be on one partition, nor is there anything wrong with that partition being an ext3 filesystem type. There are potentially "better" filesystems (many people like the xfs filesystem you're using on some of your other partitions already), but ext3 is the "defacto standard" on Linux systems, and it the most widely supported as a boot partition. Therefore, I believe that it is a perfectly fine choice.

2) Do you want everything on one big partition?

This one is actually related to the first one! Personally, I like to have a reasonably large (10-20GB) boot (root) partition as an ext3 filesystem, and then a much larger working partition (/home for me) for 99% of my data. My / partition is ext3, where my /home partition is xfs.

But those are just MY PERSONAL preferences. If you polled every Linux guru on the net you'd get a different opinion from each! What you need to keep in mind are the following:
 - each partition will be a separate filesystem. This means a little more flexibility in choosing fillesystems, but a little less flexibility in file management and space allocation.
 - more partitions means more drive fragmentation. No, I don't mean files will be split up across partitions - in this case, what I mean is most clearly represented by the following example:
    suppose I create a 2GB /var partition (which has 700MB of free space), a 5GB /usr partition (which also has about 1GB of free space), a 2GB /boot partition (with about 1GB of free space)... and the my /home partition (which uses a lot of space) is 700GB -- but suddenly is nearly full. I need (for whatever reason) another 2GB of storage.
    I simply don't have any way (other than resizing partitions) to squeeze the extra space out of this hard drive - even though I have nearly 3GB of usable space on the drive, they're in blocks of no larger than 1GB in separate partitions.

So, in summary, I think you need to have a balance: not a separate partition for each root folder (like /boot, /root, /usr, /var, /etc and so on) unless you have a bunch of smaller drives you don't have any other use for; and not just one huge partition unless you have no need for different filesystem types. (The latter being a not-so-very uncommon state.)

3) The output of parted explained:

Firstly, know that the only REAL difference between ext2 & ext3 is the presence of a "journal" in the ext3 layout. So it is not at all uncommon for tools to identify ext2 filesystems as ext3, or vice-versa.

Next, you appear to be concerned about the fact that parted won't partition to some exact value. Not to worry -- parted is just telling you that, since partitions must end on "cylinder boundaries" on the physical hard drive, it has done the calculation for you and you will get slightly more (or rarely - slightly less) than you asked for because of it.

After that, you appear to be trying to resize a partition to use the entire drive... that's all well and good, but you need to keep some things in mind:
 1) parted won't resize a partition over top of another partition -- so you need to remove the other partitions first
 2) parted sees that this is a bootable drive, and so will NOT start a partition on cylinder 0 (that's where the boot sector lies)

One final note -- the existing partitions look as though they may be a part of a RAID5 array (I haven't done the math, but it doesn't appear to be a RAID-1 array). You will need to "dismantle" the RAID-5 array before you re-partition, or else you risk losing ALL of your data.

I hope this answers some of your questions... I'm sure I missed something, as I'm a little tight for time this AM, so write back whatever may still be on your mind...

Dan
IT4SOHO

Author

Commented:
Dan:  Thank you very much for this very complete and helpful reply.  


> One final note -- the existing partitions look as though they may be a part of a RAID5 array (I haven't done the math, but it doesn't appear to be a RAID-1 array). You will need to "dismantle" the RAID-5 array before you re-partition, or else you risk losing ALL of your data.

It is supposedly a RAID-1 (set up by 1and1 during the server imaging process; I actually have not idea how it works).  Do you have do dismantle this?  I am not concerned about any of the data in the sense of a backup, but I want to system to run as if it was a fresh install (which it is) but with the new partitioning scheme.  So, in the latter sense, I do indeed want to save the data.


>  1) parted won't resize a partition over top of another partition -- so you need to remove the other partitions first

This was a big and stupid mistake on my part.  I thought that when I resized the swap partiion, parted had indeed used part of another partition (which struck me as strange, but convenient in this case), but looking again, it did not.  So, I had expected that when I did the second resize, it would overwrite in the same manner.  


Regarding the rest of the issues you discussed, I'm with you all the way and have no concerns.  

Author

Commented:
Below is my second attempt at repartitioning.  This time, I removed partition 4 (=>4-7), then moved the swap partition, and then tried to move the root partition but got the "strange layout" message again.  Maybe I need to do something about this raid stuff, about which I know nothing:  I've never used software-based RAID before and this was set up for me in the server imaging process.  

(parted) print
Disk geometry for /dev/sda: 0.000-238475.179 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031    964.841  primary   ext3        raid
2        964.841   2878.835  primary   linux-swap
4       2878.835 238472.688  extended
5       2878.866   7655.976  logical   xfs         raid
6       7656.007  12433.117  logical   xfs         raid
7      12433.148 238472.688  logical   xfs         raid
(parted) rm 4
(parted) rm 5
Error: Partition doesn't exist.
(parted) rm 6
Error: Partition doesn't exist.
(parted) pring
  check MINOR                   do a simple check on the filesystem
  cp [FROM-DEVICE] FROM-MINOR TO-MINOR      copy filesystem to another partition
  help [COMMAND]                prints general help, or help on COMMAND
  mklabel LABEL-TYPE            create a new disklabel (partition table)
  mkfs MINOR FS-TYPE            make a filesystem FS-TYPE on partititon MINOR
  mkpart PART-TYPE [FS-TYPE] START END      make a partition
  mkpartfs PART-TYPE FS-TYPE START END      make a partition with a filesystem
  move MINOR START END          move partition MINOR
  name MINOR NAME               name partition MINOR NAME
  print [MINOR]                 display the partition table, or a partition
  quit                          exit program
  rescue START END              rescue a lost partition near START and END
  resize MINOR START END        resize filesystem on partition MINOR
  rm MINOR                      delete partition MINOR
  select DEVICE                 choose the device to edit
  set MINOR FLAG STATE          change a flag on partition MINOR
(parted) print
Disk geometry for /dev/sda: 0.000-238475.179 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031    964.841  primary   ext3        raid
2        964.841   2878.835  primary   linux-swap
(parted) resize 2 237475.179 238475.179
Error: Error informing the kernel about modifications to partition /dev/sda2 -
Device or resource busy.  This means Linux won't know about any changes you made
to /dev/sda2 until you reboot - so you shouldn't mount it or use it in any way
before rebooting.
Ignore/Cancel? I
(parted) print
Disk geometry for /dev/sda: 0.000-238475.179 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031    964.841  primary   ext3        raid
2     237476.470 238472.688  primary   linux-swap
(parted) resize 1 0 237476.469
No Implementation: This ext2 filesystem has a rather strange layout!  Parted
can't resize this (yet).
(parted)
Daniel McAllisterPresident, IT4SOHO, LLC

Commented:
I'm not sure, but I believe you have made 2 very closely related errors:
 1) you assumed 1&1 would do a "simple" Linux install on "raw" partitions, and
 2) you have chosen to ignore the "raid" label parted shows you for each of the raw partitions...

Therefore, I suspect that the "strange layout" is due to the use of software RAID (mdadm). If this were the case, then the parted program, in looking only at the "raw" partition wouldn't see the data layout expected for a filesystem (because it would be stripped by the use of the RAID drivers).

If 1&1 has created your system with a RAID array, you'll want to resize the RAID parttions, not the raw disk partitions.  See this website for details on re-sizing RAID (mdadm) partitions:
http://www.howtoforge.com/how-to-resize-raid-partitions-shrink-and-grow-software-raid

I hope this helps!

Dan
IT4SOHO
Daniel McAllisterPresident, IT4SOHO, LLC
Commented:
My apologies for the above post, as I wrote it before reading your 2nd reply... and it appears that you ARE aware that you are using a RAID array... so the issue now is purely how that will work.

A RAID-1 array on a single hard drive is of virtually no value -- the point of a RAID-1 array is to duplicate all data so that a hardware failure on one device is recoverable by using the second. But if both halves of the mirror are on the same hard drive, then when one "side" of the mirror fails due to a hardware failure, the other side will have failed too (same hardware!).

Now the folks at 1&1 are not stupid (at least, not in my experience)... so I suspect that we're dealing with multiple devices -- another reason why parted would complain about your attempted changes.

So, the method you will use to repartition will likely be the one I linked you to above, but I would like to see the output of a "df -h" command first... this will show us the filesystems that are mounted and the device names they are using to access the hardware.

Thanks! I think we're making progress!

Dan
IT4SOHO

Author

Commented:
> but I would like to see the output of a "df -h" command first

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md1              950M  144M  758M  16% /
/dev/md5              4.7G  440M  4.3G  10% /usr
/dev/md6              4.7G   19M  4.7G   1% /var
/dev/md7              221G  4.6M  221G   1% /home
none                  996M     0  996M   0% /tmp


Here's what I go when trying to follow
http://www.howtoforge.com/how-to-resize-raid-partitions-shrink-and-grow-software-raid
:
rescue:~# modprobe md
modprobe: Can't open dependencies file /lib/modules/2.6.27.35-20090930a/modules.dep (No such file or directory)
... and analogous errors for the other modprobe commands.  


> A RAID-1 array on a single hard drive is of virtually no value -- the point of a RAID-1 array is to duplicate all data so that a hardware failure on one device is recoverable by using the second. But if both halves of the mirror are on the same hard drive, then when one "side" of the mirror fails due to a hardware failure, the other side will have failed too (same hardware!).
> Now the folks at 1&1 are not stupid (at least, not in my experience)... so I suspect that we're dealing with multiple devices -- another reason why parted would complain about your attempted changes.

There are two "identical" 250GB drives that are configured as a RAID-1 set/pair.  But, yes, it would be entertaining is someone set up RAID-1 across two partitions on the same drive.  


Thought I might toss this into the mix as well since it might shed some light on the RAID situation:
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [faulty]
md1 : active raid1 sdb1[1] sda1[0]
      987840 blocks [2/2] [UU]
     
md5 : active raid1 sdb5[2] sda5[0]
      4891648 blocks [2/1] [U_]
        resync=DELAYED
     
md6 : active raid1 sdb6[2] sda6[0]
      4891648 blocks [2/1] [U_]
        resync=DELAYED
     
md7 : active raid1 sdb7[2] sda7[0]
      231464384 blocks [2/1] [U_]
      [=================>...]  recovery = 87.1% (201757376/231464384) finish=7.8min speed=63040K/sec
     
unused devices: <none>
#
Daniel McAllisterPresident, IT4SOHO, LLC

Commented:
OK, so I am guessing that you want / need a partition with more than 221GB available?

Or are you just trying to get everything onto 1 partition "for grins & giggles"?

If there really is a need here, what you'll need to do is to:
1) Free up the use of the /usr partition
 1a) create a new directory at something like /usr1 (it needs to be on the / partition)
 1b) create a complete duplicate of /usr at /usr1 (I recommend a "dump" piped into a "restore")
 1c) unmount /usr & rename /usr1 to /usr
2) Repeat for the /var partition
3) You will still have room, so you can repeat for the existing /home partition

Next, follow the instructions at
http://www.gnu.org/software/parted/manual/html_chapter/parted_7.html

The key here is to remember that you're working primarily with md devices, NOT sd devices!

But I must say, all this effort to add about 10GB to a system with 220 GB already available in one chunk seems to me to be a lot of work for a very little benefit!

Good Luck either way!

Dan
IT4SOHO

PS: If your intent is to remove the RAID-1 and use the 2x 250GB drives in something like a RAID-0, then I'm afraid you'll be very unhappy to hear that 1&1 won't support that (and for good reason).

Author

Commented:
>  OK, so I am guessing that you want / need a partition with more than 221GB available?
Yes I do, but the issue is not this but that the 221GB is allocated to the /home partition (which is crazy for the typical use of these servers, ie, a web server).  If the bulk of the space was allocated to the /var partition, for example, it would be just fine.

> But I must say, all this effort to add about 10GB to a system with 220 GB already available in one chunk seems to me to be a lot of work for a very little benefit!

This is true, but again the big chunk is /home.  That said, it is probably easier to just use symlinks to put the dirs that need space into the /home partition.  That's what I'm going right now.  
Daniel McAllisterPresident, IT4SOHO, LLC

Commented:
Your last comment is EXACTLY what I was going to recommend.... but you don't even need sym-links for the web server!

On my own servers, /var contains my configurations for my web server -- but I am a hosting provider -- so I have an array of domain names for which I host domains.

In my /home partition, I have a folder for clients -- and everything for that client is stored in that folder (makes checking storage utilization VERY easy!). Inside each /home/client folder there is an e-mail and a web folder. Inside each /home/client/web folder are the domains for which that client is paying.

So, the DocumentRoot for example.com (a domain owned by client1) would point to:
 /home/client1/web/example.com

Similarly, in my mail server, the root folder for the example.com domain's e-mail messages is located at /home/client1/e-mail/example.com. But, since I use vpopmail, that is accomplished by making a symbolic link from /home/vpopmail/domains/example.com to /home/client1/e-mail/example.com

Good Luck!

Dan
IT4SOHO

Author

Commented:
I'm with you.  Good thoughts.  

The main issue is really data, not the DocumentRoot.  In particular, this means mysql data, ie, /var/lib/mysql.  So, I created a symlink for that into /home/var/lib/mysql.  That pretty much covers it.  
Daniel McAllisterPresident, IT4SOHO, LLC

Commented:
Yes, I usually sym-link /var/lib/mysql to something like /home/mysql so that the database is not on the root partition.

I would think, given the circumstances, that a single / partition would be sufficient (even preferable). Personally, the only reason I use a /home partition is so it can be formatted with an XFS filesystem (which I prefer for Samba shares).

Best of luck -- and don't forget to close the question!

Dan
IT4SOHO

Author

Commented:
Update:  May have another server soon on which to work through this.  Unfortunately, at this time I can't.  But, thank you and I will post again when I have a server to work with to do this.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial