Vagrant Error

I came across a situation where “vagrant up” just wasn’t successful. “vagrant halt” and “vagrant destroy” didn’t do it. I even removed everything from ~/.vagrant.d but it still kept on failing with the following error.

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["import", "/home/hiriumi/.vagrant.d/boxes/oraclelinux-VAGRANTSLASH-7/7.9.289/virtualbox/box.ovf", "--vsys", "0", "--vmname", "OL7U9_x86_64-vagrant-virtualbox-b289_1643606820210_37412", "--vsys", "0", "--unit", "11", "--disk", "/media/hiriumi/extra/OL7U9_x86_64-vagrant-virtualbox-b289_1643606820210_37412/box-disk001.vmdk"]

Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Interpreting /home/hiriumi/.vagrant.d/boxes/oraclelinux-VAGRANTSLASH-7/7.9.289/virtualbox/box.ovf...
OK.
0%...
Progress state: NS_ERROR_INVALID_ARG
VBoxManage: error: Appliance import failed
VBoxManage: error: Code NS_ERROR_INVALID_ARG (0x80070057) - Invalid argument value (extended info not available)
VBoxManage: error: Context: "RTEXITCODE handleImportAppliance(HandlerArg*)" at line 1119 of file VBoxManageAppliance.cpp

I even opened VirtualBox to check if a leftover VM was still there but there wasn’t. When I navigated to the directory where VirtualBox creates VMs and there was a directory leftover from the failed instance. I manually removed the directory where VirtualBox stores VM files and did “vagrant up” and then things came back to normal.

Hope this helps someone out there. 🙂

How to Create Partitions on a New Disk on Linux

I seldom add and remove disks on my Linux machine but I added a new disk on my Linux desktop machine just now, so I am going to summarize what I am doing here now. The commands I am showing in this blog can applied to any cloud environment as well.

I added a Kensington SSD (500 GB) disk. I want to list the disks attached to my Linux. Here is what you can do.

lsblk

Here is the result:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 447.1G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
└─sda2   8:2    0 446.6G  0 part /
sdb      8:16   0 447.1G  0 disk 
└─sdb1   8:17   0 447.1G  0 part

You can alternatively list disks and their partitions with fdisk.

sudo fdisk -l
Disk /dev/sdb: 447.13 GiB, 480103981056 bytes, 937703088 sectors
Disk model: KINGSTON SA400S3
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: 0xc979445b

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdb1  *     2048 937701375 937699328 447.1G 83 Linux

lsblk shows the disks and the partitions. The disk I just added is sdb and it has sdb1 partition. I want to remove the partition, recreate it and format it from the terminal. Here is how you can remove the partition sdb1.

Though fdisk shows more detailed information, lsblk seems to be easier to read.

To remove the sdb1 partition, we’ll select the disk first with fdisk.

sudo fdisk /dev/sdb

You will see a prompt like the following:

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

By entering m, you get the pretty good list of what you can do with it.

If you enter ‘d’, you get to remove the partition. As you may have seen, sdb disk that I have has only 1 partition, so partition 1 is automatically selected. If the disk has multiple partitions, you can select a partition by entering its number.

When I enter ‘i’, I get to print information about a partition but since I removed the only partition, it cannot print anything.

Command (m for help): i
No partition is defined yet!

Now you can save the change you just made by entering ‘w’. When you do that, it exits fdisk. Just to see it, you can run lsblk again and you don’t see any partition anymore.

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 447.1G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
└─sda2   8:2    0 446.6G  0 part /
sdb      8:16   0 447.1G  0 disk

Creating 2 New Partitions

Select sdb disk with fdisk.

sudo fdisk /dev/sdb

Now I am dividing the disk into 2 partitions.

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-937703054, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-937703054, default 937703054): 468851527

Created a new partition 1 of type 'Linux filesystem' and of size 223.6 GiB.

Command (m for help): n
Partition number (2-128, default 2): 2
First sector (468851528-937703054, default 468852736): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (468852736-937703054, default 937703054): 

Created a new partition 2 of type 'Linux filesystem' and of size 223.6 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

I calculated the last sector number for the partition 1 by dividing the last number of the sector by 2.

Here is the result of lsblk.

❯ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 447.1G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
└─sda2   8:2    0 446.6G  0 part /
sdb      8:16   0 447.1G  0 disk 
├─sdb1   8:17   0 223.6G  0 part 
└─sdb2   8:18   0 223.6G  0 part

sdb is now partitioned into 2 now. Now we have format them and mount them to be able to start to use them. Let’s format them!

❯ sudo mkfs -t ext4 /dev/sdb1
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done                            
Creating filesystem with 58606185 4k blocks and 14655488 inodes
Filesystem UUID: 8c060f92-bf34-4473-993d-da8b52474da3
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

❯ sudo mkfs -t ext4 /dev/sdb2
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done                            
Creating filesystem with 58606289 4k blocks and 14655488 inodes
Filesystem UUID: 3c31b2dc-409d-49ec-a9c2-e23748c49bbe
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

Now create a directory you can mount the partitions.

mkdir ~/extra1
mkdir ~/extra2

Now mount it.

sudo mount /dev/sdb1 /home/hiriumi/extra1
sudo mount /dev/sdb2 /home/hiriumi/extra2

Now I can access those partitions from those directories in my home directory.

However, the mount does not survive restarts. What to do? Let’s take a look at the disk data a little closer with lsblk.

lsblk -fs

We will use UUID to retain the mounts in /etc/fstab file. Be very careful editing the file. If there is an error, your system might not start up correctly and you might get into a rabbit hole of fixing it.

NAME  FSTYPE LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda1  vfat         8FE2-835D                             505.8M     1% /boot/efi
└─sda                                                                  
sda2  ext4         226cfcfc-711c-4b8d-b0f8-67210dfbf8b4    390G     6% /
└─sda                                                                  
sdb1  ext4         8c060f92-bf34-4473-993d-da8b52474da3  207.8G     0% 
└─sdb                                                                  
sdb2  ext4         3c31b2dc-409d-49ec-a9c2-e23748c49bbe  207.8G     0% 
└─sdb 

Now add the 2 lines in /etc/fstab file.

UUID=8c060f92-bf34-4473-993d-da8b52474da3 /home/hiriumi/extra1  ext4
UUID=3c31b2dc-409d-49ec-a9c2-e23748c49bbe /home/hiriumi/extra2  ext4

Now you can constantly access those partitions.

❯ ll | grep extra
drwxr-xr-x 3 root    root    4.0K Jan 30 13:16 extra1
drwxr-xr-x 3 root    root    4.0K Jan 30 13:16 extra2

So many steps huh… If you can use a desktop environment, you can use disks utility to configure disk partitions pretty much visually and as for Linux Mint, it automatically edits /etc/fstab automatically. So what are these steps for? Well, if you are en engineer having to deal with disks and partitions in cloud environments, you cannot escape from these issues.

Making VS Code Terminal Look Cool

I’m a fan of oh-my-zsh and p10k. They makes my terminal look very cool and useful. To make that happen, I have to set the Terminal font to “MesloLGM Nerd Font” or one of the nerd fonts.

After you set that up and start your VS Code, you realize that the terminal part looks all screwy.

You can go to preferences in VS Code and change the font face of the terminal and set the font to make it look cool as well.

Vagrant Images

There are vagrant images out there. I’m starting to look into more images to play with. You can find Oracle Linux vagrant images here.

HashiCorp’s Vagrant Cloud has a selection of available images for different providers. There are not as many as I thought but it’s good enough to spin up test environment.

Now I’m thinking… would Ansible work with Vagrant? I’ll find out!

Installing VS Code on Linux Mint

Fun part of starting a new install of any OS is figuring out how to install and configure your favorite tools. VS Code is one of my favorite tools that I use daily for work and privately.

Here is a way to install VS Code Linux Mint. You can alternatively install it from Software Manager but you cannot launch it from terminal, so here is the way to enable it.

  1. sudo apt update
  2. sudo apt install apt-transport-https
  3. curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
  4. sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
  5. sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
  6. sudo apt update
  7. sudo apt install code

Like I mentioned above, this way you can open VS Code from terminal. When you are navigating around, you may want to open VS Code in the directory. You can just type code . and it opens in that directory. I do that all the time on my work Mac.

How to Show Only Grep Match on a String

This was a little bit of a struggle just because I never had a need for it.

I wanted to get standard output from the result of grep only on a match of a string. I wanted to get the standard output from a grep match of 5 digits in a string. Here is how you can do it.

echo '12345asdf' | grep -oE '[0-9]{5}'

The result is ‘12345’.

Simple enough but took me about 20 mins to figure it out.

Undo a Single File in Git

I just had a need to undo (reset) a single file while I was working on multiple files. I was just testing stuff in different files and I wanted to undo the changes in a single file. Here is what you can do.

git checkout HEAD -- myfile

I think I did this before but I had forgotten it. I’m hoping to remember it by blogging it and help someone out there. 🙂

How to Install Docker Compose 2 on Intel x86_64 Processor

I’m guessing most of the people out there still use Intel x86_64 processor. I am writing a blog article on how to install Docker Compose 2 on it.

  1. Create a directory.
    mkdir -p ~/.docker/cli-plugins/
  2. Download Docker Compose 2 binary for x86_64.
    curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
  3. Give the binary file execute permission.
    chmod +x ~/.docker/cli-plugins/docker-compose
  4. Check if the binary has been installed successfully.
    docker compose version
  5. You should an output like the image below.

Back to Linux Mint

I had my old PC laying around doing nothing for about a year. I am reviving it by putting it back at my desk and installing Linux Mint.

I love the fact that once you install the OS, pretty much everything is good to go. There is no spending so much time to get certain device to work because of driver issues. I can just start to use everything I want.

I cannot emphasize hard enough how great Linux Mint is. I would think it is up for prime time to take over the desktop world. I understand non-tech people may say they cannot play games with Linux. I guess they can just stick with Windows but Linux is very very capable of running computations. This blog runs on Linux, and even really big enterprise sized applications run on Linux. My daily work revolves around it and I am having so much fun.

I am thinking… If you are a tech and don’t even bother to learn Linux, you would have a serious disadvantage as an engineer.

Just recently, my own blog really helped me perform a great work and all of the articles that helped it were related to Linux. Obviously, my company uses Linux for all of our production purposes and I am so glad I spent a lot of time digging into it and blogged about it.

With the latest toy of vagrant, I am having so much fun!