The Sky is not the limit

Entries tagged as ‘Free BSD’

Adding swap space

May 5, 2008 · Leave a Comment

Swap Memory is a space in the Hard Disk of your computer that Operating Systems (Linux in our case) will use to put the info that is actually on the RAM to free it for another application. Sometimes in the course of a system’s existence you find that the swap partition you set up at install-time just isn’t enough anymore. So we need to increase the swap space for better performance of the system. You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available in the disk to create partition.

A) To add a swap partition (assuming /dev/sdb2 is the swap partition you want to add):

1. The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The easiest way to achieve this it to boot your system in rescue mode. Refer to Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, select Skip.

Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.

2. Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted:

* At a shell prompt as root, type the command parted /dev/sdb, where /dev/sdb is the device name for the hard drive with free space.

* At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.

* At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.

Changes take place immediately; be careful when you type.

* Exit parted by typing quit.

3. Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following:

mkswap /dev/sdb2

4. To enable the swap partition immediately, type the following command:

swapon /dev/sdb2

5. To enable it at boot time, edit /etc/fstab to include:

/dev/sdb2 swap swap defaults 0 0

The next time the system boots, it will enable the new swap partition.

6. After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.

B) To add a swap file:

1. Determine the size of the new swap file and multiple by 1024 to determine the block size. For example, the block size of a 128 MB swap file is 131072.

2. At a shell prompt as root, type the following command with count being equal to the desired block size:

root@localhost ~> dd if=/dev/zero of=swapfile bs=1024 count=131072
131072+0 records in
131072+0 records out

where

dd: – is used to copy a specified number of bytes from an Input file (if) to an Output file (of). Here the dd command copy null characters from the special file “/dev/zero” and copy it to the output file “aSwapFile” in the “/” directory. The “bs” specifies that the characters are read as BYTES. The “count” specifies the size of the bytes block that is to be created in the output file.

3. Change the permission

root@localhost ~> chmod 600 swapfile

4. Setup the swap file with the command

root@localhost ~> mkswap swapfile
Setting up swapspace version 1, size = 135372800 bytes

5. To enable the swap file immediately but not automatically at boot time:

root@localhost ~> swapon swapfile

6. To enable it at boot time, edit /etc/fstab to include:

/swapfile swap swap defaults 0 0

The next time the system boots, it will enable the new swap file.

7. After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.

Adding a Swap File on FreeBSD

1. Be certain that your kernel configuration includes the memory disk driver (md(4)). It is default in GENERIC kernel.

device md # Memory “disks”

2. Create a swapfile (/usr/swap0):

# dd if=/dev/zero of=/usr/swap0 bs=1024k count=64

3. Set proper permissions on (/usr/swap0):

# chmod 0600 /usr/swap0

4. Enable the swap file in /etc/rc.conf:

swapfile=”/usr/swap0″ # Set to name of swapfile if aux swapfile desired.

5. Reboot the machine or to enable the swap file immediately, type:

# mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0

Adding a Swap File on Solaris

If you have a Solaris system that badly needs more swap but you don’t have a free swap device available, you can create a file in the file system and add it as additional swap.

  1. Use mkfile to create a file suitable for a local swap area. For example, to create a 1GB swap file:
        /usr/sbin/mkfile 1024m /swap

    where /swap is the name of the file to be used as swap space. Units for the size can be kilobytes (k), blocks (b), or megabytes (m).

  2. Tell the system to start using the file as swap:
        /usr/sbin/swap -a /swap

    Use swap -l to verify that the swap file has been activated.

Categories: Linux tutorials
Tagged: , , , , , , , , , ,

Installing packages in Free BSD

January 3, 2008 · 2 Comments

Installations
in Free BSD using packages & ports

 

 

 

FreeBSD provides two complementary technologies for installing third-party software on your system: the FreeBSD Ports Collection (for installing from source), and packages (for installing from pre-built binaries). Either method may be used to install the newest version of your favorite applications from local media or straight off the network. By installing from the port, you can
tweak the compilation options to (for example) generate code that is specific to a Pentium 4 or Athlon processor.By building from the port you do not have to accept the default options, and can set them yourself.

 

 

Finding Your Application :-
Before you can install any applications you need to know what you want, and what the application is called.

 

The FreeBSD web site maintains an up-to-date searchable list of all the available applications, at
http://www.FreeBSD.org/ports/. The ports are divided into categories, and you may either search for an application by name (if you know it), or see all the applications available in a category.

 

If you know the exact name of the port, but just need to find out which category it is in, you can use the whereis command. Simply type whereis file, where file is the program you want to install. If it is found on your system, you will be told where it is, as follows:

 

# whereis lsof

lsof:
/usr/ports/sysutils/lsof

 

This tells us that lsof (a system utility) can be found in the /usr/ports/sysutils/lsof directory.

 

Yet another way to find a particular port is by using the Ports Collection’s built-in search mechanism. To use the search feature, you will need to be in the /usr/ports directory. Once in that directory, run make search name=program-name where program-name is the name of the program you want to find. For example, if you were looking for lsof:

 

# cd /usr/ports

# make search
name=lsof

Port:
lsof-4.56.4

Path:
/usr/ports/sysutils/lsof

Info: Lists
information about open files (similar to fstat(1))

Maint:
obrien@FreeBSD.org

Index: sysutils

B-deps:

R-deps:

 

  1. Installing a Package

     

You can use the pkg_add utility to install a FreeBSD software package from a local file or from a server on the network.

 

# ftp -a
ftp2.FreeBSD.org

Connected to ftp2.FreeBSD.org.

220
ftp2.FreeBSD.org FTP server (Version 6.00LS) ready.

331 Guest login
ok, send your email address as password.

230-

230- This
machine is in Vienna, VA, USA, hosted by Verio.

230-
Questions? E-mail freebsd@vienna.verio.net.

230-

230-

230 Guest login
ok, access restrictions apply.

Remote system
type is UNIX.

Using binary mode
to transfer files.

ftp> cd
/pub/FreeBSD/ports/packages/sysutils/

250 CWD command
successful.

ftp> get
lsof-4.56.4.tgz

local:
lsof-4.56.4.tgz remote: lsof-4.56.4.tgz

200 PORT command
successful.

150 Opening
BINARY mode data connection for ‘lsof-4.56.4.tgz’ (92375 bytes).

100%
|**************************************************| 92375
00:00 ETA

226 Transfer
complete.

92375 bytes
received in 5.60 seconds (16.11 KB/s)

ftp> exit

# pkg_add
lsof-4.56.4.tgz

 

If you do not have a source of local packages (such as a FreeBSD CD-ROM set) then it will probably be easier to use the -r option to pkg_add.

 

# pkg_add -r lsof

 

 

 

Managing Packages

 

# pkg_info lsof

# pkg_version lsof

# pkg_delete lsof

All package information is stored within the /var/db/pkg directory. The installed file list and descriptions of each package can be found within files in this directory.

 

========

5. Using the Ports Collection

 

 

 

Before you can install ports, you must first obtain the Ports Collection–which is essentially a set of
Makefiles, patches, and description files placed in /usr/ports. Make sure /usr/ports is empty before
you run CVSup for the first time! If you already have the Ports Collection present, obtained from another source, CVSup will not prune removed patch files.

 

1. Install the net/cvsup-without-gui package:

 

# pkg_add -r cvsup-without-gui

 

2. Run cvsup:

 

# cvsup -L 2 -h cvsup.FreeBSD.org /usr/share/examples/cvsup/ports-supfile

 

Alternate method:- Portsnap Method

 

# pkg_add -r portsnap

 

# mkdir /usr/ports

 

# portsnap fetch

 

# portsnap extract

 

# portsnap update

 

 

 

ii) Installation

 

To begin, change to the directory for the port you want to install:

 

# cd /usr/ports/sysutils/lsof

once inside the lsof directory, you will see the port skeleton. The next step is to compile, or “build”,
the port. This is done by simply typing make at the prompt. Once you have done so, you should see something like this:

 

# make

>> lsof_4.57D.freebsd.tar.gz doesn’t seem to exist in
/usr/ports/distfiles/.

>> Attempting to fetch from ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/.

===> Extracting for lsof-4.57

[extraction
output snipped]

>> Checksum OK for lsof_4.57D.freebsd.tar.gz.

===> Patching for lsof-4.57

===> Applying FreeBSD patches for lsof-4.57

===> Configuring for lsof-4.57

[configure output
snipped]

===> Building for lsof-4.57

[compilation
output snipped]

#

 

 

Notice that once the compile is complete you are returned to your prompt. The next step is to install
the port. In order to install it, you simply need to tack one word onto the make command, and that word is install:

# make install

===> Installing for lsof-4.57

…[installation
output snipped]

===> Generating temporary packing list

===>Compressing manual pages for lsof-4.57

===>Registering installation for lsof-4.57

===> SECURITY
NOTE:

This porthas installed the following binaries which execute with increased privileges.

#It is a good idea to delete the working subdirectory, which contains all the temporary files used during compilation. Not only does it consume valuable disk space, but it would also cause problems later when upgrading to the newer version of the port.

 

# make clean

===> Cleaning for lsof-4.57

 

 

 

#
Note: You can save two extra steps by just running make install clean instead of make, make install and make clean as three separate steps.

Iii) Upgrading Ports

 

Once you have updated your Ports Collection, before attempting a port upgrade, you should check
/usr/ports/UPDATING. This file describes various issues and additional steps users may encounter and need to perform when updating a port.

 

# cd /usr/ports/ports-mgmt/portupgrade

# make install clean

 

 

# portupgrade -ai

# portupgrade -R firefox

 

To free the disk space consumed while installing packages

 

# portsclean -C

 

 

 

Categories: Linux tutorials
Tagged: , , , , , ,