Part 01
Vagrant Guide
Vagrant is an open-source tool for building and managing virtualized environments. It provides easy-to-use workflows for working with different development environments.
Installation
1. Install VirtualBox
Vagrant requires a provider such as VirtualBox. Download and install it from VirtualBox Downloads.
2. Install Vagrant
Download and install Vagrant from Vagrant Downloads.
Verify the installation:
vagrant --versionGetting Started with Vagrant
1. Initialize a New Project
To create a new Vagrant environment:
vagrant init bento/ubuntu-24.04 --box-version 202407.23.0This command creates a Vagrantfile in your project directory, which describes the virtual machine configuration.
2. Start the Virtual Machine
Run the following to launch the VM:
vagrant up3. SSH into the Virtual Machine
Log into the virtual machine using SSH:
vagrant ssh4. Shut Down the Virtual Machine
When done, halt the VM:
vagrant haltCommon Commands
| Command | Description |
|---|---|
vagrant init | Initialize a new Vagrant environment. |
vagrant up | Start the Vagrant environment. |
vagrant ssh | SSH into the Vagrant machine. |
vagrant halt | Stop the virtual machine. |
vagrant destroy | Remove the virtual machine. |
vagrant status | Check the status of the virtual machine. |
vagrant provision | Apply changes in the Vagrantfile to the VM. |
vagrant reload | Restart the VM with updated configurations. |
Basic Vagrantfile Example
Below is a sample Vagrantfile:
Vagrant.configure("2") do |config|
# Define the box to use
config.vm.box = "hashicorp/bionic64"
# Define the virtual machine's network
config.vm.network "private_network", type: "dhcp"
# Share a folder between the host and the guest
config.vm.synced_folder "./data", "/vagrant_data"
# Customize VM resources
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 2
end
endAdditional Resources
Linux Basics Tutorial
Introduction to Linux
Linux is an open-source operating system widely used in servers, desktops, and embedded systems. It’s known for its stability, security, and versatility. Linux is based on the Unix operating system and provides a command-line interface (CLI) for users to interact with the system.
Basic Linux Commands
Navigating the File System
pwd
Prints the current working directory.pwdls
Lists files and directories in the current directory.ls ls -l # For detailed listing ls -la # for hiddent file starting with .cd
Changes the current directory.cd /path/to/directory cd ~ # Goes to the home directorymkdir
Creates a new directory.mkdir new_directoryrmdir
Removes an empty directory.rmdir directory_namerm
Removes files or directories.rm file_name rm -r directory_name # Removes a directory and its contents
File and Directory Operations
touch
Creates an empty file or updates the timestamp of an existing file.touch new_file.txtcp
Copies files or directories.cp source_file destination_file cp -r source_directory destination_directory # For directoriesmv
Moves or renames files or directories.mv old_name new_name mv file_name /path/to/destination
Viewing File Content
cat
Displays the contents of a file.cat file.txtless
Opens a file for reading, allowing scrolling through the content.less file.txthead
Displays the first 10 lines of a file.head file.txttail
Displays the last 10 lines of a file.tail file.txt
Searching Files and Directories
find
Finds files and directories by name, type, and other attributes.find /path/to/search -name "filename.txt"grep
Searches for a specific pattern inside a file.grep "search_pattern" file.txt
File Permissions
chmod
Changes file permissions.chmod +x file.sh # Adds execute permission chmod 755 file.sh # Sets specific permissionschown
Changes file owner and group.chown user:group file.txt
Process Management
ps
Lists running processes.ps aux # Lists all processestop
Displays system processes in real-time.topkill
Terminates a process by its process ID (PID).kill PID
Package Management (Debian/Ubuntu)
apt update
Updates the list of available packages.sudo apt updateapt upgrade
Upgrades installed packages to their latest versions.sudo apt upgradeapt install
Installs a new package.sudo apt install package_nameapt remove
Removes an installed package.sudo apt remove package_name
User and Group Management
useradd
Creates a new user.sudo useradd usernamepasswd
Changes the password for a user.sudo passwd usernamegroupadd
Creates a new group.sudo groupadd group_name
3. File System Structure
Linux uses a hierarchical file system structure, where everything is under the root directory /. Below are common directories:
/- Root directory/home- User home directories/etc- Configuration files/var- Variable files (e.g., logs)/usr- User programs and data/tmp- Temporary files
4. Basic Shell Scripting
Create a script
Create a new file and add a shebang at the beginning (#!/bin/bash), followed by commands.nano script.sh #!/bin/bash echo "Hello, Linux!"Make the script executable
chmod +x script.shRun the script
./script.sh
Check the currently logged in user
whoamiLog in with root
sudo -sCheck memory usages
free -mDisk Management
- Check all disk available
fdisk -l
lsblk- Check block id of a disk
blkid- Check Disk space
df -sh- Check disk usgaes
du -sh *- How to format a disk
mkfs.ext4 /dev/sdc- How to mount to a directory ?
mkdir /data
mount /dev/sdc /data- Mount this permanenetly
vi /etc/fstab
/dev/sdc ext4 /data defaults 0 0- Update the fstab
mount -a- Test after rebooting your Server if you want
reboot
init 6