Saturday, May 09, 2020
Linux dd multiple partitions into single image file
List block devices
[root@localhost ddtest]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 244M 0 disk
├─sdb1 8:17 1 30M 0 part /run/media/root/datapartition2
├─sdb2 8:18 1 40M 0 part /run/media/root/datapartition
└─sdb3 8:19 1 50M 0 part /run/media/root/datapartition1
/dev/sdb1,2,3 = 30M,40M,50M in size
Umount them
[root@localhost ddtest]# umount /dev/sdb*
Confirm again
[root@localhost ddtest]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 244M 0 disk
├─sdb1 8:17 1 30M 0 part
├─sdb2 8:18 1 40M 0 part
└─sdb3 8:19 1 50M 0 part
Fdisk the drive to find its last partition end sector
root@localhost ddtest]# fdisk -l /dev/sdb
Disk /dev/sdb: 255 MB, 255852544 bytes, 499712 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xf4f4f4f4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 63487 30720 83 Linux
/dev/sdb2 63488 145407 40960 83 Linux
/dev/sdb3 145408 247807 51200 83 Linux
Calculate dd count over 1MB with formula below
(<last partition end sector> + 1) / 2048
For this USB we have (247807 + 1) / 2048 = 121
Now dd the whole /dev/sdb to test.iso with count of 121 times of 1MBytes
[root@localhost ddtest]# dd if=/dev/sdb of=test.iso bs=1M count=121 status="progress" conv=sync,noerror
121+0 records in
121+0 records out
126877696 bytes (127 MB) copied, 37.6761 s, 3.4 MB/s
Check the test.iso file size
[root@localhost ddtest]# ls -alh
-rw-r--r--. 1 root root 121M May 8 23:37 test.iso
Test the ISO file by restoring the ISO to another USB drive.
Plug out USB 1 and plug in USB 2 and check lsblk
[root@localhost ddtest]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 3.7G 0 disk
Dd the test.iso file to /dev/sdb
[root@localhost ddtest]# dd if=test.iso of=/dev/sdb bs=1M conv=sync,noerror
121+0 records in
121+0 records out
126877696 bytes (127 MB) copied, 25.2433 s, 5.0 MB/s
Check lsblk again
[root@localhost ddtest]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 3.7G 0 disk
├─sdb1 8:17 1 30M 0 part
├─sdb2 8:18 1 40M 0 part
└─sdb3 8:19 1 50M 0 part
Now we have 3 partitions restored identical to USB 1
Try to mount and check partition content
[root@localhost ddtest]# mount /dev/sdb1 1
[root@localhost ddtest]# mount /dev/sdb2 2
[root@localhost ddtest]# mount /dev/sdb3 3
[root@localhost ddtest]# ls 1
WinSCP-5.17.5-Setup.exe
[root@localhost ddtest]# ls 2
WinSCP-5.17.5-Setup.exe
[root@localhost ddtest]# ls 3
WinSCP-5.17.5-Setup.exe
Check lsblk
[root@localhost ddtest]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 3.7G 0 disk
├─sdb1 8:17 1 30M 0 part /root/Desktop/temp/ddtest/1
├─sdb2 8:18 1 40M 0 part /root/Desktop/temp/ddtest/2
└─sdb3 8:19 1 50M 0 part /root/Desktop/temp/ddtest/3
It also works with Windows tools such as Rufus...
Or Win32 Disk Imager, but only if the device exists under the drop button circled below
Just to add, if you are having missing partition from Gparted you can try to zeroing the 1st sector of 512 bytes (MBR)
[root@localhost ddtest]# dd if=/dev/zero of=/dev/sdc bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00308483 s, 166 kB/s
Thursday, May 07, 2020
Nginx PHP-FPM setup under Kali Linux
Another Nginx PHP-FPM setup post similar to previous post [ here ]To start with, install Nginx...
root@kali:~# apt-get -y install nginx
Start Nginx
root@kali:~# service nginx start
Install PHP-FPM, note the version
root@kali:~# apt-get -y install php-fpm
Edit default configuration
root@kali:~# vi /etc/nginx/sites-available/default
Add index.php into server block
index index.html index.htm index.nginx-debian.html index.php;
Add location block
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
Restart Nginx
root@kali:~# service nginx restart
Edit php.ini, note the PHP-FPM version, add cgi.fix_pathinfo=0
root@kali:~# vi /etc/php/7.3/fpm/php.ini
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
Restart PHP-FPM
root@kali:~# service php7.3-fpm restart
Create a PHP test page "test.php" as content below and save it to /var/www/html/
<?php
phpinfo();
?>
run the PHP file = http://<your host>/test.php
Monday, April 20, 2020
Nginx PHP-FPM setup under Centos 7
Nginx (pronounced as Engine-X) is a web and reverse proxy server well known for its speed and capability to handle large number of requestsWhile PHP-FPM (PHP-FastCGI process manager) is a common gateway interface between the web server and dynamic content serving programs. It listens on a port or socket and passes the request between the PHP and web server
To start with, install Nginx...
[root@localhost ~]# yum install nginx -y
Start the service
[root@localhost ~]# service nginx start
Now test the Nginx by opening its default web page http://<your host>/
Find Nginx web directory by checking service status
[root@localhost ~]# service nginx status
Apr 20 20:42:56 localhost.localdomain nginx[5942]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Apr 20 20:42:56 localhost.localdomain nginx[5942]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Grep "root" from the "nginx.conf" file
[root@localhost ~]# grep root /etc/nginx/nginx.conf
root /usr/share/nginx/html;
Create a PHP test page "test.php" as content below and save it to /usr/share/nginx/html/
<?php
phpinfo();
?>
Try to run the PHP file = http://<your host>/test.php
As we know it won't parse. It will just download or show the PHP file content. This is expected since we didn't link Nginx with PHP-FPM yet.
Install PHP-FPM
[root@localhost ~]# yum install php-fpm -y
Check the PHP-FPM installation
[root@localhost ~]# service php-fpm status
Locate the PHP=FPM "www.conf" file
[root@localhost ~]# locate www.conf
/etc/php-fpm.d/www.conf
Edit the "/etc/php-fpm.d/www.conf" change listen ip:port to socket
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /run/php-fpm/php-fpm.sock
Restart PHP-FPM
[root@localhost ~]# service php-fpm restart
Backup and edit /etc/nginx/nginx.conf
Under server scope {} block, add location scope {} block to enable PHP-FPM to parsePHP file
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#location / {
#}
location ~* \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Make sure this line is pointing to correct Unix socket
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
Restart both Nginx and PHP-FPM
[root@localhost ~]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
[root@localhost ~]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
Try to run the PHP file = http://<your host>/test.php again
x
Sunday, April 19, 2020
Minimal PHP/Apache Docker setup
Why Docker?
The portability of the containers, can be deployed anywhereEfficient system resource usage compare to VM
How to Dockerize your php application?
Assuming your OS already have a good and working Docker installation
Let us use single page PHP applications below, index.php inside a webfolder directory
index.php content;<?php
phpinfo();
?>
[root@localhost php_docker]# tree .
.
└── webfolder
└── index.php
Create a Dockerfile
Dockerfile in a list of instruction/command call to assemble the image
[root@localhost php_docker]# tree .
.
├── Dockerfile
└── webfolder
└── index.php
Content of the Dockerfile;
[root@localhost php_docker]# tree .
.
├── Dockerfile
└── webfolder
└── index.php
Content of the Dockerfile;
FROM php:7.4-apache
COPY webfolder/ /var/www/html/
EXPOSE 80
Explanation for each line
FROM php:7.4-apache
[root@localhost php_docker]# docker build --rm -t myphpdocker .
docker build [OPTIONS] PATH | URL | -
--rm = Remove intermediate containers after a successful build
-t = Name and optionally a tag in the 'name:tag' format
myphpdocker = docker container name
. (single dot) = build path
Check the built image
[root@localhost php_docker]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
myphpdocker latest 0c1fe5b1aa9e 47 minutes ago 414 MB
Next is to run the docker
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
-t = Allocate a pseudo-TTY
-i = Keep STDIN open even if not attached
-it = For interactive processes (like a shell), you must use -i -t together
-p = Publish a container's port(s) to the host
-d = Run container in background and print container ID
Lets try the interactive mode first
[root@localhost php_docker]# docker run -p 80:80 -it myphpdocker
Apache log appear on the terminal.
Open your browser and head to "http:/<host ip>/"
Now try the detach mode
[root@localhost php_docker]# docker run -p 80:80 -d myphpdocker
Check the running container
[root@localhost php_docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4619304831d4 myphpdocker "docker-php-entryp..." 6 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp frosty_tesla
Explanation for each line
FROM php:7.4-apache
- php:7.4-apache based image selection
- copy webfolder content into container /var/www/html/
- Apache2 default web directory
- expose port 80 to the host
[root@localhost php_docker]# docker build --rm -t myphpdocker .
docker build [OPTIONS] PATH | URL | -
--rm = Remove intermediate containers after a successful build
-t = Name and optionally a tag in the 'name:tag' format
myphpdocker = docker container name
. (single dot) = build path
Check the built image
[root@localhost php_docker]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
myphpdocker latest 0c1fe5b1aa9e 47 minutes ago 414 MB
Next is to run the docker
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
-t = Allocate a pseudo-TTY
-i = Keep STDIN open even if not attached
-it = For interactive processes (like a shell), you must use -i -t together
-p = Publish a container's port(s) to the host
-d = Run container in background and print container ID
Lets try the interactive mode first
[root@localhost php_docker]# docker run -p 80:80 -it myphpdocker
Apache log appear on the terminal.
Open your browser and head to "http:/<host ip>/"
Now try the detach mode
[root@localhost php_docker]# docker run -p 80:80 -d myphpdocker
Check the running container
[root@localhost php_docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4619304831d4 myphpdocker "docker-php-entryp..." 6 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp frosty_tesla
Wednesday, April 15, 2020
vLan on Realtek PCIe GBE Family
Download "Diagnostic Program for Win7/Win8/Win10" and installhttps://www.realtek.com/en/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-pci-express-software
Select the Realtek NIC > VLAN and add accordingly
Subscribe to:
Posts
(
Atom
)