Ubuntu – Add a new partition to Ubuntu and append it to /var/www/


I have installed an Ubuntu server on a VMWare workstation with a space of 20GB storage as seen below;

enter image description here

After the installation I've attached another 40GB worth storage to the existing Ubuntu server installation (seen below);

enter image description here

Now I want to add this 40GB to my / (root) directory or to /var/ directory but my df -h result shows;

root@Userver:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        18G  900M   16G   6% /
udev            990M  4.0K  990M   1% /dev
tmpfs           400M  308K  399M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            999M     0  999M   0% /run/shm
none            100M     0  100M   0% /run/user

What should I do now? Further, I have only ssh access to the server.

Best Answer

First, create a new partition on the second hard disk drive sdb and fomrat it, this can be done in one step:

# sudo mkfs.ext4 /dev/sdb -I

Then mount the created partition on the /var/www/ folder

# sudo mount /dev/sdb1 /var/www

Note that the www folder should be empty, if not move its contents to another folder, mount the new drive and move the files back again to www.

To make mounting permanent so you won't need to mount the drive every time you restart the machine, add the following line to /etc/fstab

/dev/sdb1   /var/www/   ext4    defaults    1   1
Related Question