Tagged: tutorial

Vim: Removing ^M characters at the end of lines

Sometimes when editing files in both Windows and UNIX environments, a CTRL-M character is visibly displayed at the end of each line as ^M in vi. This is how to remove those annoying characters:

Disclaimer:
The information below is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others.

:%s/^V^M//g (Ctrl-V)(Ctrl-M)

That's all!
-gibb

slackware64: Installing qemu-kvm and virt-manager

I've been using VirtualBox for a while on my slackware box. It's been working ok but I recently read a couple of blogs/articles recommending KVM. They said that KVM is rapidly becoming the de facto standard for open source visualization. Interesting. So, I gave a shot with qemu-kvm with libvirt (for GUI).

Disclaimer:
The information below is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others.

Terminology:

libvirt
libvirt allows management of different virtualization solutions such as KVM and Xen through a common (programming and user) interface.
virt-manager
A graphical virtual machine manager
KVM (Kernel Virtual Machine)
KVM provides full virtualisation and can run unmodified Linux or Windows images, but it requires CPU virtualisation extensions (Intel VT or AMD-V).
Qemu
Qemu functioning as a userspace, software-only emulation package. It can be used standalone (that is, it does not require a special kernel module, or CPU virtualisation extensions, or a hypervisor layer) and is capable of running unmodified operating system images.

Prerequisite:

The CPU needs to support virtualization in order to take advantage of qemu-kvm. To check, execute below command: $ egrep -c '(vmx|svm)' /proc/cpuinfo

If the CPU supports virtualization, you should get a non-zero value.

Or, as Daniel Berrange suggested, virt-host-validate to validate host virtualization setup: # virt-host-validate qemu QEMU: Checking for hardware virtualization: PASS QEMU: Checking for device /dev/kvm : PASS QEMU: Checking for device /dev/whost-net : PASS QEMU: Checking for device /dev/net/tun : PASS

Installation and Post-Configurations:

Install qemu-kvm, libvirt, virt-manager and their dependencies from SlackBuilds.org.

There are a few notes for post-configuration:

  • Configure libvirt for user group and permission:
    Create a group called libvirt and assign a regular user to it. Then, uncomment unix_sock_group and unix_sock_rw_perms from /etc/libvirt/libvirtd.conf # groupadd libvirt # gpasswd -a USER libvirt # vim /etc/libvirt/libvirt.conf ----------------------------------------- unix_sock_group = "libvirt" unix_sock_ro_perms = "0770" unix_sock_rw_perms = "0770"
  • Default user group for kvm:
    The qemu-kvm SlackBuild patches the installed udev rules so that you no longer are required to use the system group kvm as the default. The users group is set as the default
  • Start the libvirt daemon at boot:
    To start the ibvirt daemon at boot, add a following piece of code to /etc/rc.d/rc.local # vim /etc/rc.d/rc.local ---------------------------------------- # Start libvirt: if [ -x /etc/rc.d/rc.libvirt ]; then /etc/rc.d/rc.libvirt start fi

Now Virtual Machine Manager (VMM) can be executed via: $ virt-manager

That's all!
-gibb

Slackware64 14: Post Installation Configuration

Yep. Long waited Slackware 14.0 was finally released on 09/28/2012! I immediately downloaded and installed on my system as a guest OS for VirtualBox. Since the installation and a bit of customization, I have not had enough time to play with it, but now, I tried some more configuration today.

Disclaimer:
The information below is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others.

Switching to Generic Kernel:

During Slackware installation, it uses "huge" kernel, which has every hardware driver built in. It's not necessary to switch to "generic" kernel, but it is said that with "generic" kernel, it uses less memory and runs faster since "generic" kernel has virtually no drivers built in and all drivers are loaded into RAM on demand.

Create an initial RAM # /usr/share/mkinitrd/mkinitrd_command_generator.sh

This is an informational-only command which shows a next command (mkinitrd) to run to generate the initrd.gz image. # # mkinitrd_command_generator.sh revision 1.45 # # This script will now make a recommendation about the command to use # in case you require an initrd image to boot a kernel that does not # have support for your storage or root filesystem built in # (such as the Slackware 'generic' kernels'). # A suitable 'mkinitrd' command will be: mkinitrd -c -k 3.2.29 -f ext4 -r /dev/sdb2 -m ohci-hcd:mbcache:jbd2:ext4 -u -o /boot/initrd.gz

Add a new section in /etc/lilo.conf to load a new image. # vim /etc/lilo.conf ------------------------ image = /boot/vmlinuz-generic-3.2.29 initrd = /boot/initrd.gz # add this line so that lilo sees initrd.gz root = /dev/sda1 label = Slackware read-only

Also, put "lba32" in the global options in /etc/lilo.conf to avoid getting a warning message "lba32 addressing assumed" # vim /etc/lilo.conf ------------------------ # Override dangerous defaults that rewrite the partition table: change-rules reset lba32 # Normal VGA console

Save the file and run below command then reboot. # lilo -v

That's all!
-gibb

Installing Arch Linux: LVM on top of an encrypted partition

IMPORTANT!!!
I now have updated version of Arch Linux with LVM on LUKS, Installing Arch Linux: LVM on top of an encrypted partition [[UPDATED]] with updated contents. Please visit that page!

I recently got a new notebook from my friend. I'm a slackware user but decided to give it a try on Arch Linux for this notebook. Ah... Arch Linux. I like its simplicity and user-centric philosophy. So I was reading up about Arch Linux and came across about encryption. Hmm... I could give it a try and make my notebook secure.

After reading, it looks like setting up LVM on top of the encrypted partition is the best method. So, I'll do that.

Disclaimer:
Information below is gathered mostly from the Arch Linux Wiki page and changed here and there for my liking. This information below is solely used for my purpose and may not be suitable for others.

Erasure of the Hard Disk:

Information (data) on a Hard Drive is written in chunk here and there. Re-partitioning or reformatting a disk does not really removes (erase) the data. It merely remove the system structure that used to identify where the original data was located. This leaves the actual data on a disk.

To securely erase a disk, you could either:

  • Fill with zeros
  • Fill with random bits
Both methods overwrite data on a disk but the first one fill with zero's leaving easily (to some extent) identify where the encrypted data ends. So, I follow the second method. # dd if=/dev/urandom of=/dev/<drive> bs=1M Just to be warned, this takes a long, long time.

Partitioning a Disk:

Even though Arch Linux version that I'm using (2012.08.04) comes with GRUB2 and this supports having the /boot partition in LVM, the /boot directory has to reside on its own. If the /boot directory is encrytpted (with or without LVM), the bootloader cannot read it; thus, boot failure will occur. # fdisk /dev/sda

Partition Layout:
/dev/sda1 -> /boot (bootable)
/dev/sda2 -> LVM (8e)

Configuring LUKS:

cryptsetup is used to interface with LUKS for formatting, mounting and unmounting encrypted partition.

First make sure the device mapper kernel module is installed: # modprobe dm-mod

Then format it as an encrypted LUKS partition: # cryptsetup -c aes-xts-plain -s 512 -yvh sha256 luksFormat /dev/sda2

  • -c: defines the cipher type
  • -s: defines the key size
  • -yvh sha256: prompts for the password twice and stores it in a 256-bit hash

It looks like AES cipher in XTS mode (XTS-AES) is most popular these days.

Unlocking/Mapping LUKS partition with the Device Mapper:

To access the encrypted volume, It needs to be unlocked. # cryptsetup luksOpen /dev/sda2 lvm

LVM:

Create a physical volume (encrypted volume) and a group volume. # lvm pvcreate /dev/mapper/lvm # lvm vgcreate lvmvg /dev/mapper/lvm

Create logical volumes on this new volume group. # lvm lvcreate -L 10G -n root lvmvg # lvm lvcreate -L 500M -n swap lvmvg # lvm lvcreate -l 100%FREE -n home lvmvg

Installation of Arch Linux:

Follow my blog entry, Installing Arch Linux on LVM, to install Arch Linux.

Configuration:

There are several configuration files that need to be modified.

/etc/rc.conf

Change USELVM="no" to USELVM="yes": # vi /etc/rc.conf -------------------- USELVM="yes"

/etc/mkinitcpio.conf

Configure /etc/mkinitcpio.conf for encryption and LVM by adding encrypt lvm2 (in this order) in the HOOKS section before filesystems so that the kernel will find LVM volumes at boot time. # vi /etc/mkinitcpio.conf -------------------- HOOKS="...encrypt lvm2 filesystems..."

/boot/grub/grub.cfg

Add cryptdevice=/dev/sda2:lvmvg between root=... and ro in the line starts with linux. This needs to be done for "Arch Linux" and "Arch Linux Fallback". # vi /boot/grub/grub.cfg -------------------- linux /boot/vmlinuz-linux root=/dev/mapper/lvmvg-root cryptdevice=/dev/sda2:lvmvg ro quiet

Reboot:

Now reboot the system.

That's all!
-gibb