Skip to main content

Posts about linux (old posts, page 4)

kvm on raspberrypi

kvm On Raspberry Pi OS (64bit) beta test version

related packages

$ sudo apt install --no-install-recommends qemu-system-arm qemu-utils kpartx

boot alpine linux

get kernel and initra from the iso file

$ sudo mount -o loop alpine-standard-3.12.0-aarch64.iso /media/tmp
$ sudo cp /media/tmp/boot/initramfs-lts .
$ sudo cp /media/tmp/boot/vmlinuz-lts .
$ sudo umount /media/tmp

boot

$ sudo qemu-system-aarch64 -cpu host -enable-kvm -machine virt -nographic -m 512 \
> -kernel vmlinuz-lts -initrd initramfs-lts \
> -drive if=none,id=image,file=alpine-standard-3.12.0-aarch64.iso -device virtio-blk-device,drive=image \
> -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
> -monitor telnet:localhost:10025,server,nowait

install debian10

download kernel and initrd file and create an empty virtual image file.

$ wget -O linux http://ftp.jp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux
$ wget -O initrd.gz http://ftp.jp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz
$ qemu-img create -f qcow2 hda.qcow2 16G

boot the installer with downloaded kernel and initrd file and install to the virtual image file.

$ sudo qemu-system-aarch64 -cpu host -enable-kvm -machine virt -m 512 \
> -kernel linux -initrd initrd.gz \
> -drive if=none,id=image,file=debian10.qcow2 -device virtio-blk-device,drive=image \
> -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
> -monitor telnet:localhost:10025,server,nowait \
> -no-reboot -vnc :1

$ vncviewer xxx.xxx.xxx.xxx:5901

get kernel and initrd file from qcow2 file

$ lsmod | grep nbd
$ sudo modprobe nbd
$ sudo qemu-nbd -c /dev/nbd0 debian10.qcow2
$ sudo kpartx -av /dev/nbd0
$ sudo mount /dev/mapper/nbd0p1 /media/tmp

$ cp /media/tmp/initrd.img-4.19.0-11-arm64 .
$ cp /media/tmp/vmlinuz-4.19.0-11-arm64 .

$ sudo umount /media/tmp
$ sudo kpartx -dv /dev/nbd0
$ sudo qemu-nbd -d /dev/nbd0
$ sudo rmmod nbd

boot

$ sudo qemu-system-aarch64 -cpu host -enable-kvm -machine virt -m 512 \
> -kernel vmlinuz-4.19.0-11-arm64 -initrd initrd.img-4.19.0-11-arm64 \
> -append 'root=/dev/vda2' \
> -drive if=none,id=image,file=debian10.qcow2 -device virtio-blk-device,drive=image \
> -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
> -monitor telnet:localhost:10025,server,nowait \
> -nographic

docker on raspberrypi

Install docker on Raspberry Pi OS (64bit) beta test version We can download the iso images from https://downloads.raspberrypi.org/raspios_arm64/images/

Also we can use torrent to download them

make a script to stop transmission when download finished (in this case, the script name is stop_torrent.sh)

sleep 10
kill $(ps -ef | grep transmission | grep -v grep | awk '{print $2}')

then start download

transmissIon-cli --download-dir (fullpath) --uplimit (kbps) --downlimit (kbps) --encryption-required --finish (fullpath)/stop_torrent.sh https://(fqdn)/(path)/(filename).torrent

How to install

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --dry-run
$ sudo sh get-docker.sh
$ systemctl is-active docker
$ systemctl is-enabled docker
$ sudo docker version

change the docker root directory where we store the images and containers.

$ sudo docker info | grep Root
$ sudo systemctl stop docker
$ sudo mv /var/lib/docker /path/to/
$ sudo ln -s /path/to/docker /var/lib/docker
$ sudo systemctl start docker
$ sudo docker run --rm hello-world

confirm the result

$ sudo docker run --rm -it alpine
/ #
/ # uptime
 03:17:44 up 1 day,  2:47,  load average: 0.02, 0.05, 0.01
/ #
/ # uname -a
Linux 4db177a44a14 5.4.42-v8+ #1319 SMP PREEMPT Wed May 20 14:18:56 BST 2020 aarch64 Linux
/ #
/ # free -m
              total        used        free      shared  buff/cache   available
Mem:           7816         315        6339           2        1161        7460
Swap:          8191           0        8191

install docker-compose

$ http_proxy=http://192.168.xxx.xxx:3142/ sudo -E apt install libffi-dev libssl-dev
$ sudo pip3 install docker-compose
$ pip3 show docker-compose
$ docker-compose version

commands of docker-compose

config # Validate and view the Compose file
ps # List containers
images # List images
build # (Re)Build services
create # Create services
up # Create and start containers
start # Start services
stop # Stop services
rm -f # Remove stopped containers
down # Stop and remove containers
version # Show version information
help # Show help messages

When update docker-compose.yml, no need to rebuild the image.

docker-compose up -d

When update Dockerfile or edit any source codes, need to rebuild the image.

docker-compose build
docker-compose up -d

vhd

Windows can mount vhd file as a virtual drive. We can use it for application install space or document storage area.

When we create a vhd file on a flash memory, the memory should be formatted with ntfs format.

parted /dev/sdb print
parted /dev/sdb rm 1
parted /dev/sdb mkpart primary ntfs 0% 100%
mkfs.ntfs -Q /dev/sdb1
mount /dev/sdb1 /mnt

At first a raw image file, make label, and make partition.

dd if=/dev/zero of=file.img bs=1M count=0 seek=59000
losetup -f
losetup /dev/loop1 file.img
losetup -a
parted /dev/loop1 print
parted /dev/loop1 mklabel msdos
parted /dev/loop1 mkpart primary ntfs 0% 100%
losetup -d /dev/loop1

Then format the partition in ntfs format.

kpartx -a -v file.img
mkfs.ntfs -Q /dev/loop1p1
kpartx -d -v file.img

The vhd file must not be sparse file. So after we convert it to vhd format, then we should convert it to normal file.

cp --sparse=never file.img file_new.img
qemu-img convert -O vpc -o subformat=fixed,force_size=on file.img output.vhd
cp -pi --sparse=never output.vhd.sparse file.vhd

diskpart

In windows os, we can handle partition and filesystem with sub commands of diskpart command.

format usb drive

list volume
select volume=2
format fs=ntfs quick

create a vhd file and attach it

list volume
create vdisk file="d:\image.vhd" maximum=1024
select vdisk file="d:\image.vhd"
attach vdisk
list vdisk

create partition in the vhd file

select disk 2
list disk
create partition primary

format in ntfs and assign drive letter

list volume
select volume=3
format fs=ntfs quick
assign letter=e:

detach the vhd file

select vdisk file="d:\image.vhd"
detach vdisk
list vdisk

next time, just attach it

select vdisk file="d:\image.vhd"
attach vdisk
list vdisk