Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Thursday, January 5, 2017

Shrink a Ubuntu Guest VDI File

When using a Ubuntu virtual box guest, sometimes we want to shrink the dynamic expanding VDI file to release the unused disk space. Here is the steps to archive that.

  1. Install ZeroFree

    sudo apt-get install zerofree
  2. Reboot into recovery mode
    a. sudo shutdown -r now
    b. Holding the left Shift key while rebooting
    c. Select Advanced and then Recovery mode and finally Drop to root shell prompt option.

  3. Remount the root partition

    mount -n -o remount,ro -t ext4 /dev/sda1 /
  4. Run ZeroFree

    sudo zerofree -v /dev/sda1
  5. Shutdown the VM

    shutdown -h now
  6. Shrink the VDI file is host OS

    SET PATH=%PATH%;"c:\Program Files\Oracle\VirtualBox
    VBoxManage modifyhd Ubuntu.vdi -compact


Reference: How to shrink a dynamically-expanding guest virtualbox image

Saturday, March 15, 2014

Setup Debian in a Virtualbox

The following tips can make it convenient to use debian in a virtual box, but please keep in mind that they are not good practices for a production server.

Disable Sudo Password Requirement

On ubuntu/debian, you could disable sudo password prompt by following the steps below.

sudo visudo

Change

%sudo ALL=(ALL) ALL

to

%sudo ALL=(ALL) NOPASSWD: ALL

Auto login

The following steps can let you log in automatically to a console when boots.

sudo vi /etc/inittab

Change the line

1:2345:respawn:/sbin/getty 38400 tty1

to

1:2345:respawn:/bin/login -f user </dev/tty1 >/dev/tty1 2>&1

Disable Grub Screen

The following steps can disable grub splash screen when boots

sudo vi /etc/default/grub

Change the value of GRUB_TIMEOUT to 0

And then run the following command to update grub config.

sudo update-grub

Tuesday, February 18, 2014

Core Dump on Ubuntu

Listed below are just several notes about core dump on Ubuntu.

The location of core dump files

The following command can print out where will the core dump files be placed.

cat /proc/sys/kernel/core_pattern

If the output start with a | character, the kernel then will write the core dump to the stdin of the command after the | character.

Core dump file size

The following command can remove core dump file size limit.

ulimit -c unlimited

Apport

On ubuntu, core dump files are forwarded to Apport by default. So if you can’t find the core file in your current directory, you may want to try /var/crash. Probably you will see crash report files there.

The command apport-unpack can be used to extract the core files out of a crash report files.

Monday, December 30, 2013

Zsh History Search

Compared to Fish, currently I like Zsh a little bit more. But one of the unforgettable feature of Fish is its auto-suggestion based on history.
It made command line input so fluent.

Zsh has a feature similar to that called predict. You could configure by placing the following codes in your ~/zshrc.
You could press <Ctrl-Z> to toggle predict on and off.

autoload predict-on
predict-toggle() {
  ((predict_on=1-predict_on)) && predict-on || predict-off
}
zle -N predict-toggle
bindkey '^P'   predict-toggle
zstyle ':predict' toggle true
zstyle ':predict' verbose true

But compared to Fish’s auto-suggestion, I feel that the predict feature is less useful.
The difference show up when you simply type ls<Enter>.

  • In Fish, only ls will be executed.
  • In Zsh, if predict was turned on, ls -la will be executed, which is sometimes not what we want.

So for a more convenient way of accessing command line history, I prefer Zsh’s vi mode and history-search-backward.
You could press <Ctrl-J> and <Ctrl-K> to search history forward and backward.

# vi mode
setopt vi

# bind k and j for history search in vi mode
bindkey -M viins '^k' history-search-backward
bindkey -M viins '^j' history-search-forward
bindkey -M vicmd '^k' history-search-backward
bindkey -M vicmd '^j' history-search-forward

Make Python 3.x Default Python on Ubuntu

If you installed both python version 2.x and 3.x on system, you could add the following line to your ~/.bashrc or ~/.zshrc to make python 3.x the default python.

alias python='python3'

If you want to make pip-3.x and virtualenv-3.x your default ones, you may also add the following lines.

alias pip='pip-3.3'
alias virtualenv='virtualenv-3.3'