2

I'm currently using Ubuntu 14.04.2 Server on Oracle VM VirtualBox as I'm trying to understand the deployment to be ready to deploy it in a real network.

Here is the situation. Currently, I have assigned a 8GB HDD to the VM which I use for the system. Now, I want to add another HDD, say 12GB, to be used with Samba for storing files to be shared among multiple users.

What I need to be able to do is:

  1. Add a new 12GB HDD to the VM
  2. Link the newly added HDD to the system
  3. Mount it as /srv/share/ which will be used with the Samba

What I also need to know, is the process the same for a real hardware?

The base HDD is 500GB and the secondary is 1TB

sikas
  • 143

1 Answers1

4

These are minimum steps to create and attach a new virtual hard drive to an existing virtual machine:

In the host:

  1. Create a virtual hard drive

    VBoxManage VBoxManage createhd --filename <path/to/name.vdi> --size <in MB>
    
  2. Attach this drive to the VM

    VBoxManage storageattach "<VM name" --storagectl SATA-Controller --port <number> --type hdd --medium </path/to/name.vdi>
    
  3. Boot the virtual machine

Alternatively we may also just add a new partition to an already attached exisiting virtual drive by increasing it's size which then needs to be partitioned too.

In the guest:

  1. Partition the new drive

    You may want to find out the device decriptor of the new drive with sudo fdisk l first.

    sudo parted /dev/<sdx> ## run parted on device sdx
    (parted) mklabel msdos ## create a msdos partition
    (parted) mkpart primary ext4 1MiB 100% ## create primary ext4 partition using whole disk
    (parted) quit
    
  2. Format the new partition

    sudo mkfs -t ext4 </dev/sdX1>
    
  3. Mount this partition

    sudo mount <options> /dev/sdx1 <mountpoint>
    
  4. If mounting in 4. worked then optionally put an entry in /etc/fstab for mounting on boot:

    <UUID>   <mountpoint>   ext4    <options>    0    2
    

    The <UUID> can be read from sudo blkid, <options> as for mount.

All steps can of course also be performed from a GUI. For steps 1. to 3. this would be the Virtual Box Manager in the host. For steps 4. to 5. it would be gparted in the guest (e.g. by temporarily booting to a live Ubuntu). Manual mounting needs a terminal, editing fstab can be done with any editor.

For more details on creating virtual hard drives also see the Virtual Box Manual.

Takkat
  • 142,284
  • Thank you Takkat for the guidance .. Got couple of points I need to check/confirm .. 1) The same guide will work normally with a real machine, except that steps 1-3 will be installing another HDD, right? 2) After finishing the above, on the reboot, the box hangs until I skip the mount of the new partition .. I feel I'm missing something here – sikas Mar 24 '16 at 09:42
  • @sikas: your ftsab entry may have an issue... any errors on mounting manually (resp. sudo mount -a)? – Takkat Mar 24 '16 at 09:55
  • nope, sudo mount -a works fine ... – sikas Mar 24 '16 at 09:56
  • well, actually, I had an issue with the type .. it was ext instead of ext4 .. corrected that and worked fine .. – sikas Mar 24 '16 at 09:56
  • can you check point 1, in my first comment, and advise on it? – sikas Mar 24 '16 at 09:57
  • yeah, partitioning with parted and mounting is the same on bare metal. – Takkat Mar 24 '16 at 09:58
  • If you are uncomfortable using the CLI you can also partition with booting a graphical live system to use gparted. – Takkat Mar 24 '16 at 09:59
  • I'm using Ubuntu Server, so I have to use CLI only .. I can deal with it, but sometimes I miss-type :( – sikas Mar 24 '16 at 10:00