2

I want my data from /dev/sda1 partition to automatically "overflow" to the /dev/vda partition. So I think my question is: how do I combine the 2 partitions so / becomes 138GB in size?

root@vps:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           780M   34M  747M   5% /run
/dev/sda1        39G  7.7G   32G  20% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           780M     0  780M   0% /run/user/1000
/dev/vda         99G   60M   94G   1% /mnt/vda

And these are the available disks:

root@vps:/# fdisk -l
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 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


Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0xffcebafc

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1  *     2048 83886046 83883999  40G 83 Linux

I have not much knowledge of this so I might not ask the right questions.

1 Answer 1

2

Given that you're dealing with two physical devices, you won't be able to combine the partitions at the physical level. But, you can use LVM (logical volume manager) to create what amounts to a virtual block device which consists of multiple real block devices. That would simulate a partition of ~138GB. It's also possible to do something similar at the filesystem level using BTRFS, but here's what you can do with LVM:

NOTE: Aside from LVM support, your system will need the ability to boot from LVM, which depends on your boot loader and how it's configured.

Converting to LVM

Obviously, make sure you back up your system first, since this process will wipe out /dev/sda1 and /dev/vda. Then boot Linux from a Live CD/USB drive and...

  1. Run wipefs /dev/vda to quickly clear out the partition.
  2. Create an LVM physical volume by running pvcreate /dev/vda
  3. Create a volume group: vgcreate vg0 /dev/vda
  4. Create a logical volume for your root filesystem: lvcreate -L80G -n rootfs vg0. Don't worry about the size of 80 GB; that's to be increased later.
  5. Put a filesystem on the logical volume, say... ext4: mkfs.ext4 -L ROOTFS /dev/vg0/rootfs
  6. Mount the new filesystem to say... /mnt/newroot: mount -L ROOTFS /mnt/newroot
  7. Since you'd be doing this from a live CD, you'll need to mount the real / somewhere, say... /mnt/oldroot: mount /dev/sda1 -o ro /mnt/oldroot
  8. Copy the old root to what will become the new root: cp -aR /mnt/oldroot/* /mnt/newroot/

Now, so far, other than loosing whatever was in /dev/vda, nothing irreversible has taken place. So this is the perfect opportunity to set up your boot loader (ex. GRUB2) to boot from /dev/vg0/rootfs and make sure you can boot. Everything should be the same except your df output should look something like this:

root@vps:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           780M   34M  747M   5% /run
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           780M     0  780M   0% /run/user/1000
/dev/vg0/rootfs  99G  7.7G   92G   ?% /

If you get that far, then you can proceed with the following to leverage LVM's magical powers. With some filesystems, such as EXT4, the following can be done on the live system; no live CD needed.

  1. Wipe out the old root: wipefs /dev/sda1
  2. Create a new physical volume: pvcreate /dev/sda1
  3. Add the new physical volume to LVM: vgextend vg0 /dev/sda1

At this point, the two partitions are available for LVM's use, but not yet utilized. To use both partitions (actually they are LVM physical volumes now) for your /, extend the root logical volume to consume all the space available:

  1. Enlarge the logical volume: lvextend -l 100%FREE /dev/vg0/rootfs
  2. Enlarge the filesystem: resize2fs /dev/vg0/rootfs

That should give you a root filesystem ~138GB in size :)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.