вторник, 8 марта 2016 г.

xsession script for twm

This is an ~/.xsession script I have used to run twm (Tom's Window Manager) on my home FreeBSD box. It sets up screen resolution and starts some IRC client, clock and terminal with Z Shell.
#!/bin/sh
xrandr --size 1920x1080
xrandr --dpi 96
exec xterm\
 -geometry 100x50-0+0\
 -T 'Z Shell'\
 -e sh\
 -c "cat softlist; ${SHELL:-sh}" &
exec xclock -update 1 -chime -geometry 70x70+0-0 &
exec pidgin &
exec twm
That's enough for me :)

четверг, 18 февраля 2016 г.

Creating VirtualBox machine based on a physical partition using VBoxManage

0. Preface


In this article I am going to show you how to install and setup FreeBSD and start use it as a home OS.

I will use
  • FreeBSD 10.2
  • ZFS (I believe 2GiB of RAM is o.k. for it)
  • LXDE 1.0
  • VBoxManage 4.3
  • SeaMonkey 2.39
  • MPlayer 1.2

1. Virtual Hard Drive using raw partition support


Let me start from creating the virtual hard drive for the machine. I am going to use raw partition support. This feature is a part of the VMDK format.
It allows a guest operating system to access its virtual hard disk without going through the host OS file system

1.1. Create a partition

First of all I create a partition for a virtual hard drive.

1.1.1. Example 1 (physical partition)

# gpart add -t freebsd -s 40G -a 4k ada0
ada0s4 created

1.1.2. Example 2 (logical slice)

# gpart add -t freebsd -s 40G -a 4k ada0s4
ada0s4s1 created
This approach was not applicable for me because of several reasons: 1) too complex partitioning (bsdinstall will divide the partition of partitions into at least three partitions).

The advice: use GPT partitioning scheme and don't forget about aligning.

1.2. Choose the partition for virtual disk and set the correct permissions to it

Secondly, I list partitions for using as a hard drive for the future virtual machine
% VBoxManage internalcommands listpartitions\
   -rawdisk /dev/ada0
It outputs table like these (below).

1.2.1. Example 1 (root scheme)

Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
1       0xa5  0   /2  /1   1023/255/63        212991          126
2       0xa5  1023/255/63  1023/255/63       1048575    436207716
3       0xa5  1023/255/63  1023/255/63         16383   2583691362
4       0xa5  1023/255/63  1023/255/63         40959   2617245792
The 4th partition was created by the first command (gpart) and I use it as the base for the virtual machine disk. To avoid permissions problem with virtual HD made using raw partition support, issue the next command (as root) before creating a virtual disk with raw partition support:
# chmod g+w /dev/ada0s4
where ada0s4 is the geom for virtual hard drive.

To make this permanent I added the one line to devfs configuration:
# cp /etc/devfs.conf /etc/devfs.conf.old
# echo 'perm  ad6s4  0660' >> /etc/devfs.conf

1.2.2. Example 2 (logical slice)

Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
1       0xa5  0   /2  /1   1023/255/63         40959          126
# chmod g+w /dev/ada0s4s1
# cp /etc/devfs.conf /etc/devfs.conf.old
# echo 'perm  ad6s4s1  0660' >> /etc/devfs.conf
Remember: this is just example and if you use MBR, your sub-partitions may be erased after reboot (I don't know why). For example /me confronted this problem. But the first example work for me well.

1.3. Create the virtual disk

If you already have got a virtual disk attached to a virtual machine you can detach it using the next command.
% VBoxManage storageattach fbsd\
   --storagectl sata1\
  
--port 1\
  
--type hdd\
  
--medium none
There is an easy way to delete the unusable virtual hard drive: just delete the according VMDK file:
% rm /mnt/barracuda/vm/fbsd.vbox/dsk/ada0s4*.vmdk
After that I can create a VMDK for the VM.
% VBoxManage internalcommands createrawvmdk\
   -filename /mnt/barracuda/vm/fbsd.vbox/dsk/ad6s4.vmdk\
   -rawdisk /dev/ada0\
   -partitions 4\
   -relative
The -relative key prevents access to entire disk. It released me from the access problem and I got the next result
RAW host disk access VMDK file /mnt/barracuda/vm/fbsd.vbox/dsk/ad6s4.vmdk created successfully.

1.3.1. The note about -relative

Actually, you should use the next command
% VBoxManage internalcommands createrawvmdk\
   -filename /mnt/barracuda/vm/fbsd.vbox/dsk/ad6s4.vmdk\
   -rawdisk /dev/ada0\
   -partitions 4
(without the -relative option) as it is more correct. But I faced up with the next useless error:
VBoxManage: error: VMDK: could not open raw partition file '/dev/ad6'
VBoxManage: error: Error code VERR_ACCESS_DENIED at /wrkdirs/usr/ports/emulators/virtualbox-ose/work/VirtualBox-4.3.36/src/VBox/Storage/VMDK.cpp(3533) in function int vmdkCreateRawImage(PVMDKIMAGE, const PVBOXHDDRAW, uint64_t)
VBoxManage: error: Cannot create the raw disk VMDK: VERR_ACCESS_DENIED
VBoxManage: error: The raw disk vmdk file was not created
If you know how to create a VMDK made of a raw partition without the -relative key, please, let me know by e-mail or in comments block below the text.

1.3.2. The additional note concerning permissions

If you still having problems with creating the VMDK, try to issue the next commands:
# chmod a+wr /dev/ada0*
#
chown vblinkov /dev/ada0*

2. Create the VM

I usually create virtual machines (VMs) using the next command.

% VBoxManage createvm\
   --name fbsd\
   --basefolder /mnt/barracuda/vm/fbsd.vbox/machine/\
   --register
The result of the command is listed below
Virtual machine 'fbsd' is created and registered.
UUID: 7f0add90-fbe6-4dba-83b1-b2782290c16a
Settings file: '/mnt/barracuda/vm/fbsd.vbox/machine/fbsd/fbsd.vbox'
To list registered machines use the next command
% VBoxManage list vms
"fbsd" {7f0add90-fbe6-4dba-83b1-b2782290c16a}
Then I look at the memory size:
% VBoxManage showvminfo fbsd | grep Memory
Memory size:     128MB
I usually consume up to 2 GiB of RAM, so I increase memory size using
% VBoxManage modifyvm fbsd --memory 2048
% VBoxManage showvminfo fbsd | grep Memory
Memory size:     2048MB
I enable PAE/NX (required (but does not help to run) for Windows 8+, requires the same option to be enabled on your physical motherboard (look for it in BIOS))
% VBoxManage modifyvm fbsd --pae on
Install sound card:
% VBoxManage modifyvm fbsd\
   --audio oss\
   --audiocontroller hda
 

Now I create a SATA master  controller
% VBoxManage storagectl fbsd\
   --name sata1\
   --add sata\
   --bootable on
After that I attach the created earlier virtual hard disk based on the physical partition.
% VBoxManage storageattach fbsd\
   --storagectl sata1\
   --port 1\
   --type hdd\
   --medium /mnt/barracuda/vm/fbsd.vbox/dsk/ada0s4.vmdk
Look!
% VBoxManage list hdds
UUID:           42db7f73-392e-4af7-9a8a-bc8c461dad29
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /mnt/barracuda/vm/fbsd.vbox/dsk/ada0s4.vmdk
Storage format: VMDK
Capacity:       1430799 MBytes
My virtual hard drive (HD) is registered in VirtualBox now.

To start the VM I use this command
% VBoxManage startvm fbsd --type sdl

If you do not want to install operating system right now you can halt the machine using the command shown below.
% VBoxManage controlvm fbsd poweroff
I insert a DVD with FreeBSD 10.2 distro typing the next command (from a terminal [emulator])
% VBoxManage storageattach fbsd\
   --storagectl sata1\
   --port 2\
   --type dvddrive\
   --medium\
   /mnt/barracuda/os/freebsd/10.2/FreeBSD-10.2-RELEASE-i386-dvd1.iso
and restart the machine
% VBoxManage controlvm fbsd reset
I issue the next command to make screenshots:
% VBoxManage controlvm fbsd screenshotpng /tmp/02.png

 
This is the FreeBSD 10 boot menu.


3. FreeBSD 10 installation process

Please follow the next link to read my another article concerning FreeBSD 10.2 installation process:
http://freebsdathome.blogspot.ru/2016/03/installing-freebsd-102.html


After installation is complete you might want to eject the distro DVD.
% VBoxManage storageattach fbsd\
  
--storagectl sata1\
  
--port 2\
  
--type dvddrive\
  
--medium emptydrive

4. After installation

You may want to do next things.

4.1. Rename/move a VM

% VBoxManage modifyvm fbsd --name win
% VBoxManage unregistervm win
% cd /mnt/barracuda/vm # location of the VM directory
% mv fbsd.vbox win.vbox # rename (can move) the directory
% # heads up: use the ABSOLUTE path in the next command
% VBoxManage registervm\
   /mnt/barracuda/vm/win.vbox/machine/win/win.vbox
% # detach hard drive (it's old location) from machine:
% VBoxManage closemedium disk\
   /mnt/barracuda/vm/fbsd.vbox/dsk/ad6s4.vmdk
% # attach the disk at its new location
% VBoxManage storageattach win\
   --storagectl sata1\
   --port 1\
   --medium /mnt/barracuda/vm/win.vbox/dsk/ad6s4.vmdk\
   --type hdd

4.2. Install guest additions

Guest additions is a program to add something like cooperation between the guest OS of VM and the host operating system. You can find all about the additions at the official VirtualBox documentation.

Next I will show you how I usually install additions.
% wget http://download.virtualbox.org/virtualbox/\
   4.3.36/VBoxGuestAdditions_4.3.36.iso
% VBoxManage storageattach win\
   --storagectl sata1\
   --port 2\
   --type dvddrive\
   --medium VBoxGuestAdditions_4.3.36.iso

4.3. Setup networking

4.3.1. Connect the VM to the Internet

% VBoxManage controlvm win poweroff
% VBoxManage modifyvm win\
   --nic1 nat\
   --nictype1 82540EM
  

4.3.2. Wire host and guest

% VBoxManage modifyvm win\
   --nic2 hostonly\
   --nictype2 82540EM\
   --hostonlyadapter2 vboxnet0

4.4. Setup share between host and guest

Install additions (see paragraph 4.2) before proceed!
% VBoxManage sharedfolder add win\
   --name share\
   --hostpath /mnt/barracuda/vm/win.vbox/share/
   --automount

4.5. Start VM instead on desktop manager

~/.xinitrc
#!/bin/sh

# login to VM
VirtualBox --fullscreen --startvm fbsd

P.S. Sorry for formatting: Blogger editor sucks :)

Bibliography

  1. Access to individual physical hard disk partitions / VirtualBox manual, /chapter 9.9.1.2 / https://www.virtualbox.org/manual/ch09.html#rawdisk.

вторник, 26 января 2016 г.

Portable Drive Re-Partitioning for FreeBSD

10

Attach the device and find its geom using the next command
% camcontrol devlist
The command shows something like this:
<Optiarc DVD RW AD-5280S 1.01>     at scbus0 target 0 lun 0 (pass0,cd0)
<ST1500DM003-9YN16G CC4B>          at scbus1 target 0 lun 0 (pass1,ada0)
<Multi Flash Reader 1.00>          at scbus6 target 0 lun 0 (da0,pass2)
<WD My Passport 0828 1012>         at scbus7 target 0 lun 0 (da1,pass3)
<WD SES Device 1012>               at scbus7 target 0 lun 1 (ses0,pass4)

20

Check out the existing partitioning scheme:
% gpart show da1
The command will show you current partitioning for the device specified by geom (da1 in the example).

30

Destroy the existing scheme using
# gpart destroy -F da1
The -F key is not required, but the last time I used it.
The command replies: da1 destroyed.

40

Create new scheme:
# gpart create -s GPT da1
da1 created

50

Add a partition using the next command.
# gpart add -t freebsd da1
da1s1 created

60

Grow file system on the recently created partition:
% newfs -L passport -U -o time /dev/da1s1
You may have to detach and attach the device back before newfs'ing to avoid an I/O error while formatting.

понедельник, 25 января 2016 г.

Update. January, 2015 - fix for a libmatemixer problem

I updated my system and its software packages. It was easy.

The only problem: output volume slider was broken. The symptom: movement of the slider does not change volume of the output signal.
I fixed this problem using only the next command:
% cd /usr/ports/audio/libmatemixer ; sudo make config reinstall clean
Checked the ALSA option.
(Re-login to your system after the command finished of executing)

воскресенье, 27 декабря 2015 г.

I solved the problem with gone shutdown button (MATE desktop)

In the September 2015 I have found a problem in MATE desktop environment.
The problem was: shutdown button gone from the MATE's main menu.
exec ck-launch-session mate-session

To fix this quickly I created the shuter project.

Today I suddenly found a solution. I fixed the problem by replacing the next line
exec ck-launch-session mate-session
with the another one:
exec mate-session
in the ~/.xinitrc file.
exec mate-session
 Start sessions of MATE properly!

пятница, 18 декабря 2015 г.

Update from December, 18

I've just updated software packages on my FreeBSD 10.1.
Read this post if you wish to know what's new.
(I'll update this post during solving problems.)

Font

Yes. Default font in MATE was updated. It became thinner.

GIMP

Goodbye gimp. It was updated to 2.8.16.
Opening and saving JPEGs was broken (file-jpeg plugin clash).
Darla plugin was broken (script-fu plugin clash).
The plugin-browser and procedure-browser plugins are broken too.
Something else... may be.

The solution for all the problems is
# cd /usr/ports/graphics/gimp-app ; make config reinstall clean
I ticked the options with JPEG word in the description. In other words I ticked all the options of the gimp-app configuration :)

For the possible future

I'm considering to replace alsa with pulse. I wonder if this will repair volume control slider (for now: it just does not work: the volume level does not change when I'm moving the slider)

суббота, 24 октября 2015 г.

FreeBSD upgrade. October 2015

Update the operating system

# freebsd-update fetch
# freebsd-update install
# shutdown -r now

Upgrade binary packages

# pkg update
# pkg updating | $PAGER
# pkg upgrade
# portupgrade -fr ffmpeg
# portupgrade -fr icu
# pkg autoremove
# pkg clean
# portsclean -C

Major improvements and bug fixes

MATE Desktop

[Bug 202984] x11/mate desktop version 1.10, Trash does not work has been fixed. May be accidentally? ;)

Implementing the patches

For gnome-mount

Patch

MATE still does not mount DVDs and SD cards because gnome-mount is still broken. Therefore I suggest to allow users to mount devices. To do this...
# cd /etc
# #   tune the kernel
# cp sysctl.conf sysctl.conf.orig
# echo 'vfs.usermount=1' >> sysctl.conf
#  we should use devfs.rules instead of devfs.conf
#  to be able to work with devices plugged in
#
  after the system is in multi user mode
# cp devfs.rules devfs.rules.orig
# echo 'add path 'da*'        mode 0660 group operator' >> devfs.rules
# shutdown -r now
Ensure that rules set is enabled in /etc/rc.conf. For example, when the /etc/devfs.rules has the next content
[system=10]
add path 'usb/*'    mode 0660 group operator
add path 'da*'        mode 0660 group operator
then the /etc/rc.conf must has the next line
devfs_system_ruleset="system"

For user


First approach
First time: create an mnt/ at your home
% mkdir -p ~/mnt
Every time:
To mount...
% mount_msdosfs /dev/da0s1 ~/mnt
Then you can find the card in the mnt/ subdirectory inside your home directory.
If you do not know the name of the card device:
Run the next command to find out all the devices you can plug in to your system
% camcontrol devlist
Tip: If device did not mount, you should try to mount it again.
To unmount...
% umount ~/mnt
:-D
In my case the problem was a typo in the PolicyKit.conf ))
But this approach to allow users to mount devices really works !

Bibliography 

  1. FreeBSD: Allow Normal Users To Mount CDROMs / DVDs / USB Devices. NixCraft (cyberciti.biz), http://www.cyberciti.biz/faq/freebsd-allow-ordinary-users-mount-cd-rom-dvds-usb-removabledevice/.
  2. devfs. FreeBSD (http://freebsdguide.ru), http://freebsdguide.ru/_8/_16/.