1

This sounds like a very basic question, but I have yet to find an answer for it.

I have a partition layout which looks like this:

NAME           MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
xvda           202:0    0  108G  0 disk
├─xvda1        202:1    0   46G  0 part  /
├─xvda2        202:2    0    1K  0 part
└─xvda5        202:5    0    2G  0 part
  └─cryptswap1 252:0    0    2G  0 crypt
xvde           202:64   0  1.5G  1 disk
└─xvde1        202:65   0  1.5G  1 part
xvdf           202:80   0    6G  1 disk

How can I grow the first partition xvda1 ? I only have remote command line only access to the server.

I tried using resize2fs but it seems to fail with a cryptic error

   $ sudo resize2fs /
   resize2fs 1.42.12 (29-Aug-2014)
   open: Is a directory while opening /

EDIT: This is the result from gparted. Rebooting is not a problem, and I do have a backup ready (but I would prefer not to need it of course).

Command (m for help): p
Disk /dev/xvda: 108 GiB, 115964116992 bytes, 226492416 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000da796

Device     Boot    Start       End  Sectors Size Id Type
/dev/xvda1          2048  96452607 96450560  46G 83 Linux
/dev/xvda2      96454654 100661247  4206594   2G  5 Extended
/dev/xvda5      96454656 100661247  4206592   2G 82 Linux swap / Solaris

And the output of "sudo parted -l /dev/xvda"

bob@bob:~% sudo parted -l /dev/xvda
[sudo] password for bob:
Model: Linux device-mapper (crypt) (dm)
Disk /dev/mapper/cryptswap1: 2154MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system     Flags
 1      0.00B  2154MB  2154MB  linux-swap(v1)


Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 116GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  49.4GB  49.4GB  primary   ext3
 2      49.4GB  51.5GB  2154MB  extended
 5      49.4GB  51.5GB  2154MB  logical


Model: Xen Virtual Block Device (xvd)
Disk /dev/xvde: 1611MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      4000kB  1611MB  1607MB  primary  ext3


Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdf: 6442MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  6442MB  6442MB  ext3
Byte Commander
  • 107,489
Markus
  • 111
  • We can't resize a mounted partition (which apparently also is your root partition). – Takkat Jan 26 '16 at 12:45
  • You can't repartition directories (mount points), but only partitions. And usually you need to unmount a partition before you can resize it, but some file systems (including ext4) support growing of mounted partitions to the right (i.e. the start of the partition stays at the same position). There was a question about this, let me look it up... – Byte Commander Jan 26 '16 at 12:45
  • 2
    Possible duplicate of How can I resize an ext root partition at runtime? <-- look at the answer by Søren Løvborg, he describes both enlarging the partition and resizing the file system to match the new partition boundaries nicely. But make sure to *have a BACKUP!* – Byte Commander Jan 26 '16 at 12:48
  • @ByteCommander thanks. xvda1 is definitly ext4, but I'm not sure about xvda2 and xvda5. Does that matter? can I also use resize2fs if xvda2 and xvda5 is located to the right of xvda1 ? (which is looks like they are). And yes, I do have a backup :) – Markus Jan 26 '16 at 12:52
  • 1
    To increase the virtual hard drive /xvda you'd also need access to the XenServer command line interface. Otherwise the most you may get is 2 GB from disabling swap (xvda5). – Takkat Jan 26 '16 at 13:01
  • @Takkat I may have misunderstood someting. But I do not want to grow xvda. Xvda is already 100 GB, but my main/root partition (xvda1) is only 46 GB. However, I am unsure how to grow it when there are two minor partitions located right behind it. – Markus Jan 26 '16 at 13:03
  • @Markus: from your update it appears that swap is on a logical partition xvda5 within xvda2... try to disable swap. You then may be able to move xvda2 to the end of xvda in order to be able to grow xvda1. I have however no idea if Xen has some extra tools to make that more comfortanle. – Takkat Jan 26 '16 at 13:12
  • Please add the output of sudo parted -l /dev/xvda (or sudo parted -l if the other doesn't work) to your question ([edit] it!). It will show us where the exact partition boundaries are and where the free space is located. Thanks. – Byte Commander Jan 26 '16 at 13:36
  • @Markus Okay, the free space seems to be located at the end of the xvda drive. That means you need to move xvda2 (which contains xvda5) to the end of the disk. To do that, first make sure they're both unmounted (and swap is off). Then grow xvda2 to occupy all available space, move xvda5 inside it to the right border, and shrink xvda2 again to its minimum size by moving its left border. Then you have about 60 GB space after xvda1. At this point, you can follow the linked question. – Byte Commander Jan 26 '16 at 14:05
  • @ByteCommander thank you a lot! I will try that, but it may have to wait until tomorrow – Markus Jan 26 '16 at 14:06
  • You're welcome @Markus. :) – Byte Commander Jan 26 '16 at 14:08

1 Answers1

1

It won't be possible to extend /dev/xvda1 directly, but since your xvda volume only appears (according to your fdisk output) to have 46G+2G used, you should be able to create another partition on the disk and mount it over the area of the root filesystem where you need more space.

For example, if you needed more space for user101's home area, you could use one of 2 approaches:

1) Create /dev/xvda3 as a partition that uses up the rest of the disk, create an EXT4 filesystem on it, then mount that over /home/user101. The biggest disadvantage of this approach is that you would have to resort to things like symbolic links or bind mounts if you needed extra disk space in more than 1 area.

or,

2) Create /dev/xvda3 as a partition using the rest of the disk, make it a LVM physical volume, put that into a volume group, then create logical volumes out of that volume, mounting them as required. This approach lets you have as many different filesystems as you need (within reason), but the initial setup is more complex. On the flip side, these filesystems can be extended as required with lvextend (and with the -r option, the filesystem is automatically increased to match the volume size).

  • Your suggestions are a valid alternative, but it's wrong that growing a mounted ext4 partition without moving its start point does not work. Please read my comments below the question to learn how it can be done. :-) – Byte Commander Jan 26 '16 at 14:10
  • I never suggested growing the existing root partition. In fact, it's a downright dangerous operation, although the likes of gparted do a fine job of working with the GUI to do this. – Uditha Desilva Jan 26 '16 at 14:15
  • It never failed on my systems yet. It may, as all partitioning operations, but it's not necessarily dangerous. Have a backup and you can sleep well. – Byte Commander Jan 26 '16 at 14:16