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
Linux/Unix

CentOS/RHEL 5 中 Samba 服务无法访问

新安装的 CentOS 6.3 的服务器使用原始 Samba 配置文件却无法正常工作,症状是:能够访问,但是进入目录提示没有权限。

尝试方法:

关闭 SELinux

vim /etc/sysconfig/selinux

改为如下:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
#SELINUX=enforcing
SELINUX=disable
#
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
Categories
Linux/Unix Storage

Device Mapper Multipath Configuration

1. Setup Steps

1.1 install and load device mapper (not necessary in RHEL58)

a) install Device Mapper Multipath/DMMP

yum install device-mapper device-mapper-multipath

b) load and check device mapper and multipath modules

modprobe dm-multipath
modprobe dm-round-robin
lsmod | grep md

c) start the multipathd service

Categories
Linux/Unix

编译 64bit Linux Kernel 时报 genksyms 找不到

可以使用

$ make mrproper
$ make cloneconfig
$ make prepare-all

来解决。

不过如果报错:“/bin/sh: scripts/genksyms/genksyms: No such file or directory”,可以将 “make prepare-all” 改为 “make prepare scripts”。如下:

$ make mrproper
$ make cloneconfig
$ make prepare scripts

 

Categories
Linux/Unix

bash 中的双引号和单引号

a=3
echo "b=$a+2"     # 显示 b=3+2
echo 'b=$a+2'     # 显示 b=$a+2

在 bash 中,

单引号 可以保证引用区域内的文字不被转换,起到保护作用,一般可以用在显示 code 之类;
双引号 可以包含文字或者函数段。其中,反引号中的函数,$ 开头的变量和 \ 开头反转换的字符外,其他都是直接输出。

之所以用双引号,是因为在bash中的变量替换发生在双引号内,如果不用引号,bash会把它们解释为命令。

Categories
Linux/Unix

SSH/SCP 不用输入密码连接远程 Linux 主机

其实步骤很简单:

1)在本地主机生成密钥对

ssh-keygen -t rsa

再输入密钥时候,直接按回车,我们的目的是不用输入密码嘛。

这个命令生成一个密钥对:id_rsa(私钥文件)和 id_rsa.pub(公钥文件)。默认被保存在 ~/.ssh/ 目录下。

2)将公钥添加到远程主机的 authorized_keys 文件中
SSH 到登陆到远程主机,将公钥追加到 authorized_keys 文件中