Archive for the ‘Ubuntu / Linux’ Category.

Linux – Retrieve Windows OEM/BIOS key

Most laptops come with Windows license, but if you run Linux variant as your primary OS, you can still use the Windows OEM activation in VirtualBox, kvm, or what ever virtualization tool you use.

To retrieve the product key in bios.

sudo xxd /sys/firmware/acpi/tables/MSDM

Key will show at the end of the output

Using nslookup to add allow entries for PeerGuardian Linux

I use PeerGuardian Linux to block IPs as extra layer of protection my servers. Because I block more than I need, I wanted a way to quickly add IPs to the allow.p2p file by their hostname. Below is the contents of my “Add_Allow_IPs” script.
nslookup $1 | sed -e '1,4 d' -e '$ d' -e 'N;s/\n/ /' -e 's/ Address: /:/g' -e 's/Name:\t//g' >> /etc/pgl/allow.p2p
sudo pglcmd reload
sudo pglcmd restart

So now if I run:
./Add_Allow_IPs google.com
It will take out all the google.com ipv4 addresses from nslookup output and make them line items in the allow.p2p file. It dose not work for IPV6 and CNAME results.

Windows previous versions for ZFS backed Samba shares

If you want ZFS’s snapshots to show up as previous versions in Windows File Shares you need to have ZFS backed, samba data set with 1 or more snapshots. My zfs data set is tank in my examples. A snapshot can be made manually or automatically. The easy way to manage automatic snapshots is to use ‘zfs-auto-snapshot’ that is bundled with zfsonlinux. Example for hourly snapshots of the tank.
zfs-auto-snapshot -l hourly tank
Or you can use cron to do hourly snapshots for you.
5 */1 * * * zfs snapshot tank@`date +%F-%H%M`
Also cron can clean up old snapshots. (Careful with this one. Verify zfs list -H -o name -t snapshot -r tank | head -n 24 output first)
30 0 * * * zfs list -H -o name -t snapshot -r tank | head -n 24 | xargs -n1 sudo zfs destroy

Lastly to have samba to use ZFS snapshots you’ll need shadow: format, vfs objects, shadow: sort, and shadow: snapdir added to your samba share. Here is example config with if using zfs-auto-snapshot hourly.
[tank]

shadow: format = zfs-auto-snap_hourly-%F-%H%M
vfs objects = shadow_copy2
shadow: sort = desc
path = /tank
comment = ZFS dataset with Previous Versions enabled
writeable = yes
public = yes
shadow: snapdir = .zfs/snapshot

Mapping raw image files (from dd or ddrescue) with partition support in linux

When I do full backups of a hard drive, mostly for recovery reasons, I almost always use GNU ddrescue. When I want to access a single file off that image I’ve been using a great windows application called ImDisk. Open it up, point to the raw image on my nas, it will ask me what partition to mount. For NTFS partitions it auto mounts to my windows system and I can grab what ever I need.

But I wanted to do this in linux. I knew about losetup and mapping a loop device. But this does not work for images with partition tables. After little googling I found kpartx. Simple 1 line solution.
kpartx -a -v /path/to/img.file
This will look at that image file’s partition table (I can only confirm MBR support) and map to a loop device. Then it will map each partition at /dev/mapper/loopXpX. If needed you can symlink /dev/mapper/loopXpX to /dev/loopXpX, so application like gparted can understand the partition layout.

** Now to do this in FreeBSD (Like Nas4free/FreeNas)

mdconfig -a -t vnode -u 0 -f /path/to/img.file

this makes a MD device. Now you can mount /dev/mdXpX, or run other file system tools.

smartmontools for external USB drive docks

I recently purchased a USB 3 drive dock (Orico 6619) because my current drive dock (MyGica… no model number) doesn’t support SMART info with smartctl command.


jason@j2c ~ $ sudo smartctl /dev/sdb -a
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.11.0-12-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

Read Device Identity failed: scsi error unsupported scsi opcode

A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.

And then found out the vendor id:product id was in the smartmontools bad list. So when I got my new USB 3 enclosure (impulse buy, I did no research) I was sadden by this


jason@j2c ~ $ sudo smartctl /dev/sdb -a
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.11.0-12-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

/dev/sdb: Unknown USB bridge [0x2537:0x1066 (0x100)]
Please specify device type with the -d option.

Use smartctl -h to get a usage summary

I was bummed. After reading smartmontools mailing list archive, most new USB3 devices worked with the -d sat option.


sudo smartctl /dev/sdb -a -d sat
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.11.0-12-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family: Seagate Momentus 7200.4
Device Model: ST9320423AS
....

Sucsess! My new drive dock does work with SMART read outs! Back to saving peoples data off old hard drives.

DD with real time speed

I found a neat Linux command line helper. PV : Pipe Viewer. It allows me to view the data throughput (ex MB/s), ETA, and progress bar when moving data through a pipe. For example I just used it when restoring hard drive image to a new physical disk.
pv -petr /backup/image.img | dd of=/dev/sda

Map raw image file to VirtualBox

In the attempt to restore data off a failing hard drive I use ddrescue to make raw copy of a hard disk. But I wanted to attempt to boot the system in a virtual box for a more simple data recovery. Because the VirtualBox GUI does not have the ability to make raw device mapping you must do it by VBoxManage command. I just open up a terminal, cd into my VirtualBox storage folder and run:

VBoxManage internalcommands createrawvmdk -filename my_raw_mapping.vmdk -rawdisk /path/to/backup.img

Now map the newly created vdmk file to your VM and off you go.

Linux Mint on Software RAID5 (MDADM)

  1. Load Mint Live DVD
  2. Setup RAID5 Array. Use gparted (or any paritition tool) to make /boot and root (/) and swap partitions on each drive. Then use mdadm to make RAID1 /boot, RAID5 root (/) and format swap partitions. (I don’t recommending RAID’ing swap spaces, or don’t make swap partitions at all, use a file based swap once the system is running)
  3. Run Installer – Do advance partition layout. Map /boot, /, and swaps (if swap partitions were made). Set boot loader to RAID1′s MD (It always fails for me. But we’ll fix it later)
  4. When installer is done, don’t leave live session. Open terminal. run the following
    • mount /dev/md1 /mnt (md1 is my root mdadm array)
    • mount /dev/md0 /mnt/boot (md0 is my raid1 boot mdadm array)
    • for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done (Mount all special folders so we can run commands in a chroot environment. Taken from here)
    • chroot /mnt
    • apt-get install mdadm
    • grub-install /dev/sda;grub-install /dev/sdb;grub-install /dev/sdc (This is installing grub on each drive, so if drive fails we can boot off another. do this for all drvies)
    • update-grub
    • exit
  5. reboot into os

Finding hardware info on linux

  • How to find motherboard make and model
    • dmidecode -t baseboard
  • How to find CPU details
    • dmidecode -t processor
    • cat /proc/cpuinfo
  • Memory
    • free –  will show current memory ussage including total amount of memory installed
    • dmidecode -t memory –  for more detail on each dimm
    • decode-dimms – http://www.richud.com/wiki/Ubuntu_See_Live_RAM_Timings_Decode_DIMMS

Linux – Remove all empty folders

So yeah, Got a lot of empty folders? Want to get rid of them? run this in a folder with empty subfolders!

find -depth -type d -empty -exec rmdir {} \;