Categories
Linux/Unix

Resize QEMU image for Openwrt

While using ext4 combine image from Openwrt website directly, you will find the openwrt system only about 100MB disk. The disk has to be resized before resize the partition and filesystem. Here is the steps you can follow.

First, resize the qemu image. Reference.

# in host OS, resize the qemu image
> qemu-img resize vm-100-disk-0.raw 32G

After Openwrt system booted up. Reference.

fdisk /dev/sda

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Disk model: QEMU HARDDISK
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: 0x529e51f2

Device     Boot Start    End Sectors  Size Id Type
/dev/sda1  *      512  33279   32768   16M 83 Linux
/dev/sda2       33792 246783  212992  104M 83 Linux

Command (m for help): d
Partition number (1,2, default 2):

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Disk model: QEMU HARDDISK
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: 0x529e51f2

Device     Boot Start   End Sectors Size Id Type
/dev/sda1  *      512 33279   32768  16M 83 Linux

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (2-4, default 2):
First sector (33280-67108863, default 34816): 33792
Last sector, +/-sectors or +/-size{K,M,G,T,P} (33792-67108863, default 67108863):

Created a new partition 2 of type 'Linux' and of size 32 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): w

The partition table has been altered.
Syncing disks.

Resize ext4 filesystem after partition was resized. Reference.

opkg update
opkg install losetup resize2fs
BOOT="$(sed -n -e "/\s\/boot\s.*$/{s///p;q}" /etc/mtab)"
DISK="${BOOT%%[0-9]*}"
PART="$((${BOOT##*[^0-9]}+1))"
ROOT="${DISK}${PART}"
LOOP="$(losetup -f)"
losetup ${LOOP} ${ROOT}
fsck.ext4 -y ${LOOP}
resize2fs ${LOOP}
reboot

After VM rebooted, now you have get Openwrt with full-size disk. Remember, after a sysupgrade, you have to resize partition and filesystem again.

# fdisk -l
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Disk model: QEMU HARDDISK
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: 0x529e51f2

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1  *      512    33279    32768  16M 83 Linux
/dev/sda2       33792 67108863 67075072  32G 83 Linux
Categories
Linux/Unix

SSH connection keepalive

Add these lines into you ~/.ssh/config file. It can help you send keepalive message 6 times every 30 seconds.

Host *
  ServerAliveInterval 30
  ServerAliveCountMax 6

Categories
Linux/Unix

Enable backspace in VIOS command line

Log in as padmin

$ oem_setup_env
# echo "export ENV=/home/padmin/.kshrc" >> /home/padmin/.profile     

# echo "export HOST=\"\$(/usr/bin/uname -n)\"\nif [ \"\`whoami\`\" = \"root\" ]; then\n  PS1=\"\`whoami\`@\$HOST:\\\$PWD # \"\nelse\n  PS1=\"\`whoami\`@\$HOST:\\\$PWD $ \"\nfi\n\nset -o emacs;alias -x __A=\"\$(echo '\\\\020')\"; alias -x __B=\"\$(echo '\\\\016')\"; alias -x __C=\"\$(echo '\\\\006')\"; alias -x __D=\"\$(echo '\\\\002')\"; alias -x __H=\"\$(echo '\\\\001')\"; alias -x __Y=\"\$(echo '\\\\005')\"\n" >> /home/padmin/.kshrc
Categories
Linux/Unix Software

OS X Terminal: -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

Uncheck the box “Set locale variables automatically” in iTerm2 under Preferences -> Profiles -> Terminal

Categories
Linux/Unix

X11 forwarding box font…

Try to install X11 font

yum install xorg-x11-fonts-Type1

 

Categories
Cloud

Build docker for OpenPOWER (ppc64le)

It’s a nightmare if you have a unsupported arch while building tools. I have tried to build docker for RHEL/CentOS, Ubuntu for ppc64le. It took me lots of time.

Fortunately, from 1.10, docker will support arch ppc64le officially. ppc64le will be the default arch for OpenPOWER system. As of now, docker code is still in reorg. So there might be some tricks while building docker for ppc64le. Follow below steps. You can get a preview docker 1.10.0-dev for your system. Let’s try it.

It is much simpler than before. Only two commands~

docker build -t docker -f Dockerfile.ppc64le .
docker run --privileged docker ./hack/make.sh gccg

Let’s check the running version.

./docker-1.10.0-dev version
Client:
 Version:      1.10.0-dev
 API version:  1.23
 Go version:   go1.4.2 gccgo (GCC) 5.3.0
 Git commit:   6f86bce-unsupported
 Built:        Sun Jan 31 16:11:15 2016
 OS/Arch:      linux/ppc64le

Server:
 Version:      1.10.0-dev
 API version:  1.23
 Go version:   go1.4.2 gccgo (GCC) 5.3.0
 Git commit:   6f86bce-unsupported
 Built:        Sun Jan 31 16:11:15 2016
 OS/Arch:      linux/ppc64le
Categories
Hardware

Linux 下安装识别 Marvell 88SE91xx 硬盘

88SE91xx 可以使用 AHCI 驱动,但是默认 Linux 无法识别 88SE91xx 需要手动添加到 AHCI 列表中。方法如下。

  • 首先获得到 88SE91xx 的 Vendor ID 和 Device ID
$ lspci -nnk | grep Marvell
04:00.0 RAID bus controller [0104]: Marvell Technology Group Ltd. 88SE9172 SATA III 6Gb/s RAID Controller [1b4b:9192] (rev 11)
  • 使 AHCI 识别
$ /bin/echo 1b4b 9192 > /sys/bus/pci/drivers/ahci/new_id

 

这样就能识别到在 88SE91xx 上的硬盘了。

Categories

强制 VMware vSphere Client 语言以英文运行

步骤:

  1. 右击 vSphere Client 图标
  2. 选择 “快捷方式” 选项卡,在目标后加上 “-locale en_US”
  3. 确定退出
  4. 使用更改后的快捷方式打开 vSphere Client

英文运行vSphere Client

Categories
Uncategorized

fatal error: Python.h: No such file or directory

root@raspberrypi ~/tools/RPi.GPIO-0.5.2a # python setup.py install
running install
Checking .pth file support in /usr/local/lib/python2.7/dist-packages/
/usr/bin/python -E -c pass
TEST PASSED: /usr/local/lib/python2.7/dist-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing RPi.GPIO.egg-info/PKG-INFO
writing top-level names to RPi.GPIO.egg-info/top_level.txt
writing dependency_links to RPi.GPIO.egg-info/dependency_links.txt
reading manifest file 'RPi.GPIO.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'RPi.GPIO.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv6l/egg
running install_lib
running build_py
running build_ext
building 'RPi.GPIO' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv6l-2.7/source/py_gpio.o
source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

解决方法:

安装对应版本的 python-dev,

root@raspberrypi ~/tools/RPi.GPIO-0.5.2a # apt-get install python2.7-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  python2.7-dev
0 upgraded, 1 newly installed, 0 to remove and 343 not upgraded.
Need to get 28.7 MB of archives.
After this operation, 35.3 MB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python2.7-dev armhf 2.7.3-6 [28.7 MB]
Fetched 28.7 MB in 17s (1,644 kB/s)
Selecting previously unselected package python2.7-dev.
(Reading database ... 66907 files and directories currently installed.)
Unpacking python2.7-dev (from .../python2.7-dev_2.7.3-6_armhf.deb) ...
Processing triggers for man-db ...
Setting up python2.7-dev (2.7.3-6) ...

 

Categories
Python

判断 Python 模块是否安装

在不加载 module 的情况下判断 module 是否已安装

import imp

class checkModule:
    def check_psutil(self):
        try:
            imp.find_module('psutil')
            found = True
        except ImportError:
            found = False

        if not found:
            raise AssertionError('Module psutil is not installed.')
        else:
            print('Module psutil is installed.')