суббота, 26 марта 2016 г.

Enabling G-Journal in FreeBSD

Example 1

First of all, login to your system.
Then look at your fstab file and find a partition to enable geom journal on. Note that it is impossible to enable journal for the root / file system.
I am going to enable journal for the partition of the /var directory located on the ada0p4 geom.

First of all I check if the gjournal kernel module is loaded. If it is not loaded, I add it to the loader configuration (/boot/loader.conf) and load it.
Then I add a new partition for journal provider.
You can see that ada0s6 will become the journal provider.

To enable journaling for a partition you should make sure that the partition is not mounted. If it is mounted, you should to unmount it:
# umount -f /var/
and enable journaling using the next command:
# gjournal label -f ada0p4 ada0s6
where ada0p4 is a data provider and ada0s6 is a journal provider.
After journaling is enabled you should edit the fstab file.
For example if your data provider geom was ada0p4, you should replace its device with /dev/ada0p4.journal. You also should use asynchronous mounting for journaled partition using the async option.
After that you should to disable soft updates for the partition and tune its file system to set gjournal.
This was the last stepping stone to enable journaling for the partition, so you may mount it back now.

Example 2

The full geom journal enabling typescript may look like this.
$ su
# gpart add -t freebsd -a 4k ada0
# umount -f /usr/
# gjournal label -f ada0p5 ada0p7
# cp /etc/fstab /etc/fstab.old
# ed
e e /etc/fstab
e 5c
e /dev/ada0p5    /usr    ufs    rw,async    2    2
e .
e w
e q
# tunefs -J enable -n disable /dev/ada0p5.journal
# mount /usr/

Continue reading -> Bootstrapping package manager.

пятница, 25 марта 2016 г.

Installing FreeBSD 10.2

Today I will show you how to install the FreeBSD 10.2 operating system upon your computer. This process is quite easy and fast.

First of all you have to put previously prepared installation DVD to the tray of your optical drives reader and (re-)boot the computer.

After the computer boot you will see the next screen.
Press B or ENTER to boot FreeBSD installer immediately.

After boot process complete you will see the Installer welcome screen.
Press ENTER or I to start installation. The first stepping stone is key map selection.
Use arrow keys (UP and DOWN) to select the keyboard map you prefer.
Then press ENTER.
Press UP and, then, ENTER keys to continue with the selected map.
This screens asks you to type the name of the computer. Do it.
Then press ENTER to confirm. The next dialog allows to select operating system's components you wish to install. Move the selection using the UP and DOWN keys and check or uncheck components using the SPACE bar.
If you see a [*] mark on the contrary component, it means the component will be installed.


I usually install all the components except the extra documentation.
Disk partitioning is the most important part of the installation.
The Auto (UFS) option is the simplest. Just press ENTER...

...and again to grant FreeBSD access to the entire hard drive.
Select the GPT partition scheme as it is modern and the most commonly used and compatible scheme.
This user friendly pseudo graphical partition editor suggests you very easy and flexible disk setup. But I like to use separate file systems for a /usr and /var directories. To achieve this I set the selection over the ada0p2 partition (in using double press DOWN key) and delete it (press D) because of the aforementioned reason. Then I select ada0p3 partition and delete it too because I want to have a larger swap partition.
Then I select ada0 scheme and press C to create a new partition for the root file system. The partition editor shows the window where I specify the type (freebsd-ufs), the size (4GB) of the creating partition and the mount point (/).
After pressing the ENTER key I create the the partition for swap. I set partition type to freebsd-swap, size to 2GB (this is a required minimum for desktop systems) and leave mount point and label empty for this partition.
Then I create one more partition. This time is for the /usr directory.
And, finally, I create 4GB partition for the /var directory.
The rest free space I am going to use for G-Journals for the /usr and /var directories file systems.
I press F here to finish partitioning...
...and ENTER here to commit changes to the disk.

  *  *  *

FreeBSD starts copying files from check sums verification...
...and then extracts distribution files of the selected components from archives.
This stage takes a few minutes (up to ten).
Files copied! Next screen asks to type root's password.
Now FreeBSD installer tries to configure the network.
I pressed ENTER here.
And here.
Here too.
And here :-)
Of course YES :-) and wait few seconds.
Then...
...accept correctly determined network settings.
Here...
  ...I didn't know (it is the virtual machine), so I selected <No>...
 ...and pressed ENTER.
Then I select my region and...
...country.
Then I choose my primary time zone...
 ...and accepted time zone abbreviation.
The next screen offers different services.
I usually activate all of them exclude local caching validation resolver.
Then Installer asks us if we want to add users to the system.
I usually agree and add myself.
Note, that you should list groups separate them by space.
After confirmation I got the clean installed FreeBSD.
Here I press ENTER,
N (to prevent opening post installation shell)
and ENTER or R to reboot to the installed system.

That's enough for today: FreeBSD has been installed!

Read the next: Enabling G-Journal in FreeBSD.

вторник, 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.