Tag Archive : bsd

/ bsd

File Transfer using Rsync

December 9, 2015 | Article | No Comments

Rsync, old but still powerful tools for moving files between hosts. The main use is to keep file trees synchronized. Rsync have been used for long time since its inception. And it seems Rsync is still used this day.

Rsync is available in many platform, especially UNIX-like system. As the title said, we will discuss about Rsync and not nailed to specific Operating System. In this article we are not discussing about how to install rsync so I assume we already have rsync installed on local machine.

We also not covering about how to prepare rsync server. It will be discussed in another article.

Rsync Overview

Rsync syntax in general would be:

rsync [OPTION] SRC DST

Where SRC is the source address and DST is the destination.

In general, we can use rsync for some purposes:

    1. Copying local files.
    2. Copying from local machine to remote machine.
    3. Copying from remote machine to local machine.

Synchronize local directory and remote rsync server.

On next sections, we will discuss each way described above. But our topic will be focused to point (2) to (4). Well, why would we use rsync to copying local files instead of using cp command?

It is also recommended to used rsync over ssh. Rsync does not provide any security while transferring data therefore we need to tunnel it with secure remote connection.

Now, some arguments or command options we will used in this article:

  • –delete: delete files that don’t exists on sender (system)
  • -v: verbose, use -vv for more detailed information
  • -e “ssh options”: specify ssh as remote shell. The “options” will then passed to ssh when creating a connection
  • -a: archive mode
  • -r: recurse into directories
  • -z: compress file data. Might consume memory and cpu resource but helpful for low bandwidth.

Copying from Local Machine to Remote Machine

Also known as push / upload file(s) into remote machine. Suppose we want to copy /var/www/backup.tgz to a remote server called backup.celestial-links.net on home directory, we could use:

rsync -v -e ssh /var/www/backup.tgz [email protected]:~

You will then be prompted by a password authentication message.

Copying from Remote Machine to Local Machine

Also known as pull / download file(s) from remote machine. Suppose we want to copy /usr/bin/secretbackdoor from remote server machine.celestial-being.net to local storage /tmp:

rsync -v -e ssh [email protected]:/usr/bin/secretbackdoor /tmp/

Synchronizing Local Directory and Remote RSync Server

Well, this is the main purpose of rsync (guess where rsync name comes from). Here the methods are two way connection, it means both machine will synchronizing their content.

rsync -r -a -v --delete rsync://rsync.celestial-links.net/somedir/ /local/somedir/

Or you can swap the src and destination, its same

rsync -r -a -v /local/somedir rsync://rsync.celestial-links.net/somedir

Note that this method use pure rsync which means we are not using it on top of ssh protoocl.

If you want to only synchronize a local directory according to remote directory:

rsync -r -a -v -e "ssh -l xathrya" --delete /local/somedir backup.celestial-links.net:/somedir

Or you want to only synchronize a remote directory according to our local directory:

rsync -r -a -v -e "ssh -l xathrya" --delete backup.celestial-links.net:/somedir /local/somedir

Transfer from One Remote Machine to Other Remote Machine

Suppose we have two remote servers: A and B. In this section we will use rsync to move a file from A to B without transit to our machine. It means file on A is directly copied to B.

rsync -zavrR --delete --links usernameA:[email protected]:/path/to/resource \
usernameB:[email protected]:/path/to/resource

Install FreeBSD on GPT Partition

December 3, 2015 | Article | No Comments

At previous article, we have discussed about how to install Slackware on GPT. In this article we will attempt on installing FreeBSD to GPT disk with or without EFI support.

Unlike previous article, for this article I use generic desktop PC. Thus, you can do it either on notebook or desktop PC. Obviously we constraint ourself to use GPT-based disk :). This article aim to guide you to Fresh Installing FreeBSD.

Step 1: Partitioning

Boot your FreeBSD (I use 8.3). Once you are at sysinstall menu, choose Fixit option. Later you will be brought to a terminal.

Now we will initialize the drive to support GPT partitions.

gpart create -s GPT ad0

Where ad0 is our disk. If you have more than one disk and want to also initialize them, do the similar command and replace ad0 with your device.

Then we will proceed for creating partitions. Our partition have specific purpose but all partition we want to create are a standard one. Do the followings:

gpart add -s 128 -t freebsd-boot -l boot ad0
gpart add -s 5G -t freebsd-ufs -l root ad0
gpart add -s 4G -t freebsd-ufs -l tmp ad0
gpart add -s 4G -t freebsd-swap -l swap ad0
gpart add -s 10G -t freebsd-ufs -l var ad0
gpart add -s 200G -t freebsd-ufs -l usr ad0

On above commands, we have create 6 partitions. The general syntax we use has following pattern:

gpart add -s size -t partition_type -l label disk

Where size is numeric value for size of partition. It also accept suffix K,M,G for Kilo, Mega, and Gigabyte. If no suffix is specified, the default value will be on Kilobytes.

For this article, the partition type can be freebsd-boot, freebsd-ufs, freebsd-swap.

The first partition are partitioned with freebsd-boot for type. It is equivalent to MBR of older disk type. Others are partition with freebsd-ufs (except 4th partition) for regular file system. The label is used for differentiate one partition with other partition.

To see partitions we have create we can invoke this command:

gpart show ad0

Unlike using gdisk, the change using gpart is automatically written on disk.

note: To see partition by label use this command

gpart show -l ad0

If you want to delete a partition, use following command:

gpart delete -i3 ad0

The i3 (generally -in where n is a number) is for pointing out what partition we want to delete. In this case we want to delete 3rd partition from disk ad0. So if your want to delete 5th partition, use gpart delete -i5 ad0.

In extreme condition, if you want to destroy GPT table from ad0 you can use following command:

gpart destroy ad0

The main reason might be you want to erase old disk scheme and create a new one later.

Now format the partition:

newfs -U /dev/ad0p2
newfs -U /dev/ad0p3
newfs -U /dev/ad0p5
newfs -U /dev/ad0p6

Hey, why we skip /dev/ad0p1 and /dev/ad0p4? Take look at their type 😀

Now put MBR (Master Boot Record) code in our first partition (boot partition):

gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptboot -i1 ad0

Then we mount all the partitions to install FreeBSD:

mkdir boot var usr
mount /dev/ad0p2 /mnt
mount /dev/ad0p3 /mnt/tmp
mount /dev/ad0p5 /mnt/var
mount /dev/ad0p6 /mnt/usr

Step 2: Installing FreeBSD

Now we reach the stage for FreeBSD installation itself. Do following:

export DESTDIR=/mnt
cd /dist/8.3-RELEASE
for dir in base catpages dict doc info lib32 manpages; do 
   (cd $dir; ./install.sh); 
done

If you attempt to install x86 (or i386) version of FreeBSD then exclude lib32 in the for loop (you won’t need it.

Next we install the kernel. The kernel we want to install are GENERIC version so do following:

cd kernels
./install.sh GENERIC

And then the sources:

cd ../src
./install.sh

And copy the kernel in /mnt/boot/kernel directory:

cd /mnt/boot
rmdir kernel
cp -Rp GENERIC kernel

Step 3: Configuring
Last step! Configure the FreeBSD. Create /etc/fstab, /etc/resolv.conf and /etc/rc.conf files.

/etc/fstab :

# Device Mountpoint FStype Options Dump Pass#
/dev/ad0p4 none swap sw 0 0
/dev/ad0p2 / ufs rw 1 1
/dev/ad0p3 /tmp ufs rw 1 1
/dev/ad0p5 /var ufs rw 1 1
/dev/ad0p6 /usr ufs rw 1 1

/etc/resolv.conf :

nameserver 8.8.8.8 # or your ISP's DNS

/etc/rc.conf :

defaultrouter="<your router IP>"
hostname="VedaCore"
ifconfig_em0="inet <your IP> netmask <your netmask>"
sshd_enable="YES"

Reboot and enjoy the FreeBSD >:)

NOTE:

  1. If you get error “Device Busy” when you try to delete GPT from drive with gpart delete ad0, then turn off the safety with sysctl variable: sysctl kern.geom.debugflags=16
  2. If you want to destroy GPT table from drive, make sure all partitions have been deleted.

Social media & sharing icons powered by UltimatelySocial