Finding a Drives Name in Linux From the Command Line

There are a few different ways to find out a drives(sdcard, usb drive, external hard drive) name.

dmesg command

One way to do it is to look at dmesg. Insert your drive and then run the command. It displays a lot of info, what we are interested in is the end which should say something about your drive.

dmesg
[ 4443.109976] mmc0: new high speed SDHC card at address aaaa
[ 4443.111857] mmcblk0: mmc0:aaaa SU04G 3.69 GiB 
[ 4443.120836]  mmcblk0: p1 p2
[ 4453.045338] EXT4-fs (mmcblk0p2): recovery complete
[ 4453.086165] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 4453.086184] SELinux: initialized (dev mmcblk0p2, type ext4), uses xattr

This tells us that the device is mmcblk0. The “p2” at the end is the partition number.

df Command

Another way to do it is to run the df command.
Run the below command without your drive plugged in.

df -h

it’ll return something like this

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root   50G   12G   36G  24% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G  600K  1.9G   1% /dev/shm
tmpfs                    1.9G  1.0M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                    1.9G   28K  1.9G   1% /tmp
/dev/sdb1                477M  115M  333M  26% /boot
/dev/mapper/fedora-home   76G   45G   23G  87% /home

The above command returns all the partitions that are mounted on your computer.
Now mount your drive and run the command again, it should show your drive at the bottom.

[me@fedora ~]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root   50G   12G   36G  24% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G  600K  1.9G   1% /dev/shm
tmpfs                    1.9G  1.1M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                    1.9G   28K  1.9G   1% /tmp
/dev/sdb1                477M  115M  333M  26% /boot
/dev/mapper/fedora-home   76G   45G   23G  87% /home
/dev/mmcblk0p2           3.6G  2.3G  1.1G  69% /run/media/me/fc522c75-9sws

You can see that the bottom one “/dev/mmcblk0p2 ” is the partition of the drive you just plugged in.

Using fdisk

You can also use fdisk.

sudo fdisk -l

It will return something similar to the following.

Disk /dev/mapper/fedora-home: 78.8 GiB, 191931351040 bytes, 374865920 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mmcblk0: 3.7 GiB, 3965190144 bytes, 7744512 sectors

The bottom section is the drive “mmcblk0”.

Using lsblk

lsblk is another cool tool to list drives and partions. When run with the -p option it shows the path to the drive and partition.

Example output of what you may get with “lsblk -p”

admin@localhost:~$ lsblk -p
NAME                              MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
/dev/nvme1n1                      259:0    0   450G  0 disk  
├─/dev/nvme1n1p1                  259:1    0   499M  0 part  
├─/dev/nvme1n1p2                  259:2    0   100M  0 part  
├─/dev/nvme1n1p3                  259:3    0    16M  0 part  
└─/dev/nvme1n1p4                  259:4    0 449.3G  0 part  
/dev/nvme0n1                      259:5    0   477G  0 disk  
 ├─/dev/nvme0n1p1                  259:6    0   512M  0 part  /boot/efi
 ├─/dev/nvme0n1p2                  259:7    0   732M  0 part  /boot
 └─/dev/nvme0n1p3                  259:8    0   400G  0 part  
   └─/dev/mapper/vg-root           253:1    0   391G  0 lvm   /
   └─/dev/mapper/vg-swap_1         253:2    0   7.9G  0 lvm   [SWAP]
admin@localhost:~$ 

How To Make a Live Bootable Fedora Thumb Drive in Linux

Insert your thumb drive into the computer.

We need to find out where the thumb drive is mounted.  We can do this with the “df” command as shown below or you can find it in dmesg.

So if we run the df command

df -h

It returns something like this

[me@fedora ~]$ df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/fedora-root   50G   11G   37G  23% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G  1.2M  1.9G   1% /dev/shm
tmpfs                    1.9G  1.1M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                    1.9G   52K  1.9G   1% /tmp
/dev/sdb1                477M  115M  333M  26% /boot
/dev/mapper/fedora-home  176G  125G   42G  75% /home
/dev/sdc1                3.8G  3.2G  592M  85% /run/media/me/136A-7360
[me@fedora ~]$

Note that the bottom one is the thumb drive /dev/sdc1 yours may differ.

Now that we know where the drive is mounted we can write the image to the thumb drive.

Change the path in “if=/” to the path to your Fedora iso and change “of=/” to you thumb drive path

su -c "dd if=/home/me/Downloads/Fedora-Live-x86_64-20-1.iso of=/dev/sdc bs=8M"

It will take a couple of minutes to complete and it will not give you any information until it is finished.

Congratulations, you now have a live working Fedora thumb drive.

How to Install Flash on Linux

Installing flash on Ubuntu is pretty straight forward.  Type the following command into a terminal and press enter and away you go.

sudo apt-get install flashplugin-installer

On Fedora need to do the following

(64-bit)

sudo yum install http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm -y

(32-bit)

sudo yum install http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm -y

And install the Adobe Flash web browser plugin.  The first command imports the GPG key for the Adobe Flash plugin repository and the second command installs the plugin itself.

sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux 
sudo yum install flash-plugin -y

Create a Bootable OS X Thumb Drive on Linux

NOTE:  This is a post has not been completely tested.  So use at your own risk.  This text will be removed once the post is completely tested.

 

What you need

  1. InstallESD.dmg
  2. 7zip installed on your computer
  3. Thumb Drive with 8gb of space on it
  4. A few other things installed

Getting Ready

So first we need to make sure we have a few things installed.

yum install hfsplusutils gparted p7zip dmg2img

on Debian based systems use

sudo apt-get install hfsplus hfsprogs hfsutils gparted p7zip-full

Now that we have all the tools we need we can move on.

 

Navigate to were your InstallESD.dmg file is.  Then run the following command.

7z x InstallESD.dmg

After it is finished cd into the InstallMacOSX.pkg

cd InstallMacOSX

now run

dmg2img InstallESD.dmg

Now you have a new file called InstallESD.img.

Open up Gparted (or your favorite disk tool) and find your thumb drive.  Format the drive with a GUID Partition Table and make sure it is HFS+. When it is finished formating, Find the thumb drive and unmount it, and then click restore.  It is under the “More actions” button on the top right.  Find your InstallESD.img file and click Restore.
You are now finished.  Have Fun!

 

 

How to Install VirtualBox on Fedora in 10 Steps

1.  Open a terminal and change to the root user

su -

2.  Then cd into the following directory

cd /etc/yum.repos.d/

3.  Install wget.

yum install wget

4.  Download the repo files with wget.

wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo

5.  Install the dependencies.

yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms

6.  Update your computer.

yum update

7.  Install VirtualBox.

yum install VirtualBox-4.2

8. Add the VirtualBox user to the vboxusers group

usermod -a -G vboxusers user_name

9.  Reboot your computer.

reboot

10.  Enjoy.  If you run into problems try the following.

/etc/init.d/vboxdrv setup

Note:
I have created a script that will do all this for you, download here.  All you need to do is the following 3 commands.

cd /pathto/fedora-vb-installer.sh
chmod +x fedora-vb-installer.sh
sudo ./fedora-vb-installer.sh

 

 

How to Setup a Cron Job

There are a couple ways to set up a cron job.  If you have a script that you want to run ever so often, you could drop it in one of the cron directories, like cron.daily, or cron.weekly.  These are located in /etc.  Another way to do it is to use crontab.

To setup a cron job in crontab type

crontab -e

and then,

*/30 * * * * /path/to/yourscript.sh

The “*/30”  makes the script run every 30 minutes.  Below gives you a better idea of how the line works.  The asterisk (*) specifies all possible values for a field, but can/should be replaced with the time you want the script to execute.

* * * * * command to be executed

*(min) *(hr) *(DoM) *(month) *(week) /path/to/command_or_script.sh
  • min= Minute 0 – 50
  • hr = Hour 0-59
  • DoM = Day of month 0-31
  • month = Month 1-12
  • week = Day of Week 0-7, Sunday is 0 or 7

Below are a couple of examples of how to run a script or command.
Every minute.

* * * * * /path/to/script.sh

Every day 10 minutes after 1 in the morning,

10 1 * * * /path/to/command

Also, if you don’t want to be emailed the output of the command, you can simple append “>/dev/null 2>&1” to the end of the crontab line.
Example

0 * 1 * * /path/to/command/ >/dev/null 2>&1

How to Install XenServer Tools on Linux

This assumes you are connected to your XenServer with XenCenter.  First you need to mount the xs-tools.iso on the system.  To do this right click on the VM you want to install XenServer Tools on and click “Install XenServer Tools”

Then from the console tab do the following as the root user, or just type sudo before each command

mkdir /mnt/xs-tools
mount /dev/cdrom /mnt/xs-tools
cd /mnt/xs-tools/Linux/
bash install.sh

After it finishes, you need to reboot.

How to set a Static IP Address in Ubuntu and Debian

The first thing we need to do, is open our interfaces file.  Execute the following from a terminal.

sudo vi /etc/network/interfaces

or

sudo nano /etc/network/interfaces

Then add or copy and paste the following.

auto eth0
iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1

Close the file. Now we need to change the DNS settings

sudo vi /etc/resolv.conf

or

sudo nano /etc/resolv.conf

Edit the nameserver line to something like the following.

nameserver 8.8.8.8

Close the file and then restart the networking stuff.

sudo /etc/init.d/networking restart

How to create a bootable OS X Mountain Lion (10.8) USB drive from Linux

Found this from here, since it was useful I decided to paste it here.

I saw a few guides on how to make a bootable OS X flash drive, but not many on how to do it without already having access to an OS X machine. Here are my ugly notes on creating a bootable OS X Mountain Lion (10.8)USB drive from/with Linux.

The copy of OS X 10.8 (Mountain Lion) I downloaded was in the form of a file named “InstallESD.dmg”. First, you’ll need to open it. You will need p7zip installed. If you try to dmg2img this file, you won’t get very far, so just extract it with 7-zip:

7z x InstallESD.dmg

The unrolled dmg file I found was 4348218934 bytes in size and had an md5sum of 8b4869920cd740414fe6b7e3f0b1be3e. Inside was another file with the same name (although it is slightly smaller) which is the actual install image. The internal dmg file (the one we really want) was 4333438336 bytes in size and had an md5sum of 68fd407bb74e4a2dd1913ce8bae80fc4. It must be converted prior to mounting, and for this you will need dmg2img installed.

cd InstallMacOSX.pkg 
dmg2img InstallESD.dmg 

The resulting img file was only 137322496 in bytes and had an md5sum of 05b5788f10f7300c457e2aed735eb83a. Now find the offset to properly mount the install partition in the resulting file.

hexdump -C InstallESD.img | grep “48 2b 00 04”
00008400  48 2b 00 04 80 00 01 00  31 30 2e 30 00 00 00 00  |H+……10.0….|

I got “00008400” which is hex for 33792 in decimal:

$echo $((0x00008400))
33792

We need to subtract 1024 from this number to find the target offset:

$echo ‘33792-1024’|bc
32768

Now make the loop device:

losetup -o 32768 /dev/loop0 /path/to/InstallMacOSX.pkg/InstallESD.img

And finally, mount it:

mount -t hfsplus /dev/loop0 /mnt/tmp/or/wherever/you/want

Next, I re-initialized an 8GB USB flash drive with an MSDOS partition table and created an HFS+ partition with gparted after installing these packages: hfsprogs hfsplus hfsutils.

Next, mount the HFS+ USB device R/W and cd to the /mount/point/of/loop/device and copy the contents of the mounted image:

tar cvf – * | tar xvf – -C /mount/point/to/hfs/usb/drive

Sync, unmount, insert USB drive into the Mac and power it on while holding down the OPTION key.

How to Open a Port on Redhat, CentOS or Fedora Linux

By default iptables firewall stores its configuration at /etc/sysconfig/iptables file. You need to edit this file and add rules to open port number.

Note: if you have SELinux  enabled, you’ll need to allow the port with semanage.

Open port 80

To open a different port just enter the port number.

Open flle /etc/sysconfig/iptables:

# vi /etc/sysconfig/iptables

Append rule as follows:

A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Save and close the file.  Restart iptables:

# /etc/init.d/iptables restart

or,

#service iptables restart

 

Verify that port is open

Run the following command:

netstat -tulpn | less

Make sure iptables is allowing the port you enabled:

iptables -L -n

If you need more info you can refer to the man page:

man iptables