Arch Diaries : What to do when your virtual hard disk is out of memory in virtualbox?

So this happened while I was setting up my Arch Linux installation on Virtualbox. While installing LightDM I got an error saying there isn’t enough space in my / (root partition mounting point). My setup for the drive partition was :

1
2
3
4
5
NAME SIZE MOUNTPOINT
- sda
-- sda1 2GB /
-- sda2 2GB /home
-- sda3 1GB swap

I soon realised my mistake , I needed more space in my root partition but Virtualbox won’t allow me to increase the hardisk size. The only option would be to repeat the entire process ,
create a virtual machine with a larger hard drive --> install Arch.

I was looking for a smarter way to avoid repeating the entire procedure. Based on a hunch I created a new hard drive NewVirtualDisk.vdi for the Arch installation :
NewVirtualDisk

The new hard drive was mounted as /dev/sdb. My plan was to move the /home partition to the 8GB volume and give the entire 5GB to the / partition . This way both the root and home will have good amount of space.

The first step was to format the raw 8GB volume into ext4 and make a primary partition in it :

1
$ sudo mkfs.ext4 /dev/sdb #format /dev/sdb to ext4

1
2
3
4
5
$ sudo umount /dev/sdb
$ sudo fdisk /dev/sdb
$(fdisk console) p #print existing partition table
$(fdisk console) n #create a new partition
$(fdisk console) w #commit the changes

The new partition looked like this :

1
2
3
4
5
6
7
8
$ lsblk
NAME SIZE MOUNTPOINT
- sda
-- sda1 2GB /
-- sda2 2GB /home
-- sda3 1GB swap
- sdb
-- sdb1 8GB

Great now I had my hard drive and partitions ready, next step was to safely mount /home in /dev/sdb1 instead of current /dev/sda2.

Here comes the interesting part, for making changes to the mounting point of /home we need to first edit the fstab file which we generated during our installation.

The fstab or File Systems Table is a system configuration file that typically lists all available disk partitions indicating how they are to be initialized or otherwise integrated into the larger file system structure. It is read by mount command, which happens automatically at boot time to determine the overall file system structure.

fstab is found at /etc/fstab and can be set up in two modes , either using the uuid or label of the partitions. Both the label and uuid info of partitions can be found by :

1
$ lsblk -f

To make changes to fstab one needs root priviledges :

1
$ sudo nano /etc/fstab

In the fstab, we have to replace the label or uuid of sda2 with sdb1 in /home mount point section. This is how my fstab looked like after the changes :
fstab

As can be seen , /home is now supposed to be mounted on /dev/sdb1.

Now since the mount command reads fstab just a single unmounting and remounting process will mount /home correctly onto /dev/sdb1 but we need to change to / before we can unmount/mount /home because you can’t unmount the file system you are currently in.

1
2
3
$ cd / # switch to root
$ sudo umount /home
$ sudo mount /home

Doing lsblk now showed /home is correctly mounted on /dev/sdb1 but there was an issue, when I tried changing to my home directly it threw an error.

1
2
$ cd
error : could not find home/sanad

This error took me quite long to understand. What this meant was there was no sanad directory in our new /home. This was because the installation was done on sda2 and the entire folder of user sanad was there. What to do now? Simple, Copy all the contents of the folder from the other partition ! (by the way this was a hunch)

First I needed to mount the previous partition /dev/sda2 at a temporary place. Google helped me find that /mnt is used for the very same purpose.

1
2
$ sudo mount /dev/sda2 /mnt
$ sudo cp -r -v /mnt/sanad/ home/

The above did the trick. The new /home had all the settings , data of the user sanad. Everything should work fine right? This time when I tried to CD to home I got another error :

1
2
$ cd
error : permission denied

This was because I didn’t had enough permissions to read/execute/write to the sanad folder. A simple setting of ownerships and permissions fixed it.

1
2
3
4
5
6
7
$ sudo chown -R sanad home/sanad # change ownership of home folder to sanad
$ sudo chmod u+rwx home/sanad # give the read,write and execute permissions to the current owner (in this case 'sanad')
$ cd #change directory to home/sanad will work
$ ls -l #check permissions and ownership
total 8
drwx------ 2 root root 4096 Nov 3 11:59 lost+found
drwx------ 4 sanad root 4096 Nov 3 12:37 sanad

finally, cd took me to my home directory and I was able to use it normally :)

This is how the setup looked like after the last step:
final setup

This was just the first step, now the next steps would be :

1) Delete the partitions sda2 and sda3

2) Extend sda1 to use entire 5GB volume (by maybe using chroot and fdisk)

3) Resize the file system for the new size of the partition ( maybe resize2fs).

P.S. : I would like to thank amazing Arch Linux Community and OracleVirtualBox Team and Community for all their support. You guys rock! I am learning a lot by this method of self exploring because of DIY nature of Arch , thanks for that too.

Till then, stay tuned and Happy Hacking!

-Sanad
For corrections/suggestions : mohdsanadzakirizvi@gmail.com