Search This Blog

Wednesday, 20 July 2016

MOUNTING DRIVES ON RASBERRY Pi DEVICE

Mounting Dirves in linux rasberry pi

If you want to use flash drive and disk you need to mount the drive in linux manually to that use the following reference commands.

pi@rasberrypi ~$ cd /dev

pi@rasberry /dev$

pi@rasberry /dev$ ls

pi@rasberry /dev$ df

pi@rasberry /dev$

we need see system messages to find out if the device has made available

pi@rasberry /dev$ tail -f /var/log/messages

pi@rasberry /dev$

pi@rasberry /dev$ sudo fdisk -l

to mount this usb drive we need to make a mount point

goto /mnt

pi@rasberry /dev$ cd /mnt

pi@rasberry /mnt$

pi@rasberry /mnt$ sudo mkdir usbstick

pi@rasberry /mnt$ sudo mount /dev/sda1 /mnt/usbstick

The above will mount usb drive for root user , but we need to give permissioin to user pi

we do this like this

pi@rasberry /mnt$ sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /mnt/usbstick

goto the drive

pi@rasberry /mnt$ cd /mnt/usbstick

pi@rasberry /mnt/usbstick$ ls -lap

pi@rasberry /mnt$ cd /mnt

pi@rasberry /mnt$ sudo umount /mnt/usbstick

pi@rasberry /mnt$ sudo umount /dev/sda1

for different file system use the following

for windows drive use the following command

pi@rasberry /mnt$ sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /mnt/usbstick

pi@rasberry /mnt$

for mac drives use the following mounting command

pi@rasberry /mnt$ sudo mount -t hfsplus -o uid=pi,gid=pi /dev/sda1 /mnt/usbstick

you need to install hfsplus support on pi linux to do that use the following command

pi@rasberry /mnt$ sudo apt-get install hfsplus hfsutil hfsprogs



























LINUX PARTITIONING AND FORMATING IN LINUX SHELL

Linux Partitioning and Formatting in filesystems for Disk Use the following Commands


pi@rasberrypia ~$ fdisk
pi@rasberrypia ~$ man fidsk
pi@rasberrypia ~$ sudo fdisk -l
pi@rasberrypia ~$ sudo fdisk /dev/sda
Command (m for help):m

Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty dos partition table
p print the partition table
q quit without saving changes
s create a new empty sunlabel
t change a partitions systems id
u change display / entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

User the above options to create new partition in /dev/sda
After creating partitions to the drive use w to write changes made to disk

To Format Use the following commands

pi@rasberrypia ~$ sudo mkfs -t ext4 /dev/sda1

 ext 4 linux file system

User the following commands to mount the partition

pi@rasberrypia ~$ cd to /mnt

pi@rasberrypia  /mnt$

pi@rasberrypia  /mnt$ sudo mkdir part1 part2

now mount drives to these created directories

pi@rasberrypia /mnt$ sudo mount /dev/sda1 /mnt/part1

now it by going to the part1 directory and creating a file

pi@rasberrypia  /mnt$ cd part1

pi@rasberrypia  /mnt/part1$ sudo touch test1

pi@rasberrypia  /mnt/part1$ ls -la

to unmount use the following commands

pi@rasberrypia /mnt/part1$ sudo umount /dev/sda1

to Format a Fat32 created Disk Partition Use the following commands

pi@rasberrypia ~$ sudo mkfs apt-get install dostools

Format disk partition sda1 in Fat32 file system Use the following command

pi@rasberrypia ~$ sudo mkfs -t vfat /dev/sda1

we can also make partitions to disk using graphical user interface

sudo apt-get update

sudo apt-get install gparted

run

sudo gparted























Monday, 11 July 2016

LINUX PARTITIONING COMMANDS

To Partition a drive in linux use the following commands,

1. fdisk

use ' man fdisk ' to find about the format of this command

2. sudo fdisk -l

This will give you information about the disc.

3. To change partitions on the drive to make it a native linux type partition from FAT to linux type

goto

sudo fdisk /dev/sda

we are going to work with sda main device

command line will come type m to check options

to print partition tables on this drive type p

to change first delete the windows partition

press d to delete it

to verify type p

now create the new linux type partition type n

now type p to make it primary

now type the size of the partition

type +4G

type p to verifty the partition

now enter n

type also primary this will be primary partition

type partition no.

and default size of the partition if you dont want to or dont have anymore size left

now type p to verify

now type w to alter the partition

sudo fdisk -l

now we will see two partition

now to make file system ext4

use mkfs command

now type

sudo mkfs -t ext4 /dev/sda1

this will format the file system

now do the same for sda2 partition

sudo mkfs -t ext4 /dev/sda2

now we need to mount them

change to /mnt directory

cd /mnt

make two directories name them part01 and part02

sudo mkdir part01 part02

mount sda1 and sda2

for super use root use

sudo mount /dev/sda1 /mnt/part1

for specific user pi

sudo mount -o gid=pi, uid=pi /dev/sda1 /mnt/part1

for second one

sudo mount /dev/sda2 /mnt/part2

to create a file in part 1

cd part1

sudo touch test1

to check

ls -la

this show a file is created in part1 partition

to unmount a partition use

sudo unmount /dev/sda1

sudo unmount /dev/sda2

this will unmount the partition for super user root




















Sunday, 3 July 2016

LINUX FILE SYSTEM AND COMMAND LINE UNDERSTANDING

Unix Command Line Interface

To get around Unix / Linux file system we use the following commands.
But first look at the following Linux file structure,

most files in Linux are stored in directory hierarchy shown here,

                                        root       /
                                                     |
                ----------------------------------------------------------
                 home       usr            etc        bin            var          
                    |              |                 |                            |
                   Pi            bin             X11                     log



for example we have command line,

pi@raspberrypi ~ $  

home directory is

/home/pi

to find home directory use     whoami

to find present working directory use     pwd

to get back to home folder use teldar key    cd ~

to change directory use      cd /   (forward slash)  to goto root directory

to change to etc use    cd /etc

etc  store many of the system configuration files

to see the contents of etc use "  ls  "   list command

list command has certain options

ls -a  list all system files including the hidden files

ls -l will list all files length wise in a directory

ls -p will show a slash after directory so we can easily distinguish a file

from a directory

ls --color will show the types of files via color

to combine more than one option we can use " ls -lap"  option this will

combine all the previous option in one command

to take us back one directory use command " cd . . "

to take us back two directories use command " cd .. / .. "

single dot represent one current directory "  cd . "

to list the root directory component use

to root then type   ls  list command

/bin

this root folder is for commands and binaries

/sbin

sbin is for systems and admin commands

/usr

has usr related stuff it also has its own usr/bin and usr/sbin folder

/var

/var stands for variable it also has var/log folder

/home

is user directory

/mnt

this is for mount this for mounting any external drive we can even mount

folders

/dev

device interfaces for any hardware

/lib

this for programs and libraries

To make a directory
===============

use mkdir dir1

To remove a directory
=================

use rmdir dir1

this will throw an error if their is some file in the directory

but if you know what you are doing then you can do the following,

to create file in the directory use touch command

touch test

to remove and directory that contains file contents use

rmdir -rf dir1

r and f options

r stands for do the removing recursively drilling down the sub files you want to remove

f stands for force this to happen

Moving and copying files and directories
===============================

Use the cp command to copy

create a file

touch filename1

then use cp to copy one file to second file

cp filename1 filename2

To move a file from one file location to other use

mv filename1 filename2

to copy host files in etc to home/pi use

cp /etc/hosts /home/pi

to rename it use

cp /etc/hosts /home/pi/localhost

cp will work but mv will not work because user pi doesn't have permission

to modify files in etc directory

cp -R dir1 dir2

this will copy everything in this folder and beneath it

If you want to find out man command

man mv

Linux Partitioning Disk & Formatting commands

Linux Partitioning Disk & Formatting commands fdisk man fdisk pi@rasberrypi ~$ sudo fdisk -l