Blog

Blog

KVM setup in Fedora

KVM setup in Fedora

Commands

virsh list --all
virsh start <vm>
virsh start <vm> --console
virsh stop <vm>

KVM vs XEN

KVM isn't kernel specific, XEN required special kernel, so XEN could have kernel upgrade issue.

Bridge Network

When creating bridging network, if grub is used to create network interface, then Network Manager should not be used to create same interface. If Network Manager used, same network interface will be appear in ifconfig -a command output twice, One is created by NetworkManager, another is created by grub. If bridge network interface created on top of grub created interface, the IP address will be still assigned to grub created interface.

In order to avoid above issue, following line in /etc/default/grub to create network interface with bridging network interface br0.

GRUB_CMDLINE_LINUX=" ... ip=192.168.1.9::192.168.1.254:255.255.255.0::br0:off nameserver=192.168.1.250 ifname=enp0s10:00:26:4a:18:82:c6 bridge=br0:enp0s10"

After br0 created, KVM manager can select bridging network for vm creation.

Update grub using following command

grub2-mkconfig -o /boot/grub2/grub.cfg

Download driver

Both Windows disk controller driver and ethernet driver can be downloaded from Fedora Website, https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.139-1/virtio-win-0.1.139.iso, and add additional CD-ROM to point to this iso.

Create VM

Using Virtual Machine Manager

Create VM requires add storage, if the storage file doesn't exist, need to select the storage location, and also input the size of disk which located above the location selection box.

Using command line

To create Ubuntu VM from local image,

virt-install \
--name ubuntu2104 \
--ram 3072 \
--vcpus 2 \
--disk path=/kvm/ubuntu2104.qcow2,size=20 \
--os-variant ubuntu20.04 \
--os-type linux \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--cdrom /kvm/ubuntu-21.04-live-server-amd64.iso \
--boot kernel=casper/vmlinuz,initrd=casper/initrd,kernel_args="console=ttyS0"

To create Fedora VM from remote server

virt-install \
--name fed34 \
--ram 2048 \
--vcpus 2 \
--disk path=/kvm/fed34.img,size=20 \
--os-variant fedora34 \
--os-type linux \
--network bridge=virbr0 \
--graphics none \
--console pty,target_type=serial \
--location 'https://mirror.arizona.edu/fedora/linux/releases/34/Server/x86_64/os/' \
--extra-args 'console=ttyS0,115200n8 serial'

Create Windows 10 VM

virt-install \
   --ram=4096 \
   --name=windows10 \
   --os-type=win10 \
   --network network=default \
   --disk path=/kvm/kvm-windows10.img,size=100 \
   --cdrom=/kvm/virtio-win-0.1.139.iso \
   --graphics spice

Cons

  • Cannot select type of CPU or Passthru mode
  • Cannot select type of disk controller type to use virtual device driver.

References

10 Easy Steps To Install Windows 10 on Linux KVM – KVM Windows

Remove empty directories recursively

Remove empty directories recursively

Use find command

Use following command can remove empty directories which may have empty directories in them. The -depth will sort the output according to the depth of directories.

find . -type d -depth -exec rmdir {} \;

Note: Just ignore error due to directory not empty

Use rmdir command

First, need to know how deep of your directory, then can run following command

rmdir */*/*/*
rmdir */*/*
rmdir */*
rmdir *

Note: This can cause too many arguments error or command line too long error for large directory.

Markdown Cheat Sheet

Markdown Cheat Sheet

Special characters

Element Markdown Syntax
Ampersand (&) &amp;
Backtick (`) &#96;

Basic Syntax

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Blockquote > blockquote
Ordered List 1. First item
2. Second item
3. Third item
Unordered List - First item
- Second item
- Third item
Code `code`
Horizontal Rule ---
Link [title](https://www.example.com)
Image ![alt text](image.jpg)

Extended Syntax

Element Markdown Syntax
Table | Syntax | Description |
| ----------- | ----------- |
| Header | Title |
| Paragraph | Text |
Fenced Code Block ```
{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}
```
Footnote Here's a sentence with a footnote. [^1]

[^1]: This is the footnote.

Heading ID ### My Great Heading {#custom-id}
Definition List term<br>: definition
Strikethrough ~~The world is flat.~~
Task List - [x] Write the press release
- [ ] Update the website
- [ ] Contact the media

References

Markdown Syntax
Markdown Cheat Sheet

Configure rsync in TrueNAS

Configure rsync in TrueNAS

Create user/group

Create a user called rsync, with group rsync.

Create dataset

Create a dataset, owned by rsync:rsync, with permission 770.

Enable rsync service

Go to System Settings -> Services, enable rsync.

Create module

Click on Configure (Edit icon), select Rsync Module tab, key in following info, and save configuration.

  • Module Name
  • Access Mode: Read & Write
  • User: rsync
  • Group: rsync

Test

Run following command from remote server

rsync -avR --password-file=/root/.rsync/password \
    /tmp \
    rsync@<rsync_host>::NetBackup/`hostname`

Exporting swap space on TrueNAS

Exporting swap space on TrueNAS

There are quite number of swap partitions on TrueNAS. In short, swap are mirror partitions on /dev/sdX1, which is 2GB for each mirror, data partitions are on /dev/sdX2.

As the top information, it has not been used, so just leave it until performance impacted.

Total Space

Following screen shows 4GB swap space in top command

top - 16:31:05 up  5:26,  4 users,  load average: 11.79, 11.36, 10.90
Tasks: 540 total,   1 running, 538 sleeping,   0 stopped,   1 zombie
%Cpu(s):  0.8 us,  9.4 sy,  0.0 ni, 46.1 id, 43.1 wa,  0.0 hi,  0.5 si,  0.0 st
MiB Mem :  32052.4 total,  13522.1 free,  17935.6 used,    594.7 buff/cache
MiB Swap:   4096.0 total,   4096.0 free,      0.0 used.  13739.1 avail Mem

Devices

There are two partitions as swap

truenas# swapon
NAME      TYPE      SIZE USED PRIO
/dev/dm-0 partition   2G   0B   -2
/dev/dm-1 partition   2G   0B   -3
truenas#

Partitions

DM info, shows /dev/dm-0 and /dev/dm-1 map to md127 and md126.

truenas# dmsetup ls
md127   (253:0)
md126   (253:1)
truenas# dmsetup info /dev/dm-0
Name:              md127
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        2
Event number:      0
Major, minor:      253, 0
Number of targets: 1
UUID: CRYPT-PLAIN-md127

truenas# dmsetup info /dev/dm-1
Name:              md126
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        2
Event number:      0
Major, minor:      253, 1
Number of targets: 1
UUID: CRYPT-PLAIN-md126

truenas#

MD info

Total 4 partitions involve, mirror into 2 raid1 devices.

Reported by proc

truenas# cat /proc/mdstat      
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md126 : active raid1 sde1[1] sdd1[0]
      2097152 blocks super non-persistent [2/2] [UU]

md127 : active raid1 sdc1[1] sdb1[0]
      2097152 blocks super non-persistent [2/2] [UU]

unused devices: <none>
truenas#

Reported by mdadm

truenas# mdadm --detail /dev/md127
/dev/md127:
           Version : 
     Creation Time : Wed Oct  6 11:08:56 2021
        Raid Level : raid1
        Array Size : 2097152 (2.00 GiB 2.15 GB)
     Used Dev Size : 2097152 (2.00 GiB 2.15 GB)
      Raid Devices : 2
     Total Devices : 2

             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
truenas# mdadm --detail /dev/md126
/dev/md126:
           Version : 
     Creation Time : Wed Oct  6 11:08:57 2021
        Raid Level : raid1
        Array Size : 2097152 (2.00 GiB 2.15 GB)
     Used Dev Size : 2097152 (2.00 GiB 2.15 GB)
      Raid Devices : 2
     Total Devices : 2

             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       65        1      active sync   /dev/sde1
truenas#

Block device info

Structure of partitions

truenas# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda           8:0    0   1.4T  0 disk  
├─sda1        8:1    0     2G  0 part  
└─sda2        8:2    0   1.4T  0 part  
sdb           8:16   0   7.3T  0 disk  
├─sdb1        8:17   0     2G  0 part  
│ └─md127     9:127  0     2G  0 raid1 
│   └─md127 253:0    0     2G  0 crypt [SWAP]
└─sdb2        8:18   0   7.3T  0 part  
sdc           8:32   0 298.1G  0 disk  
├─sdc1        8:33   0     2G  0 part  
│ └─md127     9:127  0     2G  0 raid1 
│   └─md127 253:0    0     2G  0 crypt [SWAP]
└─sdc2        8:34   0 296.1G  0 part  
sdd           8:48   0 232.9G  0 disk  
├─sdd1        8:49   0     2G  0 part  
│ └─md126     9:126  0     2G  0 raid1 
│   └─md126 253:1    0     2G  0 crypt [SWAP]
└─sdd2        8:50   0 230.9G  0 part  
sde           8:64   0 298.1G  0 disk  
├─sde1        8:65   0     2G  0 part  
│ └─md126     9:126  0     2G  0 raid1 
│   └─md126 253:1    0     2G  0 crypt [SWAP]
└─sde2        8:66   0 296.1G  0 part  
sdf           8:80   1  14.9G  0 disk  
├─sdf1        8:81   1     1M  0 part  
├─sdf2        8:82   1   512M  0 part  
└─sdf3        8:83   1  14.4G  0 part  
zd0         230:0    0    20G  0 disk  
truenas# 

zpool structure

List all zpool

truenas# zpool list
NAME        SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
boot-pool    14G  3.70G  10.3G        -         -     2%    26%  1.00x    ONLINE  -
pool0       296G  9.13G   287G        -         -     1%     3%  1.00x    ONLINE  /mnt
pool1      1.36T   383G  1009G        -         -    16%    27%  1.09x    ONLINE  /mnt
pool2      7.27T  1.12T  6.14T        -         -     2%    15%  1.10x    ONLINE  /mnt
pool3       230G  2.63G   227G        -         -     0%     1%  1.00x    ONLINE  /mnt
truenas#

For individual pool, can use following command find out partition info

truenas# zpool status pool0 -v
  pool: pool0
 state: ONLINE
status: Some supported and requested features are not enabled on the pool.
    The pool can still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
    the pool may no longer be accessible by software that does not support
    the features. See zpool-features(7) for details.
  scan: resilvered 600K in 00:00:03 with 0 errors on Mon Oct  4 04:49:30 2021
config:

    NAME                                      STATE     READ WRITE CKSUM
    pool0                                     ONLINE       0     0     0
      mirror-0                                ONLINE       0     0     0
        bf410fcf-2209-11ec-b8aa-001132dbfc9c  ONLINE       0     0     0
        bfcc498a-2209-11ec-b8aa-001132dbfc9c  ONLINE       0     0     0

errors: No known data errors
truenas#

find partition by id

zpool list doesn't have partition name, only got partition id, use following command to find out mapping partition id.

truenas# ls -l /dev/disk/by-partuuid
total 0
lrwxrwxrwx 1 root root 10 Oct  6 11:05 0e8d0027-65cc-4fa5-bb68-7d91668ca1f4 -> ../../sdf1
lrwxrwxrwx 1 root root 10 Oct  6 11:05 41ba87d7-2137-11ec-9c17-001132dbfc9c -> ../../sdb1
lrwxrwxrwx 1 root root 10 Oct  6 11:05 41cbb8fa-2137-11ec-9c17-001132dbfc9c -> ../../sdb2
lrwxrwxrwx 1 root root 10 Oct  6 11:05 5626c0ae-2137-11ec-9c17-001132dbfc9c -> ../../sdd1
lrwxrwxrwx 1 root root 10 Oct  6 11:05 563bbde1-2137-11ec-9c17-001132dbfc9c -> ../../sdd2
lrwxrwxrwx 1 root root 10 Oct  6 11:05 672278c8-92bc-4e99-8158-25e53eb085c9 -> ../../sdf2
lrwxrwxrwx 1 root root 10 Oct  6 11:05 757ce69e-207a-11ec-afcf-005056a390b2 -> ../../sda1
lrwxrwxrwx 1 root root 10 Oct  6 11:05 75827da1-207a-11ec-afcf-005056a390b2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Oct  6 11:05 bf3063db-2209-11ec-b8aa-001132dbfc9c -> ../../sdc1
lrwxrwxrwx 1 root root 10 Oct  6 11:05 bf410fcf-2209-11ec-b8aa-001132dbfc9c -> ../../sdc2
lrwxrwxrwx 1 root root 10 Oct  6 11:05 bfb5835e-2209-11ec-b8aa-001132dbfc9c -> ../../sde1
lrwxrwxrwx 1 root root 10 Oct  6 11:05 bfcc498a-2209-11ec-b8aa-001132dbfc9c -> ../../sde2
lrwxrwxrwx 1 root root 10 Oct  6 11:05 e384f2ee-96dd-4b1b-ac68-8fe14ea92797 -> ../../sdf3
truenas#

Find hardware info in Linux

Find hardware info in Linux

motherboard info:

Basic info

sudo dmidecode -t 2
lshw

Detail info

sudo dmidecode | less

PCI info

lspci

USB info

lsusb

proc

cat /sys/devices/virtual/dmi/id/board_{vendor,name,version}

dmesg

dmesg | grep DMI:

GUI

hardinfo
cpu-g
lshw-gtk
PerlMon

Automator in MacOS Basic

Automator in MacOS Basic

To automate tasks in MacOS, Automator can be used. For example, convert selected images to JPG format, the steps as below

Create new task

Run Automator

Select Quick Action

Select action

Find out action Change Type of Images

Set actions’ options

Select Show this action when workflow runs

Save

Run in Finder

In Finder, select images, then select Services menu can be found after clicked following icon, then follow steps.

Services Menu

Rename Action

Right click on Action name in Automator, select Services, then rename the action.

Delete Action

Right click on Action name in Automator, select Services, then delete the action.

Screen Capture

Screen Capture