Tagged: command

Debian Wheezy (7.5): Accessing the Encrypted Partition From the Recovery System

Continued from my previous post, Debian Wheezy (7.5): Encrypted Root Filesystem on laptop.

In my previous post, I created an extra partition for recovery system that could be used to repair the main system in a situation where it becomes corrupted or un-bootable. But how exactly can I access it from the recovery system? Well, steps described below is something I would try, in other words, just a theory. If you know a better (correct) way, or if I'm doing wrong, please feel free to comment!

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Booting Into the Recovery System

At the GRUB menu, choose the Recovery system. In my case it's on /dev/sda2.
debian_install_4

Accessing Encrypted Device with `cryptsetup luksOpen`

First, let's see my partition layout: # parted (parted) p Model: ATA WDC WD3200BEKT-6 (scsi) Disk /dev/sda: 320GB Sector Size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 310GB 310GB 2 310GB 320GB 10.1GB ext4 (parted) q

Since /dev/sda1 is encrypted with crypt-luks, normal mount command would not work. # mount /dev/sda1 /mnt/main mount: unknown filesystem type 'crypto_LUKS'

So it needs to be opened to access the encrypted device. This process requires your passphrase. This will create /dev/mapper/unlocked. # cryptsetup luksOpen /dev/sda1 unlocked Enter passphrase for /dev/sda1:

Can we mount the device now? Nope. Because it's LVM.

Accessing LVM

First install lvm2. # apt-get install lvm2

SIDE NOTE:
If you get the following warnings after executing above command:

update-initramfs: Generating /boot/initrd.img-3.2.0-4-amd64
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168f-2.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168f-1.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8105e-1.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168e-3.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168e-2.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168e-1.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168d-2.fw for module r8169
W: Possible missing firmware /lib/firmware/rtl_nic/rtl8168d-1.fw for module r8169

You need to add contrib and non-free repositories to /etc/apt/sources.list: # vim /etc/apt/sources.list -------------------------------------- deb http://ftp.us.debian.org/debian wheezy main contrib non-free # apt-get update Then install the firmware-realtek package: # apt-get install firmware-realtek

Then load the necessary module. # modprobe dm-mod

Scan the system for LVM volumes and identify the volume group name in the output. # vgscan Reading all physical volumes. This may take a while... Found volume group "debian" using metadata type lvm2

Activate the volume. # vgchange -ay debian 2 logical volume(s) in volume group "debian" now active

Then find the logical volume that has the root filesystem # lvs LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert root debian -wi-a--- 284.98g swap debian -wi-a--- 3.72g

Mounting It Now!

Now all the preparation is done. It's time to mount it. # mount -o ro,user /dev/debian/root /mnt/unlocked # ls mnt/unlocked bin etc lib media proc sbin sys var boot home lib64 mnt root selinux tmp vmlinuz dev initrd.img lost+found opt run srv usr

Voilà! Successfully mounted!

That's all!
-gibb

Linux: Getting to know `find` command

The find command is one of most important and much used command in my opinion. It's very useful because it not only finds files and directories with detailed options but also can execute additional commands (ex: mv, rm, etc...) on found items.

I'm ashamed to say this but, on the other day, I accidentally corrupted my external USB hard drive that had all of my back-up files! I used TestDisk hoping to fix its partition table but it didn't work. So I used PhotoRec to recover photos.

If you have used PhotoRec before, you know this but it does not recover files with original names. Instead, it creates a directory, recup_dir.[number], and put files with a unique names like f1175051952.jpg. In my case, it created more than 3000 directories with image files scattered all over. The find command came in handy!

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Finding all .jpg files and ignoring case:

Find all files whose name has .jpg extension in the current directory and below. $ find . -iname "*.jpg" -print

Finding and moving all .jpg files in one single pass:

Find all files whose name has .jpg extension in the current directory and below and move them to /mnt/jpg. $ find . -iname "*.jpg" -type f -exec mv {} /mnt/jpg \;

Finding and removing empty directories:

Find empty directory in the current directory and below and remove them. $ find . -type d -empty -exec rmdir {} \;

Finding files with no extensions:

Find files whose name does not contain extension in the current directory and below. $ find . -type f ! -name "*.*"

Finding files without .jpg extension:

Find files whose name does not have .jpg extension in the current directory and below. $ find . -type f ! -name "*.jpg"

Here is some other useful options.

Finding files with 777 permissions:

Find files whose permissions are 777 $ find . -type f ! -perm 0777 -print

Finding files based on user:

Find files which belong to user ubyt3m3 under /home directory. $ find /home -user ubyt3m3 -print

Finding accessed files in last 1 hour:

Find files which are accessed in last 1 hour under /var/log directory. $ find /var/log -amin -60 -print

Finding last 7-14 days modified files:

Find files which are modified in last 1 hour under /home/www directory. $ find /home/www -mtime +7 -mtime -14 -print

That's all!
-gibb

FreeBSD 10: Mounting USB Drive with ext4 Filesystem

I have been configuring FreeBSD 10 on my HP Pavilion laptop for a while now. On and off, I tried to mount a USB drive formatted with ext4 filesystem but failed with below messages: # mount /dev/da0s1 /mnt mount: /dev/da0s1: Invalid argument # mount -t ext4 /dev/da0s1 /mnt mount: /dev/da0s1: Operation not supported by device

Hmm... the device is not available? # dmesg | grep da0 ... da0 at umass-sim0 bus 0 scbus1 target 0 lun 0 da0: <HITACHI_ DK23ES-20 00K5> Fixed Direct Access SCSI-0 device da0: Serial Number 0B02011C050FB0DC da0: 40,000MB/s transfers da0: 19077MB (39070080 512 byte sectors: 255H 63S/T 2432C) da0: quirks=0x2<NO_6_BYTE> # gpart show da0 => 63 39070017 da0 MBR (19G) 63 1985 - free - (993K) 2048 39068032 1 linux-data (19G) # ls /dev/da0* /dev/da0 /dev/da0s1

I have no idea why it's not working so I followed the handbook, 18.5. USB Storage Devices (and I also made a regular user mountable).

Edit /etc/devfs.rules to allow the operator group to be able to read and write the device: # vi /etc/devfs.rules -------------------------------------------- [localrules=5] add path 'da*' mode 0660 group operator

Then edit /etc/rc.conf to enable the devfs.rules(5) ruleset: # vi /etc/rc.conf -------------------------------------------- devfs_system_ruleset="localrules"

Next allow regular user to mount file system: # vi /etc/sysctl.conf -------------------------------------------- vfs.usermount=1

Also execute sysctl to make the update available now: # sysctl vfs.usermount=1 vfs.usermount: 0 -> 1

Create a directory which a regular use can mount to: # mkdir /mnt/ubyt3m3 # chown ubyt3m3:ubyt3m3 /mnt/ubyt3m3

Now return to a regular user and try to mount the USB drive: $ mount -t ext4 /dev/da0s1 /mnt/ubyt3m3 mount: /dev/da0s1: Invalid argument

I got Invalid argument instead of Operation not permitted but this did not resolve my original issue. Hmm... does this mean FreeBSD does not support mounting ext4 filesystem? A bit of googling found that FreeBSD supports ext2/ext3 with ext2fs type but not ext4. However, I found that FreeBSD base system comes with the fuse implementation. Indeed, there is sysutils/fusefs-ext4fuse. Let's try installing this. # cd /usr/ports/sysutils/fusefs-ext4fuse # make install clean

Well, will mounting work now? Let's see... $ ext4fuse /dev/da0s1 /mnt/ubyt3m3 fuse: failed to open fuse device: No such file or directory

So, it's still not working, huh? A further googling led me to some hints. It looks like there is a kernel module for fuse, fuse.ko, and this needs to be loaded to the kernel. # kldload fuse.ko

Lastly, edit /boot/loader.conf to load the module each boot: # vi /boot/loader.conf -------------------------------------------- fusefs_load="YES"

Now mounting USB drive with ext4 filesystem is working! $ ext4fuse /dev/da0s1 /mnt/ubyt3m3 $ ls /mnt/ubyt3m3 lost+found $

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

That's all!
-gibb

FreeBSD 10: Installing Apache 2.4, MySQL 5.5, and PHP5.5 — Missing libphp5.so

Continuing my quest with FreeBSD.

Today, I was installing Apache 2.4, MySQL 5.5, and PHP 5.5 (php55-5.5.11) on newly installed system. I've done this kind of installation many times on Linux so I didn't expect much of problems. Boy, I was wrong...

Apache and MySQL installation were straight forward and had no problem. After PHP installation, I couldn't find libphp5.so in /usr/local/libexec/apache24/! A little googling found articles/forums on older version of FAMP. They said its installation should be automatic or "Build Apache module" option needs to be selected, which I did not have such an option any where.

Then one thread mentioned something about configuring php conf file. So, I opened Makefile for PHP55: # vim Makefile ------------------------------------- ... OPTIONS_DEFINE+=APACHE CLI CGI FPM... OPTIONS_DEFAULT=APACHE CLI CGI FPM...

Compiled PHP55 again: # make install config ===> php55-5.5.11 doesn't install the Apache module anymore: update your OPTIONS and build www/mod_php55 port instead. *** Error code 1

Aha! www/mod_php55. I wonder if php installation didn't install mod_php55 but now I know what I need to do: # cd /usr/local/www/mod_php55/ # make install clean ... --- Zend/zend_dtrace_gen.h dtrace: failed to compile script /usr/ports/www/mod_php55/work/php-5.5.11/Zend/zend_dtrace.d: line 30: failed to resolve INP_IPV4: Unknown variable name ...

Hmm... I wonder if this was causing php55 installation to fail creating libphp5.so. Well, another googling found a suggestion/solution to load the dtraceall module: # kldload dtraceall # echo 'dtraceall_load="YES"' >> /boot/loader.conf

Now, mod_php55 was successfully installed as well as libphp5.so!

Here is the whole steps to install apache, mysql, and php:

NOTE: The steps below are not suitable for production use. Be warned!

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

Apache 2.4 - Installation and Configuration:

# cd /usr/ports/www/apache24/ # make install clean

Edit /etc/rc.conf to make the Apache server will start automatically at system boot. # vim /etc/rc.conf ------------------------------------- apache24_enable="YES"

Test the Apache server installation using the following command: # /usr/local/etc/rc.d/apache24 start

MySQL - Installation and Configuration:

# cd /usr/ports/databases/mysql55-server/ # make install clean

Start MySQL # /usr/local/etc/rc.d/mysql-server onestart

Update /etc/rc.conf # vim /etc/rc.conf ------------------------------------- mysql_enable="YES"

Set root password # rehash # mysqladmin -uroot password '<password>'

Create my.cnf # cp /usr/local/share/mysql/my-small.cnf /etc/my.cnf

Restart mysql # /usr/local/etc/rc.d/mysql-server restart

PHP Installation and Configuration:

Here is the moment of truth. First, load the dtraceall kernel module, update the /boot/loader.conf file, and then install php55. # kldload dtraceall # echo 'dtraceall_load="YES"' >> /boot/loader.conf # cd /usr/ports/lang/php55 # make install clean

Check to see if libphp5.so is there # ls /usr/local/libexec/apache24/ httpd.exp mod_include.so mod_access_compat.so mod_info.so ...

Nope, it's not there. Then manually compile www/mod_php55/ # cd /usr/ports/www/mod_php55/ # make install clean

Now, check to see if libphp5.so is there again # ls /usr/local/libexec/apache24/ httpd.exp mod_include.so libphp5.so mod_info.so ...

Copy the PHP configuration file # cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Edit /usr/local/etc/apache24/httpd.conf file and add the following lines # vim /usr/local/etc/apache24/httpd.conf ------------------------------------- AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps

Add the following line under the LoadModule section if it's not there LoadModule php5_module libexec/apache24/libphp5.so

Edit the DirectoryIndex section DirectoryIndex index.php index.html

Now restart the apache server # /usr/local/etc/rc.d/apache24 restart

Let's see now if it can show a php page # vim /usr/local/www/apache24/data/index.php ------------------------------------- < ?php phpinfo(); ?>

Voilà! It's working now!

phpinfo

That's all!
-gibb

FreeBSD 10: linux_base-f10-10_7 linuxulator is not (kld) loaded error

On the other day, I was trying to install Adobe Flash plugin support for opera by following the FreeBSD handbook. It says:

To install Adobe® Flash® plugin support, first compile the www/linux-f10-flashplugin11 port, as a package is not available due to licensing restrictions. Then install either the www/opera-linuxplugins port or package. This example compiles both applications from ports: # cd /usr/ports/www/linux-f10-flashplugin11 # make install clean # cd /usr/ports/www/opera-linuxplugins # make install clean

So I followed above example and typed make install clean for linux-f10-flashplugin11. Then I got below error: ... Linux_base-f10-10_7 linuxulator is not (kld)loaded. *** [install] Error code 1...

Huh? Being a FreeBSD novice, I got a bit confused because this chapter (7.2.2. Opera) in the handbook didn't mention anything about loading linux kernel module.

But a little googling came to rescue!

Apparently, I needed to load the linux.ko module before installing those ports (found out in chapter 11.2. Configuring Linux® Binary Compatibility):

To load the linux.ko module: # kldload linux

To verify: # kldstat Id Refs Address Size Name 1 11 0xffffffff80200000 15f0310 kernel 2 1 0xffffffff817f1000 20400 geom_eli.ko 3 2 0xffffffff81812000 34ed0 crypto.ko 4 1 0xffffffff81a12000 432d4 linux.ko

After this, compiling for linux-f10-flashplugin11 and opera-linuxplugins went smoothly.

Disclaimer:
The information in this site is the result of my researches in the Internet and of my experiences. It is solely used for my purpose and may not be suitable for others. I will NOT take any responsibility of end result after following these steps (although I will try to help if you send me your questions/problems).

That's all!
-gibb