Pages

Friday, September 21, 2012

Modify UUID of A FAT32 or NTFS Partition

The serial number (the 0x43 ~ 0x46 bytes) of FAT32 filesystem is used as UUID in Linux system. You modify UUID of a FAT32 partition by following command:

Dump the first 512 bytes of the FAT32 partition
dd if=/dev/sdb1 of=sblk.bin bs=512 count=1

Modify dump file (e.g. B893-3D6F --> C888-222C)
vi sblk.bin
%!xxd

0000000: eb58 906d 6b64 6f73 6673 0000 0208 2000  .X.mkdosfs.... .
0000010: 0200 0000 00f8 0000 3e00 f900 0000 0000  ........>.......
0000020: 00f8 3f00 f80f 0000 0000 0000 0200 0000  ..?.............
0000030: 0100 0600 0000 0000 0000 0000 0000 0000  ................
0000040: 0000 296f 3d93 b820 2020 2020 2020 2020  ..)o=..        
0000050: 2020 4641 5433 3220 2020 0e1f be77 7cac    FAT32   ...w|.
0000060: 22c0 740b 56b4 0ebb 0700 cd10 5eeb f032  ".t.V.......^..2
0000070: e4cd 16cd 19eb fe54 6869 7320 6973 206e  .......This is n
0000080: 6f74 2061 2062 6f6f 7461 626c 6520 6469  ot a bootable di
0000090: 736b 2e20 2050 6c65 6173 6520 696e 7365  sk.  Please inse
00000a0: 7274 2061 2062 6f6f 7461 626c 6520 666c  rt a bootable fl
00000b0: 6f70 7079 2061 6e64 0d0a 7072 6573 7320  oppy and..press
00000c0: 616e 7920 6b65 7920 746f 2074 7279 2061  any key to try a
00000d0: 6761 696e 202e 2e2e 200d 0a00 0000 0000  gain ... .......
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000140: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000150: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000160: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000170: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000180: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000190: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.

%!xxd -r
x! sblk_m.bin

Write back to the partition
ATTENTION: Make sure that the first 512 bytes of modified file are the same as unmodified. (excepting the serial number)
dd if=sblk_m.bin of=/dev/sdb1 bs=512 count=1
Check UUID of the partition
blkid /dev/sdb1

Wednesday, September 19, 2012

Disable / Bring HDD into Sleep State in Linux


When booting Linux from external device you may want to disable internal hard disk drive, you can disable your hard drive without removing your hard drive from your laptop/desktop PC.

Disable / Hot unplug SATA Drive
echo 1 > /sys/block/sda/device/delete

Enable / Scan SATA Devices
echo "- - -" > /sys/class/scsi_host/host0/scan
 PS: The hard disk drive may automatically power down when you disable it.


If you want to put your hard drive into standby / sleep state to save power, and it can automatically weak up when the system try to access it. You may try to use hdparm.

Put HDD into standby state
hdparm -y /dev/sda

Put HDD into sleep state
hdparm -Y /dev/sda

ATTENTION: When using hdparm command to put drive into standby/sleep state, the SATA drive may weak up if your system try to access this drive.

Friday, September 14, 2012

PERL Regular Expression

Modifiers
m      Matching
m/.../

s        Substitution
s/.../.../

i        Do case-insensitive pattern matching.
.../i

g       Global matching.
.../g

Meta-characters

           \        Quote the next metacharacter
           ^       Match the beginning of the line
           .        Match any character (except newline)
           $       Match the end of the line (or before newline at the end)
           |        Alternation
           ()      Grouping
           []      Bracketed Character class

Logical
           [^a-z]     No lowercase letters
            abc|def  abc or def

Sequence
         \w       Match a "word" character (alphanumeric plus "_",
                    plus other connector punctuation chars plus Unicode marks)
         \W      Match a non-"word" character
         \s        Match a whitespace character
         \S       Match a non-whitespace character
         \d       Match a decimal digit character
         \D      Match a non-digit character

Quantifiers
           *           Match 0 or more times
           +           Match 1 or more times
           ?           Match 1 or 0 times
           {n}       Match exactly n times
           {n,}      Match at least n times
           {n,m}   Match at least n but not more than m times


Examples
           s/^([^ ]*) *([^ ]*)/$2 $1/;     # swap first two words
           (ha)+     #Either ha or haha or hahaha or ...
           (eg|le)gs     #Either eggs or legs

Wednesday, September 5, 2012

Altera USB Blaster Linux

Enable USB Blaster for User Access
vi /etc/udev/rules.d/51-usbblaster.rules

# USB-Blaster
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6001", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6002", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6003", MODE="0666"

# # USB-Blaster II

BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6010", MODE="0666"
BUS=="usb", SYSFS{idVendor}=="09fb", SYSFS{idProduct}=="6810", MODE="0666"

Reload Rules for udev
 udevadm control --reload-rules