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.
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!
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.
❯ 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.
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.
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!
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.
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.
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.
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. 🙂
I searched my blog for it thinking I am sure I blogged it before but it turned out that I have not. This is a very useful command when you want to know the size of directories.
du -h --max-depth=1
I did remember it and I was able to use it just now… Where did I remember that… I probably tried to memorize it before.
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!