PXE Boot

Topic

PXE Boot

Explanation

The Preboot eXecution Environment (PXE, also known as Pre-Execution
Environment;  sometimes pronounced  "pixie") is  an  environment to
boot  computers using  a  network interface  independently of  data
storage devices  (like hard disks) or  installed operating systems.
PXE was introduced as part of the Wired for Management framework by
Intel and is described in the specification (version 2.1) published
by Intel and  Systemsoft on September 20, 1999.[1]  It makes use of
several  network  protocols   like  Internet  Protocol  (IP),  User
Datagram Protocol (UDP), Dynamic Host Configuration Protocol (DHCP)
and  Trivial File  Transfer Protocol  (TFTP) and  of  concepts like
Globally  Unique Identifier  (GUID), Universally  Unique Identifier
(UUID)  and  Universal Network  Device  Interface  and extends  the
firmware of  the PXE  client (the computer  to be  bootstrapped via
PXE) with  a set  of predefined Application  Programming Interfaces
(APIs).


The PXE protocol  is approximately a combination of  DHCP and TFTP,
albeit with  subtle modifications to  both. DHCP is used  to locate
the appropriate boot server or  servers, with TFTP used to download
the initial bootstrap program  and additional files.  To initiate a
PXE bootstrap  session the  PXE firmware broadcasts  a DHCPDISCOVER
packet extended  with PXE-specific options  (extended DHCPDISCOVER)
to port  67/UDP (DHCP  server port). The  PXE options  identify the
firmware as  capable of PXE, but  they will be  ignored by standard
DHCP  servers.  If  the  firmware  receives  DHCPOFFERs  from  such
servers, it may  configure itself by requesting one  of the offered
configurations.

source : http://en.wikipedia.org/wiki/Preboot_Execution_Environment

Get The Hang

 // next, check what the packet type was
        opt = request(43,71);
        if(opt == NULL)
        {
                logger->Event(LEVEL_INFO, "MakeReply", 1,
                  "Received proxy DHCP packet");
                pkttype = 1;
        }
        else
        {
                delete[] opt->data;
                delete opt;
                logger->Event(LEVEL_INFO, "MakeReply", 1,
                  "Received PXE request packet");
                pkttype = 2;
        }

bubble sort testing… 0.00006 Ver — 4000 No.’s related

$time php bubble.php

real	0m7.404s
user	0m7.012s
sys	0m0.080s
$time php bubble.php

real	0m7.333s
user	0m7.044s
sys	0m0.068s
$time php bubble.php

real	0m7.393s
user	0m7.068s
sys	0m0.100s
$time php bubble.php

real	0m7.345s
user	0m7.024s
sys	0m0.104s
$time php bubble.php

real	0m7.545s
user	0m7.224s
sys	0m0.080s
$time php bubble.php

real	0m7.275s
user	0m6.992s
sys	0m0.072s
$time php bubble.php

real	0m7.340s
user	0m7.044s
sys	0m0.072s
$

What is a TASK_KILLABLE state in Linux ?

ABOUT TASK_KILLABLE state

TASK_KILLABLE sleeping state.

Like most versions of Unix, Linux has two fundamental ways in which a process  can be put  to sleep. A
process which is placed  in the TASK_INTERRUPTIBLE  state  will sleep  until  either (1)  something
explicitly wakes it up, or (2) a non-masked signal is received. The TASK_UNINTERRUPTIBLE state, instead,
ignores signals; processes in that  state will  require an  explicit wakeup  before they  can run
again.   There are  advantages and  disadvantages to  each  type of sleep. Interruptible sleeps enable
faster response to signals, but they  make   the  programming   harder.  Kernel  code   which  uses
interruptible sleeps must always check to see whether it woke up as a result  of a signal, and, if  so,
clean up whatever  it was doing and return  -EINTR back  to user space.  The user-space  side, too,
must  realize  that  a  system  call was  interrupted  and  respond accordingly;  not all  user-space
programmers  are known  for their diligence in this regard. Making a sleep uninterruptible eliminates
these problems, but at the cost of being, well, uninterruptible. If the expected  wakeup event does  not
materialize, the  process will wait forever and there is usually nothing that anybody can do about
it  short  of rebooting  the  system. This  is  the  source of  the dreaded, unkillable process  which is
shown to be  in the "D" state by ps.


TASK_KILLABLE behaves like  TASK_UNINTERRUPTIBLE with the exception that fatal signals will interrupt the sleep.

TYPICAL PART OF A HEADER FILE RELATED (include/linux/sched.h)
[text]
/* Convenience macros for the sake of set_current_state: */
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)
#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)

#define TASK_IDLE (TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
[/text]

LINKS
https://lwn.net/Articles/288056/
https://www.ibm.com/developerworks/linux/library/l-task-killable/
https://elixir.bootlin.com/linux/latest/ident/TASK_KILLABLE
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h#L90

udev – Linux dynamic device management

ABOUT UDEV

udev - Linux dynamic device management
udev (userspace /dev) is a device manager for the Linux kernel

CONFIG FILE RELATED

# do not edit this file, it will be overwritten on update

ACTION=="remove", GOTO="cdrom_end"
SUBSYSTEM!="block", GOTO="cdrom_end"
KERNEL!="sr[0-9]*|xvd*", GOTO="cdrom_end"
ENV{DEVTYPE}!="disk", GOTO="cdrom_end"

# unconditionally tag device as CDROM
KERNEL=="sr[0-9]*", ENV{ID_CDROM}="1"

# media eject button pressed
ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $tempnode", GOTO="cdrom_end"

# import device and media properties and lock tray to
# enable the receiving of media eject button events
IMPORT{program}="cdrom_id --lock-media $tempnode"

LABEL="cdrom_end"
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/lib/udev/rules.d/60-cdrom_id.rules" [readonly] 18L, 584C                                  1,3           All

RELATED SHELL SESSION (cdrom)

[bash]
$cat /proc/sys/dev/cdrom/info
CD-ROM information, Id: cdrom.c 3.20 2003/12/17

drive name: sr0
drive speed: 48
drive # of slots: 1
Can close tray: 1
Can open tray: 1
Can lock tray: 1
Can change speed: 1
Can select disk: 0
Can read multisession: 1
Can read MCN: 1
Reports media changed: 1
Can play audio: 1
Can write CD-R: 1
Can write CD-RW: 1
Can read DVD: 1
Can write DVD-R: 1
Can write DVD-RAM: 1
Can read MRW: 1
Can write MRW: 1
Can write RAM: 1

$

[/bash]

FROM MANUAL

udev  supplies  the system  software  with  device events,  manages permissions of  device nodes and
may create  additional symlinks in the  /dev  directory, or  renames  network  interfaces. The  kernel
usually just assigns unpredictable  device names based on the order of discovery. Meaningful symlinks
or network device names provide away to reliably  identify  devices based  on  their properties  or
current configuration. The udev  daemon, udevd(8),  receives device uevents  directly from the kernel 
whenever  a device is added or  removed from the system, or  it changes its  state. When  udev receives
a device  event, it matches  its  configured  set   of  rules  against  various  device attributes  to
identify the  device. Rules  that match  may provide additional device information to be  stored in the
udev database or to be used to create meaningful symlink names. All  device  in formation  udev  processes
is stored  in  the  udev database and sent out to  possible event subscribers. Access to all stored  data
and  the  event  sources is  provided  by the  library libudev.  

source: Manual

LINKS
https://www.linux.com/news/udev-introduction-device-management-modern-linux-system
https://en.wikipedia.org/wiki/Udev
https://www.thegeekdiary.com/beginners-guide-to-udev-in-linux/

bubble sort testing… 0.00005 Ver — 2000 No.’s related

$time php bubble.php

real	0m2.076s
user	0m1.736s
sys	0m0.052s
$time php bubble.php

real	0m1.8100s
user	0m1.680s
sys	0m0.044s
$time php bubble.php

real	0m1.935s
user	0m1.672s
sys	0m0.052s
$time php bubble.php

real	0m1.861s
user	0m1.676s
sys	0m0.040s
$time php bubble.php

real	0m2.076s
user	0m1.708s
sys	0m0.064s
$time php bubble.php

real	0m1.850s
user	0m1.640s
sys	0m0.060s
$time php bubble.php

real	0m1.872s
user	0m1.664s
sys	0m0.060s
$

What is a dirty inode and what are dirty bytes ?

What is a Dirtied inode

It is a  common computer term that data in a  cache is "clean" when it  has been  synchronized, and  "dirty" when  it is  different.  A dirty inode  has had new data written  into it but it  has not been
written to disk.

source : http://serverfault.com/questions/56374/dirtied-inode
dirty_inode: this method is called by the VFS to mark an inode dirty.

What are dirty_bytes

Contains the amount  of dirty memory at which  a process generating disk writes will itself  start writeback.  Note: dirty_bytes is the counterpart of dirty_ratio. Only one  of them may be specified
at a time.  When one  sysctl is  written  it is  immediately taken  into account to evaluate  the dirty
memory limits and  the other appears as 0 when read.  Note: the minimum value allowed for dirty_bytes is
two  pages (in  bytes); any  value lower  than this  limit  will be ignored and the old configuration
will be retained.

source: http://kernel.org/doc/Documentation/sysctl/vm.txt

RELATED SHELL SESSION EXPOSURE
[bash light=”true”]
$cat /proc/sys/vm/dirty_background_bytes
0
$echo 1 > /proc/sys/vm/dirty_background_bytes
$cat /proc/sys/vm/dirty_background_bytes
1
$echo 1 > /proc/sys/vm/dirty_
dirty_background_bytes dirty_bytes dirty_ratio
dirty_background_ratio dirty_expire_centisecs dirty_writeback_centisecs
$echo 1 > /proc/sys/vm/dirty_background_ratio

$echo 1 > /proc/sys/vm/dirty_background_ratio
$echo 0 > /proc/sys/vm/dirty_background_ratio
$cat /proc/sys/vm/dirty_bytes
0
$echo 1 > /proc/sys/vm/dirty_bytes
$echo 1 > /proc/sys/vm/
block_dump legacy_va_layout numa_zonelist_order
compact_memory lowmem_reserve_ratio oom_dump_tasks
dirty_background_bytes max_map_count oom_kill_allocating_task
dirty_background_ratio memory_failure_early_kill overcommit_memory
dirty_bytes memory_failure_recovery overcommit_ratio
dirty_expire_centisecs min_free_kbytes page-cluster
dirty_ratio min_slab_ratio panic_on_oom
dirty_writeback_centisecs min_unmapped_ratio percpu_pagelist_fraction
drop_caches mmap_min_addr scan_unevictable_pages
extfrag_threshold nr_hugepages stat_interval
hugepages_treat_as_movable nr_hugepages_mempolicy swappiness
hugetlb_shm_group nr_overcommit_hugepages vfs_cache_pressure
laptop_mode nr_pdflush_threads zone_reclaim_mode
$echo 1 > /proc/sys/vm/dirty_expire_centisecs
$echo 1 > /proc/sys/vm/dirty_writeback_centisecs
$

[/bash]
RELATED SOURCE CODE EXPOSURE
[c light=”true”]
/*
* ext4_dirty_inode() is called from __mark_inode_dirty()
*
* We’re really interested in the case where a file is being extended.
* i_size has been changed by generic_commit_write() and we thus need
* to include the updated inode in the current transaction.
*
* Also, dquot_alloc_block() will always dirty the inode when blocks
* are allocated to the file.
*
* If the inode is marked synchronous, we don’t honour that here – doing
* so would cause a commit on atime updates, which we don’t bother doing.
* We handle synchronous inodes at the highest possible level.
*
* If only the I_DIRTY_TIME flag is set, we can skip everything. If
* I_DIRTY_TIME and I_DIRTY_SYNC is set, the only inode fields we need
* to copy into the on-disk inode structure are the timestamp files.
*/
void ext4_dirty_inode(struct inode *inode, int flags)
{
handle_t *handle;

if (flags == I_DIRTY_TIME)
return;
handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
if (IS_ERR(handle))
goto out;

ext4_mark_inode_dirty(handle, inode);

ext4_journal_stop(handle);
out:
return;
}
[/c]
SOURCE CODE TAKEN FROM OFFICIAL LINUX KERNEL
LINKS
https://www.kernel.org/doc/Documentation/filesystems/vfs.txt
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/ext4/inode.c?h=v4.20-rc3

The atime and noatime attribute

The atime and noatime attribute


Linux records  information about when  files were created  and last
modified as  well as  when it  was last accessed.  There is  a cost
associated  with recording  the  last access  time.  The ext2  file
system of Linux has an attribute that allows the super-user to mark
individual  files   such  that  their  last  access   time  is  not
recorded. This may lead  to significant performance improvements on
often accessed  frequently changing files  such as the  contents of
the /var/spool/news directory.


Linux has a  special mount option for file  systems called noatime
that can be  added to each line that addresses  one file system in
the /etc/fstab file.  If a file system has  been mounted with this
option, reading accesses to the  file system will no longer result
in an  update to  the atime information  associated with  the file
like  we  have explained  above.  The  importance  of the  noatime
setting  is that  it eliminates  the need  by the  system  to make
writes  to  the file  system  for  files  which are  simply  being
read. Since writes  can be somewhat expensive, this  can result in
measurable performance gains. Note that the write time information
to a file will continue to  be updated anytime the file is written
to. In  our example below, we  will set the noatime  option to our
/chroot file system.

source : http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec73.html
$lsattr yt-chanrip
------------------- yt-chanrip
$ls -l yt-chanrip
-rw-r--r-- 1 jeffrin jeffrin 230 Sep  2 18:19 yt-chanrip
$chattr +A yt-chanrip
$lsattr yt-chanrip
-------A----------- yt-chanrip
$ls -l yt-chanrip
-rw-r--r-- 1 jeffrin jeffrin 230 Sep  2 18:19 yt-chanrip
$echo "   " >> yt-chanrip
$lsattr yt-chanrip
-------A----------- yt-chanrip
$ls -l yt-chanrip
-rw-r--r-- 1 jeffrin jeffrin 234 Nov 29 22:30 yt-chanrip
$time

real	0m0.000s
user	0m0.000s
sys	0m0.000s
$chattr -A yt-chanrip
$echo "   " >> yt-chanrip
$ls -l yt-chanrip
-rw-r--r-- 1 jeffrin jeffrin 238 Nov 29 22:31 yt-chanrip
$

bubble sort testing… 0.00004 Ver — 1000 No.’s related

$time php bubble.php

real	0m0.846s
user	0m0.388s
sys	0m0.036s
$time php bubble.php

real	0m0.707s
user	0m0.368s
sys	0m0.032s
$time php bubble.php

real	0m0.718s
user	0m0.384s
sys	0m0.024s
$time php bubble.php

real	0m0.768s
user	0m0.372s
sys	0m0.036s
$time php bubble.php

real	0m0.556s
user	0m0.432s
sys	0m0.024s
$time php bubble.php

real	0m0.476s
user	0m0.372s
sys	0m0.040s
$time php bubble.php

real	0m0.438s
user	0m0.356s
sys	0m0.036s
$

block_dump enables block I/O debugging when set to a nonzero value

When this flag is set, Linux reports all disk read and write
operations that take place, and all block dirtyings done to
files. This makes it possible to debug why a disk needs to
spin up, and to increase battery life even more. The output of
block_dump is written to the kernel output, and it can be
retrieved using "dmesg". When you use block_dump and your kernel
logging level also includes kernel debugging messages, you
probably want to turn off klogd, otherwise the output of block_dump
will be logged, causing disk activity that is not normally there.

$cat /proc/sys/vm/block_dump
0
$echo 1 > /proc/sys/vm/block_dump
$cat /proc/sys/vm/block_dump
1
$