CentOS:

This is the second best OS after Linux Mint (for a newbie to Linux). It's interface is clean, and is a no frills OS. It's supported by RedHat, so it has same level of stability for OS that is expected of any large company. Best part is that it has lots of help available online. CentOS is my first choice of any Linux OS, It's screen doesn't look similar to windows, but otherwise it's very simple to use even for a person new to Linux. it's up on my laptop 24/7 for more than a year with no crashes !!

Versions:

There are many versions of CentOS Linux, as CentOS-6, CentOS-7 and CentOS-8 (as of Oct, 2021). CentOS 7 is very widely used, so I would advise to stick with CentOS 7. CentOS 8 is not going to be supported for long, so don't bother with CentOS 8. CentOs-8 is going to be followed by CentOS Stream, which is a new direction for CentOS. Until now, CentOS Linux were a rebuild of RHEL (Red Hat enterprise Linux), and so were called "downstream release" of RHEL. Starting with CentOS stream, it's going to be the other way round, where RHEL is going to be a downstream build of CentOS stream. So, your CentOS stream for laptop will be available with all latest/greatest features of RHEL, even before enterprise consumers see it.

However, for our purpose, CentOS 7 is going to suffiice for next 5 years without any issues, so we'll talk about stream in 2026.

Installating OS:

Download, install using these links:

https://www.tecmint.com/centos-7-installation/33333

steps:

1. Download CentOS ISO:

https://www.centos.org/download/

Download x86-64 bit as that's what almost all laptops using Intel/AMD chips are going to need.

2. Copy ISO files to USB drive:

You need linux already installed in order to cp the iso to usb from within linux. We don't use UUI to burn the iso as explained previously (it doesn't work anyway), so "cp" is the only way to get CentOS installed. So, in order to get CentOS installed, you need an already installed linux distro on some other laptop. Use cp cmd as explained under installation.

1A. Use cp cmd to copy to usb drive

sudo cp /home/aarav/Downloads/CentOS-7-x86_64-Everything-1804.iso /dev/sdb => Do not use /dev/sdb1. See in "Linux Installation section for details"

1B. Do NOT use dd to copy.

Follow instructions from above for running dd. run "lsblk" to get device name for usb. Run dd.

sudo dd if=/home/aarav/Downloads/CentOS-7-x86_64-Everything-1804.iso of=/dev/sdb status=progress oflag=sync

3. Reboot Windows:

Once copied, plug it in windows laptop and reboot it. Do not use UUI, as it gives error. You will be greeted with "Install centos-7" screen. Follow prompts as explained in link above from tecmint.

Once CentOS is installed, you have to reboot your computer once again. Now you will be greeted with "GRUB" bootloaded which will ask you to choose the OS you want to login with. One issue that I've seen with CentOS is that the grub boot menu may not have "windows boot" option in it at all. To fix this, do this:

  1. log into centos linux, open a terminal and type these 2 cmds: ( https://bytefreaks.net/gnulinux/ntfs-support-on-centos-7 )
  2. sudo yum --enablerepo=extras install epel-release
  3. sudo yum install ntfs-3g -y
  4. https://unix.stackexchange.com/questions/169787/windows-boot-option-is-missing-after-installing-centos-7-how-can-i-get-it-back .
    1.  type this cmd: sudo grub2-mkconfig > /dev/null => This will show windows 10 loader on /dev/sda1. Now run below 2 cmds:
      • sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.old
      • sudo grub2-mkconfig -o /boot/grub2/grub.cfg
  5. This will allow us to boot into windows

Few more helpful links:

https://wiki.centos.org/HowTos/InstallFromUSBkey

https://www.centos.org/forums/viewtopic.php?t=56144 => This not relevant as it's for UUI

 

Install desktop environment (DE):

Read about DE on "linux installation" to get some background. Here's a way to install different DE on CentOS. You may not need to do any of this if you are already satisfied with the default DE that is installed on your CentOS version.

sudo yum grouplist => lists all groups. It lists various DE as Cinnamon Desktop, MATE Desktop, Xfce, KDE Plasma Workspaces, GNOME Desktop, etc

sudo yum groupinfo "Cinnamon Desktop" => provides more info about this DE pkg. Do this for any pkg before installing it to make sure you installing what you think you want to install.

sudo yum groupinstall "Cinnamon Desktop" => this is cinnamon de used in Linux Mint.

sudo yum groupinstall "MATE Desktop" => this is continuation of GNOME2, which was much more liked. This is the default on CentOS 6.

sudo yum groupinstall "GNOME desktop" => This is GNOME3 DE, which is a big departure from GNOME2 and not liked by everyone. However, it's the default on CentOS 7. gnome classic and gnome shell are the 2 gnome de available here.

sudo yum groupinstall "KDE Plasma Workspaces" => This is the old conventional KDE desktop

sudo yum groupinstall Xfce => This is Xfce desktop. very light weight.

To remove a DE, we can do:

sudo yum groupremove "MATE Desktop" => uninstalls and removes all MATE DE related files.

 

Installing other software:

Here are links for few more pgms to install. Firefox and Skype are the important ones. Luckily they install flawlessly.

Install Firefox browser:

Firefox is installed by default. If not installed, type these cmds on Terminal.

firefox -version => shows version of firefox installed. If it's not installed or not latest one, run below cmds

sudo yum install firefox => installs firefox when nothing was installed.

sudo yum update firefox => This updates firefox to latest version if it was already installed.

firefox -version => Now check if it shows the latest version.

Install Skype:

Installing skype is very easy on CentOS. Type the 2 below cmds on terminal.

wget https://repo.skype.com/latest/skypeforlinux-64.rpm

sudo yum localinstall skypeforlinux-64.rpm

Now launch skype on clicking on Skype icon, or type "skypeforlinux" on terminal.

 

Issues and Solutions:

Sometimes some of the graphic applets will crash and not appear any more when you restart your system. As an example, the battery charge indicator icon (on the top right corner) may disappear. You just have to restart that applet, by finding out the exact name of the applet.

Network Manager applet crash: If your network manager applet (the one that shows the internet connection with bars) disappears, these are the steps to restore it. On the terminal, type the below cmds:

  • $ which nm-applet => returns something like this: /usr/bin/nm-applet
  • $ nm-applet => now run the applet. Doesn't show any o/p.
  • $ service NetworkManager restart => Now restart nm. It shows msg as below:
    • Redirecting to /bin/systemctl restart NetworkManager.service

This will restore the network manager applet back.

 

Property taxes in USA:

In most of the countries when you buy or own a home for your living, there's no tax that you pay to the government for owning in a house. However, in USA, you have to pay a property tax to local authorities for owning a home. If you live in a rental house, then the owner of that house pays the property tax. One noteworthy point is that  you have to pay property tax to the local authorities based on the market value of the house (that's true for most of the states. One notable exception is California, where taxes are charged on the purchase price of the house, and remain fixed as long as that property is not sold). Property taxes vary a lot from state to state, from city to city, and even within a city. On avg, it ranges from 1% to 3%.

Tax breaks for homeowners:

1. Homestead exemption: However one respite that homeowners get is that they get "Homestead exemption" which basically reduces the taxable amount of the property, thus reducing the taxes paid. However, this "Homestead exemption" is only available if you use that house as your primary residence for that calender year.

2. Federal tax benefit: Other tax break you get is from Uncle Sam. when you file your taxes with IRS. You can reduce your taxable income by deducting the amount of property taxes and interest paid on the house that you used as your primary residence. However, this deduction is only available if you itemize your deductions (i.e you don't claim standard deduction which is about $12K for year 2012). So, only if your mortgage interest and property taxes are over $12K, you see any benefit from it at all. It turns out that with interest rates of 2.5% and property tax of 2.5%, your house has to be over $250K, before you see even the first cent of any federal tax break. So, it's of no use for most of the people, who buy reasonably priced houses, within their means.

UPDATE 2019: Starting 2019, there are lot of changes in tax laws. Standard deduction is $24K, and amount of property tax that you can deduct is limited to $10K. Also, house prices have started going over $0.5M in most employable cities. However, the fact still remains, that most homeowners will still see very small tax benefit for owning a home, even more so with 2019 tax changes.

UPDATE 2022: Starting 2022, home prices are breaking all records, and now a whopping 10% of houses in USA are over $1M+. If you look at employable cities, and houses within reasonable commute distance, most of these houses are over $1M+. Most likely if you have a decent job (top 10% of income earners), your house has already breached $1M mark. In such cases, it may be worthwhile to look into itemizing tax deduction (as property tax of $10K+interest of $20K), will easily surpass std deduction of $24K.

Tax rates:

When you search for property tax rates for different states, you will find websites giving you a range of tax rates for different states. However, these rates are meaningless, as the rates vary a lot within the same state and same city. Before you purchase a house, find out the tax rates from neighbors, or ask them from where you can get the tax rates. More than likely, you can goto county website to get this info. OR just look up the address of the property you are interested in, and search for it's "property tax statement". These statements are public information and usually put on the "County property tax website". Sometimes they may not have all the taxes listed, as some taxes may be charged by some other government agency. USually it's complete, but be cautious andverify with current owner or nearby residents.

 

I'll talk specifically about Texas, as I'm in Texas. In Texas, for any given city, these are the taxes charged:

School district tax: A major portion of property tax goes into Public schools to fund them. So, as expected, School district tax are the biggest component of property tax. It's usually 1% or more of the value of your property. All schools that you see around you where 90% of the American kids go are public schools. Most of America attends public school, as the education is at par with private school, and you don't miss anything. There are few private schools in every city. However, private schools cost a lot of money, while public schools are free. Public schools are funded by tax dollars. Funding these public schools is the responsibility of state government, so each state government levies some kind of tax to fund these schools. Many states choose to use part of state income tax to fund these schools. States which don't have state income tax, instead use property tax to fund these schools. School district tax is part of that property tax that goes into funding schools (usually levied in states which don' have state income taxes)

Within a city, there can be several Independent School District (known as ISD). Each ISD is governed independently and can charge whatever tax it seems appropriate based on the funding it needs. Usually good ISD charge higher tax (since they maintain high quality of education through higher funding). Also, property prices are most directly influenced by rating of ISD. For top ISD, property prices are atleast 10%-20% higher than those with mediocre ISD. So, you get penalized twice with high rated ISD - one as higher property tax rate, and other as higher property price. The reason, why ISD are so important is because each house in USA is assigned a ISD. A kid with that particular home address can only attend the assigned school in that iSD. Though it's possible to send your kid to a different school, if you don't like that particular school, but it's not easy, and you have to justify it with concrete facts (not just because the school is low rated). Also, other important thing to note is that even though the particular ISD may be highly rated, but the particular school (elementary, middle and high school) that your kid will be going to, may still be pretty low rated. So, make sure that your particular schools are rated OK (rating of 8 or greater out of 10). If you are going to send your kid to private school, then ISD  or public schools should not matter for you. ISD are usually named after the name of the city.

County tax: County is similar to a district of India, where a city and its suburbs belong to one county. County tax rate is the same for every house in that county. Usually county tax is small at about 0.25% of the property value.

City tax: Each city charges it's own tax. City tax are the 2nd biggest component of property taxes after the school district taxes. City taxes vary widely from 1 city to other, but usually they are in the range of 0.5% to 1%. Most of the times, if you live in a big city, and your home address has the name of that city, you will be charged the city tax for that city. Sometimes, even though your address may indicate a particular city, your home still may not be part of that city from tax perspective. It might still be considered part of some suburb of that city depending on how the zoning and addr assignment was done. So, your city tax rate might be the suburb city tax rate. For ex, I might live in dallas city (and have a dallas addr), but might still get city tax charged by suburb of dallas, i.e plano city tax instead of dallas city tax. Usually newer cities have higher city tax rate than older established cities.

NOTE: even though your city tax may be from city A, your ISD may belong to city B. In such case, you get 2 tax statements, one from your city and one from your ISD (which might be in another city). There's no guarantee that ISD that your house is assigned to will be in the same city as your house. The reason for this is that population growth may be uneven across different areas, which may make some ISD overwhelmed, while some other may have lots of vacant slots. So, ISD reassign home addr amongst themselves to make sure no one is running out of space. ISDs for homes may change too in future.

Other thing to note is that sometimes there may be no city tax at all even though your addr may indicate a city name. This happens when that area is in the suburbs of city, and city doesn't provide services to that part of town (i.e not providing water lines, sewage lines, fire services, etc). In such cases, city doesn't charge a city tax. I've seen this happen to a lot of areas around Austin city. This may change in the future though, as city tries to being more and more areas under it's tax jurisdiction (as it's free money for the city).

College tax: There are lot of community colleges in cities, which are funded partially by College tax. This college tax is levied by the county, and is the same for a given county, so sometimes these are lumped together with county tax. This tax may not be present for all counties or cities. This tax is usually small at 0.1% or less.

Hospital tax: Many counties have Hospital tax too. These are the same for a given county, so sometimes they are lumped together with county tax. Again, this tax may not be present for all counties or cities. This tax is usually small at 0.1% or less.

MUD tax: Sometimes, a neighborhood is not part of any city for tax purpose. Some of these neighborhood form MUD (Municipal Utility District) which provide water/waste water services (since city may not provide these services for whatever reasons). MUD basically raises bond money for setting up water/waste-water infrastructure, so that the neighborhood gets these municipal services. The MUD is setup as non-profit only for that neighborhood, and taxes properties at a very high rate (sometimes as high as 1%). This MUD tax is supposed to go down over time (as the bpond is paid off), but very rarely happens so. Remember that you still have to pay water and waster bills every month for water that you use, just like you would pay anywhere the city provides these facilities. To top it off, these water/waste-water bills are also lot higher. These MUD are very common in Texas, so be very careful before you purchase a property with MUD taxes (MUD taxes are a poison). Some newer properties do away with MUD completely by setting up private septic system for waste-water drainage, which is lot cheaper. They get water from some water utility, not sure how? FIXME

Other taxes: there might be myriad of misc taxes on top of all other taxes. However, these other taxes are usually small. Biggest taxes are school, city and county taxes, as explained above, accounting for 80% of the property taxes.

 


 

Sample Taxes for cities around State of Texas:

Below are taxes that I pulled from my tax statements for various cities. These will give you an idea of how much property tax to pay when you buy a house in Texas. Usually you will pay anywhere from 2% to 4% of the current value of the property as property tax. Since many houses in Texas are approaching $1M mark as of 2022, be prepared to pay $15K-$30K just in property taxes every year. They are based on current price, so if prices keep appreciating, you will keep on paying more and more.

As of 2020, cities and counties have started reducing their tax rates by the same amount that houses appreciate by, so that your tax bill remains the same. As of 2024, tax rates for most of the houses in Texas is close to 2%, rather than 3%.

In Travis county (in the state of Texas), below is a sample of diff tax rates charged. As you can see, it varies a lot amongst counties, cities, ISD, etc. Link => https://www.realestateinaustin.com/buyers/travis-county-property-tax-rates-category/

1. Dallas, TX (in city): property tax rate breakdown (for year 2012):

School tax: 1.29% (for Dallas ISD)

City tax: 0.8% (For house in dallas city only, other cties in suburbs have different rates)

Dallas County tax: 0.25%

Hospital tax: 0.27%

College tax: 0.1% (for DCCC = dallas county community college)

So, total property tax for Dallas, TX  is: 1.29 + 0.8 + 0.25 + 0.27 + 0.1 = 2.71%

However, as an homeowner you get "Homestead exemption". So, with homestead exemption, these are the rates (NOTE: I show lower rates with homestead exemption. In reality, rates remain the same, your taxable value goes down by 20%, resulting in lower effective rate):

School tax: 1.16% (for Dallas ISD there's 10% discount). Also, Dallas ISD lowers your taxable property value by $15K, on top of this 10% discount.

City tax: 0.64% (For dallas city, there's 20% discount)

Dallas County tax: 0.20% (For dallas county, there's 20% discount)

Hospital tax: 0.22% (20% discount)

College tax: 0.08% (20% discount)

So, total property tax for Dallas, TX with homestead exemption is: 1.16 + 0.64 + 0.2 + 0.22 + 0.08 = 2.3%. On top of this, you also get $15K knocked off from your property price for School tax, so that further lowers your tax rate a little (for a house of $250K, that implies reduction of 0.07%, so effective tax rate = 2.23%).

2. Austin, TX (in City): property tax rate breakdown (for year 2019):

School tax: 1.19% (for Austin ISD)

City tax: 0.44% (For house in Austin city only, other cties in suburbs have different rates)

Travis County tax: 0.35% (austin is in Travis county)

Travis Central Health tax (aka Hospital tax): 0.1%

Austin Community college tax (aka College tax): 0.1% (for ACC = Austin community college)

So, total property tax for Austin, TX  is: 1.19 + 0.44 + 0.35 + 0.1 + 0.1 = 2.19%

However, as an homeowner you get "Homestead exemption". For travis county, homestead exemption lowers the taxable value of property resulting in effective lower rates. So, with homestead exemption, these are the rates:

School tax: 1.19% (for Austin ISD there's $25K exemption on property price, no reduction on tax rate).

City tax: 0.39% (For Austin city, there's 10% discount)

Travis County tax: 0.28% (For Travis county, there's 20% discount)

Hospital tax: 0.08% (20% discount)

College tax: 0.10% (For ACC, there's $5K exemption on property price, no reduction on tax rate)

So, total property tax for Austin, TX with homestead exemption is: 1.19 + 0.39 + 0.28 + 0.08 + 0.10 = 2.04%. On top of this, you also get $25K knocked off from your property price for School tax, so that further lowers your tax rate a little (for a house of $500K, that implies reduction of 0.06%, so effective tax rate = 1.98%).

3. Austin, TX (outside city): property tax rate breakdown (for year 2019): This is for a property having an address in Austin but not considered in city limits for tax purpose. So, there is no city tax, but MUD tax. This address is in Eanes ISD (NOT Austin ISD), so School tax is for Eanes ISD (Eanes ISd is top rated ISD in Austin)

School tax: 1.2% (for Eanes ISD)

City tax: 0% (For this house, there is no city tax even though address is in Austin)

Travis County tax: 0.35% (austin is in Travis county)

Travis Central Health tax (aka Hospital tax): 0.1%

Travis County ESD #10 tax: 0.1% (this is for addresses that are not considered part of City of Austin)

Austin Community college tax (aka College tax): 0% (No ACC tax as address is not considered part of Austin)

MUD tax: 0.6% (This MUD tax is just because that particular community developer formed a MUD. Some developers put their own septic system, and thus never have MUD taxes)

So, total property tax for this property in Austin, TX  is: 1.20 + 0.35 + 0.1 + 0.1 + 0.6 = 2.35% (so absence of city tax was more or less compensated by MUD tax). You can find many houses in Eanes ISD, which do not have MUD taxes, so their property taxes are closer to 1.75%. Some MUD taxes also also lower, like 0.3% or so. Again, you get homestead exemption, which may lower your rates further.

 

 

This is a program written in C to calculate how long you can live off a certain amount of money that you have saved.

retire.c => It needs an input that speciifes the number of years you want to see the chart for. If you do not provide this number, the pgm errors out. Choose 100 as a starting number as 100 years is what we care about.

  • Principal and Expense: Within the pgm, you can adjust the initial principal amount (I[0]) you want to start with (leave it at 100 currency units), the initial expense amount (E[0]) you want to start with (this can be adjusted based on how much of your savings go into paying all your bills for a year, 5 currency units is a reasonable number, implying you withdraw 5% out of your savings every year).
  • Rate of Income/Expense: Next you can adjust the rate at which your principal grows (RateI, i.e rate of return on your savings) and the rate at which your expenses grow (RateE, i.e rate of inflation). If your money is invested in stock market, then you may choose rateI to be 5%, and rateE to be 5% too. Rational for rateI is that stock market returns would never be lower than nominal GDP growth, as that's the amount of money pumped into the system. On top of that, inflation rate would never exceed stock market return, as stock market is 90% owned by top 10% of the people, so bottom 90% will never make enough money via any investment to drive up inflation rate.

The pgm stops and prints the year when your expenses exceed your savings, basically meaning you will go bankrupt in year "X". If your rate of return on investment is much greater than rate of inflation, then you will never go bankrupt. This basically means you have not only freed yourself from slavery, but all your future generations to come. This is what we all want to achieve !!


 

Generate Data:

Pgm: retire.c

#include <stdio.h>
//#define NUM 100
main (int arg_cnt, char *arg_option[]) {
  int NUM,NUM1;
  //NUM = (int) arg_option[1]; //int cast of ascii returns wrong values
  NUM = atoi (arg_option[1]);
  NUM1 = (int)"";
  //double I[NUM], E[NUM]; //I[n]=Principal in year n, E[n]=Expense in year n
  double I[1000], E[1000]; //array size can't be dynamic, so fixing them at large values
  int yr=0;
  float RateI, RateE; //RateI=rate at which assets increase, RateE=Inflation rate
  E[0]=1;    //start with expense of 1 currency in 1st year
  I[0]=100;  //start with principal of 100 currency in 1st year
  RateI=0.06; //expected income growth, 0.06=6% return on principal every year.change this to evaluate different cases
  RateE=0.05; //expected expense growth,0.05=5% inflation rate, change this to evaluate different cases
  FILE *fp;
  int cnt;
  for(cnt=0;cnt<arg_cnt;cnt++) {
    printf("CNT=%d OPTION=%s NUM=%d \n", cnt,arg_option[cnt],NUM1);
  }

  //write data in file, nth year income and expense
  fp = fopen("/home/kagrawal/scripts/retire.data", "w+");
  if (fp == NULL)
  {
    printf("Error opening file!\n");
    exit(-1);
  }
  printf("yr = %d, Income = %e Expense = %e \n",yr, I[yr], E[yr]);
  fprintf(fp,"%d %e %e \n",yr, I[yr], E[yr]);
  for(yr=1;yr<=NUM;yr++) {
    E[yr] = E[yr-1]*(1+RateE); //E[n]=expense for year n
    I[yr] = I[yr-1]*(1+RateI) - E[yr]; //I[n]=prinicpal left at end of year n after adding income and subtracting expenses
    printf("yr = %d, Income = %e Expense = %e \n",yr, I[yr], E[yr]);
    fprintf(fp,"%d %e %e \n",yr, I[yr], E[yr]);
    if (I[yr] <= E[yr]) break; //If principal at end of year is less than the expenses for that year, then bankrupt !!
  }
  fclose(fp);
}

Compile:prompt> gcc retire.c => compiles retire.c and generates file a.out

Run: prompt> a.out 200 => This runs the pgm with total number of years set to 200. If bankruptcy happens before year=200, then pgm stops at that year.


 

Print Data:

retire.data => Next to plot the data, we dump out a file "retire.data", which can be used to plot data in gnuplot. It has 3 columns: year X, Total money left at end of year X, Total expenses for year X. This allows us to see how are net savings growing compared to our expenses.

Bring up gnuplot on any linux m/c, by typing "gnuplot" on the terminal.

prompt> gnuplot

gnuplot> plot retire.data => this plots data in points, not as lines

gnuplot> plot for [col=2:3] "retire.data" using col with lines => here we plot data for both col2 and col3 from retire.data using lines, so it's easier to see.

Sample output: In all exapmles below, I chose 5% inflation, as GDP growth (money creation) happens at rate of 5%/year, which I consider as inflation. The inflation number govt reports is a subset of real inflation, and doesn't apply in real life.

  1. 1. If we choose E[0]=5, I[0]=100, RateI=0.06 (i.e 6% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we go bankrupt in 22 years
  2. 2. If we choose E[0]=5, I[0]=100, RateI=0.10 (i.e 10% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we go bankrupt in 65 years
  3. 3. If we choose E[0]=5, I[0]=100, RateI=0.12 (i.e 12% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we never go bankrupt. Just an extra 2% return allowed us to achieve this. Since 12% is not a guaranteed return in US stock market, let's stick with 8% return, and see how much our expenses need to be as percentage of our savings, so that we can live forever.
  4. 4. If we choose E[0]=4, I[0]=100, RateI=0.08 (i.e 8% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we go bankrupt in 44 years.
  5. 5. If we choose E[0]=2, I[0]=100, RateI=0.08 (i.e 8% return on investment) and RateE=0.05 (i.e 5% inflation), then chart shows that we never go bankrupt. Just starting with a smaller expense base, allowed us to achieve this.

So, our target should be live off just the dividend returns of our investment. Since dividend returns are somewhere close to 2%, our expenses should be 2% of our net amount saved. At that point we can retire.

 


 

Conclusion:

The above plot shows that if we amass enough money where we ca live off dividends then we will never run out of money. Since dividends are about 2%, if we our expenses are < 2% of our wealth, we can be free from slavery. The assumption here is that inflation will never run higher than the stock market return. Because in worst case scenario, when everyone in US is invested in stock market, stock market will be the inflation driver. Or inflation rate will at most be stock market return.

Year 2010: If you amass $5M in savings, and invest all of that in USA stock market, 1.5% dividend will give you $75K/year. Federal taxes will take at most $10K (15%) out of this. Assuming you are able to live off $65K/yr as of 2010, you will be able to survive rest of your life without running out of money. Not only you, but your future generations too can be free of slavery.

So, cost to free one person from slavery in USA is $5M as of 2010. It goes up every year by the % amount the US stock market goes up by.

If you do similar maths for India, you will see that the cost to free one person from slavery in India is $1.5M (since cost of living in India is lot lower, $25K/year will easily suffice. Although dividends at 1% are lower than those in USA, but difference b/w stock market return and inflation is higher).

Year 2025: USA S&P500 index has gone up by 5X, while Nasdaq has gone up by > 10X. So, $5M from 2010 would have grown to $50M as of 2025. If you have $10M in savings as of 2025, and invest all of that in USA stock market, 1% dividend will give you $100K/year.Assuming 15% tax rate you will net $85K. You should be able to survive off $85K/year in 2025, if you were able to survive off $65K/year in 2010. So, you may still be free of slavery.

 


 

Filesystems, Partitions and devices:

When you get any storage medium, whether it's usb flash drive, or hard disk or cdrom, they all store bits as 1 or 0 in every location of the device. We need to have a way so that we can identify which group of bits are together to form a picture or a song or a text file, etc. This is where the File system (FS) comes into picture. It establishes a particular way of storing data to retrieve it later on.

Very good intro here: https://www.tldp.org/LDP/sag/html/disk-usage.html

HARD DISK:

Each device is rep by separate device file. Hard disk interface are either IDE hard disk or SCSI hard disk. SCSI was the earliest hard disk, followed by IDE. IDE were parallel ATA or PATA i/f (parallel AT attachment). These have largely been replaced by SATA (or serial ATA) i/f since it's intro in 2000, due to lower pin count, reduced complexity and higher speeds. SATA rev 1 had max transfer speed of 1.5Gbits/sec, while rev2 had 3.0Gbits/sec. Latest rev3 has transfer speed of 6.0Gbits/sec. SATA pin i/f consists of 7 data pins and 15 power pins in 2 set of pins. Out of 7 data pins, 3 are gnd pins, and remaining 4 are differential tx/rx pins (A+/A- for transmit, B+/B- for receive). differential signaling reduces noise at high speed transmissions. 15 power pins have 3.3V/5.0V/12.0V power supply pins along with ground pin. Smaller SATA devices combine data pins and power pins in the same set, with only 5V supply lines provided to reduce pin count.

Now we have SSD Hard disk, which have very different i/f, and much faster speeds.

Disk partition:

Each HD can be divided into several partitions, which allows different partitions of the same disk to behave as separate hard disks. For all practical purposes, partitions can be thought s separate hard disk. So, we'll talk at partition level.

First sector of each HD (NOT partition) contains the partitioning info. This 1st sector is called master boot sector.

Very good intro here: https://www.minitool.com/lib/boot-sector.html

some more info here: https://www.bydavy.com/2012/01/lets-decrypt-a-master-boot-record/

Boot sector (or Master Boot Sector or Master Boot record (MBR) is more common term) usually refers to the first sector of hard disk. It's used for loading and transferring processor control right to operating system. After power up, boot process starts from ROM on motherboard, and then control is transferred to hard disk. This boot sector is the very first location read from hard disk.

MBR contains a small program that reads the partition table, checks which partition is active (that is, marked bootable), and reads the first sector of that partition, the partition's boot sector (the MBR is also a boot sector, but it has a special status and therefore a special name). This boot sector contains another small program that reads the first part of the operating system stored on that partition (assuming it is bootable), and then starts it. Control is transferred to OS at this point.

MBR is all contained in 1st sector of hard disk (cyl 0, head 0 sector 1). All sectors are 512 bytes.

The original partitioning scheme for PC hard disks allowed only four partitions. This quickly turned out to be too little in real life. to overcome this, primary partition was allowed to be subdivided further into more partitions, which were called logical partitions. Such a primary partition was called extended partition. First sector of each primary partition as well that of the disk is called boot sector, and contains boot pgm.

Each partition and extended partition has its own device file. The naming convention for these files is that a partition's number is appended after the name of the whole disk, with the convention that 1-4 are primary partitions (regardless of how many primary partitions there are) and number greater than 5 are logical partitions (regardless of within which primary partition they reside). Linux FS uses block, instead of sectors, where each block size=1024 bytes=2 sectors.

NOTE: size conversion are 1024 bytes = 1KB, 1024 KB=1MB, 1024MB=1GB. However, almost all linux cmds approximate 1024 with 1000 for easy calculation, so sizes may differ b/w diff cmds. So, 1GB is treated as 1000MB, and 1MB is treated as 1000KB, and 1KB is treated as 1000 bytes, even though 1 block = 2 sectors = 1024 bytes. So, this results in an error of about 10% compared to exact calculation.

Naming convention:

In Windows, each partition is assigned a "drive letter name" as C:/ (called as C drive), etc. In Linux, everything is treated as a file. So, all devices and partitions are essentially files. All devices are given file names in the form /dev/xxyN, where xx=hd (for IDE disks) and sd (for SCSI disks), y=a,b,c etc indicating 1st disk, 2nd disk, etc, while N=partition number on that disk. So, /dev/sda => refers to 1st disk, while /dev/sda2 refers to 2nd partition on 1st disk. We use "sd" instead of "hd" even though hard disks are now all SATA IDE (probably due to legacy)

fdisk: cmd "fdisk" provides all info about devices. It's used for disk partition mgmt/info too.

prompt> sudo fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors => Here hard disk is 128GB in size. It's dual boot laptop, which has Windows and Linux installed. If we treat each sector as 1024 bytes, and be exact in our calculations, then 128035676160 bytes = 250069680 sectors = 28035676160/1024KB = 125034840KB = 125034840/1024MB = 122104.3 MB = 122104.3/1024 GB = 119.24GB. However, hard disk is reported as 128GB, which uses multiplication of 1000 instead of 1024, so 128035676160 bytes = 128.03 GB.
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: 0x948dbc73

   Device Boot      Start         End                    Blocks        Id  System
/dev/sda1   *        2048     1026047                512000     7   HPFS/NTFS/exFAT => primary partition is from sda1 to sda4. sda1 size=512K blocks*1024/1000KB=524.3MB (assuming factors of 1000 instead of 1024). This is Windows system boot partition. It has boot, EFI dir in it.
/dev/sda2         1026048   166098943      82536448     7   HPFS/NTFS/exFAT => size=82536K blocks* 1024/1000=84516MB=84.5GB. This is Windows system partition, where all user pgm, etc are kept. This is the partition we are in when we log into our windows m/c.
/dev/sda3       248018944   250066943      1024000   27  Hidden NTFS WinRE => sda3 size=1024K blocks*1024/1000=1048.6MB=1.05GB. This is Windows Recovery partition.
/dev/sda4       166098944   248018943    40960000    5   Extended => 4th primary partition is an extended partition and contains 2 logical partitions, sda5 and sda6. size=40960K blocks *1024/1000 = 41.94GB. This extended partition is the one where we have Linux installed. It contains Linux OS (OS+user area) and memory swap space
/dev/sda5       166100992   168198143      1048576   83  Linux => This is first logical partition of extended partition. size=1048K blocks*1024/1000= 1073MB=1.07GB
/dev/sda6       168200192   248018943    39909376   8e  Linux LVM => 2nd logical parition. size=39909K blocks*1024/1000 = 40866MB=40.86GB. This contains centos-root and centos-swap spaces as indicated below. Total blocks=35807,232+4096,000=39903232 blocks, pretty close to those indicated above

Partition table entries are not in disk order => NOTE: sda1, sda2, sda4 and sda3 occupy continuous sectors w/o any missing sectors in b/w them.

Disk /dev/mapper/centos-root: 36.7 GB, 36666605568 bytes, 71614464 sectors => blocks=35807232. so, size=36.7GB (due to rounding of 1000)
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 /dev/mapper/centos-swap: 4194 MB, 4194304000 bytes, 8192000 sectors => blocks=4096000. so, size=4194MB (due to rounding of 1000). Note: I chose 4GB swap space during installation of CentOS, which equated to 4*1024*1024KB=4194304KB=4194304000 bytes (where 1GB=1024MB, 1MB=1024KB, 1KB=1000 bytes. So, installation process calculates GB differently than the one calculated by Linux OS)
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

parted: parted is another cmd for mgmt/info of disk partitions. It is most commonly used for partitioning of hard disks.

prompt> sudo parted -l => this also uses rounding of 1000, same as that of fdisk
Model: ATA SAMSUNG MZ7TD128 (scsi)
Disk /dev/sda: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  525MB   524MB   primary   ntfs         boot
 2      525MB   85.0GB  84.5GB  primary   ntfs
 4      85.0GB  127GB   41.9GB  extended
 5      85.0GB  86.1GB  1074MB  logical   xfs                     => This shows logical partition 5 has 1 GB size, same as what fdisk showed.
 6      86.1GB  127GB   40.9GB  logical                lvm        =>  Here, logical partition 6 shows 40.9GB size, same as what fdisk showed
 3      127GB   128GB   1049MB  primary   ntfs         diag


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4194MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system     Flags
 1      0.00B  4194MB  4194MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 36.7GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  36.7GB  36.7GB  xfs

------

 

dd: To copy contents of any device, we can use "dd" cmd. dd copies raw bytes from specified location, and has nothing to do with FS.

ex: sudo dd if=/home/file1.img of=/dev/sdb status=progress oflag=sync bs=4M => this copies file1.img from i/p file to of file /dev/sdb. Here device to be written to is the device name and not the prtition name, as we want to write the file to the device, which will create multiple partitions as needed. If we arite the file to a particular partition then booting from this new device may not work, as the boot may require particular info in main partition to boot up. option status shows status progress (otherwise no status is shown, so the device will seem stuck as it takes couple of minutes for large files to be copied), block size (bs) to transfer is set to 4M (default is 512  Bytes which will take a long time to transfer multi GB file). sudo is used since usually this cmd requires root privilege

To view contents of MBR, type below 2 cmds in a terminal:

prompt> dd if=/dev/sda of=mbr.bin bs=512 count=1 => dd cmd copies contents of any device byte by byte. if=input file, of=output file, bs=size in bytes to rd/wrt at a time, count=num of input blocks to copy. So, this cmd copies 512 bytes from 1st sector of /dev/sda device (usually hard disk) to file mbr.bin.

prompt> od -xa mbr.bin" => od dumps contents of file in octal or other formats. -x => imples hex format, -a implies print ascii char for each byte. On my hard disk, it lists below content (each line has 16 bytes):

000000    63eb    d090    00bc    8e7c    8ec0    bed8    7c00    00bf => The following 446 bytes taken up by master boot program of hard disk is from 0x0000 hex to 0x01BD hex. 2 bytes are written as pair where MSB byte is written before LSB byte, so within a pair, order is reversed, i.e 63eb has 1st byte as eb, and 2nd byte as 63, d090 has 1st byte as 90, and 2nd byte as d0, and so on ... This code contains the bootstrap loader code, which is either GRUB or ...? FIXME?
         k   c dle   P   < nul   |  so   @  so   X   > nul   |   ? nul
000010    b906    0200    f3fc    50a4    1c68    cb06    b9fb    0004
       ack   9 nul stx   |   s   $   P   h  fs ack   K   {   9 eot nul
000020    bebd    8007    007e    7c00    0f0b    0e85    8301    10c5
         =   > bel nul   ~ nul nul   |  vt  si enq  so soh etx   E dle
000030    f1e2    18cd    5688    5500    46c6    0511    46c6    0010
         b   q   M can  bs   V nul   U   F   F dc1 enq   F   F dle nul
000040    41b4    aabb    cd55    5d13    0f72    fb81    aa55    0975
         4   A   ;   *   U   M dc3   ]   r  si soh   {   U   *   u  ht
000050    c1f7    0001    0374    46fe    6610    8000    0001    0000
         w   A soh nul   t etx   ~   F dle   f nul nul soh nul nul nul
000060    0000    0000    faff    9090    c2f6    7480    f605    70c2
       nul nul nul nul del   z dle dle   v   B nul   t enq   v   B   p
000070    0274    80b2    79ea    007c    3100    8ec0    8ed8    bcd0
         t stx   2 nul   j   y   | nul nul   1   @  so   X  so   P   <
000080    2000    a0fb    7c64    ff3c    0274    c288    be52    7c05
       nul  sp   {  sp   d   |   < del   t stx  bs   B   R   > enq   |
000090    41b4    aabb    cd55    5a13    7252    813d    55fb    75aa
         4   A   ;   *   U   M dc3   Z   R   r   = soh   {   U   *   u
0000a0    8337    01e1    3274    c031    4489    4004    4488    89ff
         7 etx   a soh   t   2   1   @  ht   D eot   @  bs   D del  ht
0000b0    0244    04c7    0010    8b66    5c1e    667c    5c89    6608
         D stx   G eot dle nul   f  vt  rs   \   |   f  ht   \  bs   f
0000c0    1e8b    7c60    8966    0c5c    44c7    0006    b470    cd42
        vt  rs   `   |   f  ht   \  ff   G   D ack nul   p   4   B   M
0000d0    7213    bb05    7000    76eb    08b4    13cd    0d73    845a
       dc3   r enq   ; nul   p   k   v   4  bs   M dc3   s  cr   Z eot
0000e0    0fd2    de83    be00    7d85    82e9    6600    b60f    88c6
         R  si etx   ^ nul   > enq   }   i stx nul   f  si   6   F  bs
0000f0    ff64    6640    4489    0f04    d1b6    e2c1    8802    88e8
         d del   @   f  ht   D eot  si   6   Q   A   b stx  bs   h  bs
000100    40f4    4489    0f08    c2b6    e8c0    6602    0489    a166
         t   @  ht   D  bs  si   6   B   @   h stx   f  ht eot   f   !

000110    7c60    0966    75c0    664e    5ca1    667c    d231    f766
         `   |   f  ht   @   u   N   f   !   \   |   f   1   R   f   w
000120    8834    31d1    66d2    74f7    3b04    0844    377d    c1fe
         4  bs   Q   1   R   f   w   t eot   ;   D  bs   }   7   ~   A
000130    c588    c030    e8c1    0802    88c1    5ad0    c688    00bb
        bs   E   0   @   A   h stx  bs   A  bs   P   Z  bs   F   ; nul
000140    8e70    31c3    b8db    0201    13cd    1e72    c38c    1e60
         p  so   C   1   [   8 soh stx   M dc3   r  rs  ff   C   `  rs
000150    00b9    8e01    31db    bff6    8000    c68e    f3fc    1fa5
         9 nul soh  so   [   1   v   ? nul nul  so   F   |   s   %  us
000160    ff61    5a26    be7c    7d80    03eb    8fbe    e87d    0034
         a del   &   Z   |   > nul   }   k etx   >  si   }   h   4 nul
000170    94be    e87d    002e    18cd    feeb    5247    4255    0020
         > dc4   }   h   . nul   M can   k   ~   G   R   U   B  sp nul                      => NOTE: we see text "GRUB" here meaning it has GRUB BootLoader
000180    6547    6d6f    4800    7261    2064    6944    6b73    5200
         G   e   o   m nul   H   a   r   d  sp   D   i   s   k nul   R                          => NOTE: we see text "geom Hard Disk Read Error". This is for printing Error by the bootloader.
000190    6165    0064    4520    7272    726f    0a0d    bb00    0001
         e   a   d nul  sp   E   r   r   o   r  cr  nl nul   ; soh nul
0001a0    0eb4    10cd    3cac    7500    c3f4    0000    0000    0000 =>
         4  so   M dle   ,   < nul   u   t   C nul nul nul nul nul nul
0001b0    0000    0000    0000    0000    bc73    948d    0000   => Master boot pgm code ends here at 0x01bd (total 446 bytes), last 6 bytes are supposed to be 4 bytes of Disk Id/signature (optional) followed by null "0000" (order is incorrectly mentioned in the link above). Here disk signature is "948d bc73" from MSB to LSB, which is same as what was reported by fdisk cmd above = 0x948dbc73

0001be  2080 => These 16 bytes are partition 1. 1st byte is status. It's 80 for bootable partition and 00 for non bootable one. Here, this partition is bootable as status=80, other 3 are non bootable. It's bootable as this is the boot/EFI partition from windows.
0001c0    0021    dd07    3f1e   0800    0000    a000    000f   => 5th byte is partition type/Id which indicates the type of parition and hence the FS. It is for use by OS. It's not standardized, and Linux OS just ignores it. Here it's 0x07, which is Microsoft/IBM FS (NTFS, exFAT, etc). size=524MB, FS=NTFS.

0001ce    dd00 => These 16 bytes are partition 2.
0001d0    3f1f    fe07    ffff    a800    000f    d000    09d6  => Partition type = 0x07. FS=NTFS

0001de    fe00 => These 16 bytes are partition 3.
0001e0    ffff    fe27    ffff    7800    0ec8    4000    001f   => Partition type = 0x27, which is Winodows Recovery partition. size=1GB, FS=NTFS,

0001ee    fe00 => These 16 bytes are partition 4.
0001f0    ffff    fe05    ffff    7800    09e6    0000    04e2  => Partition type = 0x05, which is extended partition type. This has 2 logical partitons, as explained in fdisk cmd above

0001fe   aa55 => these last 2 bytes of 512 bytes "55AA" marks end of MBR. It is used as a signature for MBR. 0x55 is 511th byte(addr 0x01fe), while 0xAA is 512th byte (addr 0x01ff)

After the master boot sector, the next sectors contain the actual partitions. Parttion Typpe/Id is specified for each partition, in the MBR. Value in this specifies the FS, and originated from IBM/Microsoft in early days of computer. However, it's ignored by Linux.

file: file cmd figures out the type of a file, since it's hard for a user in linux to know file type (since extensions have no meaning in linux)

file mbr.bin => displays contents of file that was dumped from MBR above

mbr.bin: x86 boot sector; => This says that this file is a boot sector file. It then knows how to read partition info from remaining bytes

partition 1: ID=0x7, active, starthead 32, startsector 2048, 1024000 sectors; => 1000K*0.5KB/sector=500MB

partition 2: ID=0x7, starthead 221, startsector 1026048, 165072896 sectors; => 78.7GB

partition 3: ID=0x27, starthead 254, startsector 248018944, 2048000 sectors; => 1GB. This is windows recovery partition.

partition 4: ID=0x5, starthead 254, startsector 166098944, 81920000 sectors,=> 80000K*0.5KB=40000MB=40GB

code offset 0x63, OEM-ID "      м", Bytes/sector 190, sectors/cluster 124, reserved sectors 191, FATs 6, root entries 185, sectors 64514 (volumes <=32 MB) , Media descriptor 0xf3, sectors/FAT 20644, heads 6, hidden sectors 309755, sectors 2147991229 (volumes > 32 MB) , physical drive 0x7e, dos < 4.0 BootSector (0x0)

Now, we can repeat same exercise for external ssd hard disk connected via usb.

prompt> dd if=/dev/sdb of=ssd.bin bs=512 count=1=> assuming external hard disk is on /dev/sdb

prompt> hexdump ssd.bin => This is hexdump of 1st sector of this external ssd hard disk connected via usb. It shows 1st sector as boot sector, and shows the only partition it has (partition 1)

0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
00001b0 0000 0000 0000 0000 9c01 078d 0000=> since there is no bootstrap code here, most entries are 0. Here disk signature is "078d 9c01" from MSB to LSB

0001be 2000 => these 16 bytes are partition 1. 1st byte=00 => it's non-bootable partition
00001c0 0021 fe07 ffff 0800 0000 9da7 773b

0001ce 0000 => partition 2 to partition 4 are all 0 => no more partitions
00001d0 0000 0000 0000 0000 0000 0000 0000 0000
*
00001f0 0000 0000 0000 0000 0000 0000 0000 aa55 => aa55 indicates end of MBR

file ssd.bin => shows file type of MBR file from external hard disk

ssd.bin: x86 boot sector; partition 1: ID=0x7, starthead 32, startsector 2048, 2000395687 sectors, extended partition table (last)\011, code offset 0x0 => size=2000395687*0.5KB/sector=1,000,197,843.5KB = 1TB

Filesystems (FS): It's a very important concept especially for linux, as everything in Linux is treated as  file. A FS is the methods and data structures that an OS uses to keep track of files on a disk or partition; that is, the way the files are organized on the disk. FS are stored on partition of disk, and only 1 kind of FS is allowed on a particular partition. Thus, for ex, ext3 FS might be stored on partition 1 of HDD.

Unix filesystems are arranged as a big tree, with tree hier rooted at "/" or root.These files can be spread out over several devices and they can be remote or local file system. Linux supports numerous file system types.


These are the most common disk file systems (file systems suited for use on disk storage media).
1. Ext (extended FS): File systems started with Minix file systems, then was enhanced to Ext in 1992 (solved max parttition size problem). Newer versions came later as Ext2, Ext3, Ext4.
2. Ext2: enhanced version of Ext which supported inode modification, timestamps, etc.
3. Ext3: most popular enhanced version of ext2 supporting journalism. Std linux FS on most dist . Can support 2TB max file size, and 16TB max Partition size.
4. Ext4: Can support 16TB max file size, and 1EB max Partition size. Not supported on windows.
5. FAT32 (FAT=File Allocation System, proprietry windows FS): FAT was originally designed in 1970 for floppy drives. limits file size to 4.2GB, and parttition size to 2TB. Windows limits parttition size to 32GB. It's the only one that was supported on Windows systems staring from Windows95 in 1995. FAT32 is very popular on USB flash drives, where they come formatted with FAT32 FS, FAT32 FS is supported across all OS and all devices. However due to file size limitation, new devices come commonly formatted with NTFS.
6. NTFS (Windows New Tech (NT) FS, improved FAT32 proprietry windows FS): File size limit is 2TB, while partition size limit is 256TB. Most widely used as an alternative to FAT32, since NTFS-3G driver is provided with most linux dist for rd/wrt. Default for Ubuntu, Windows NT(1993), Windows 2000(XP onwards). partition tables on MBR (Master Boot Record) disks only support max partition size of 2TB, GPT volumes used to get to larger partition size.

7. exFAT: known as extended FAT, it was introduced in 2006 for USB flash drives and memory SD cards. It's used in places where NTFS is not feasible due to data structure overhead, but file sizes > 4GB are needed, so FAT32 is not possible. exFAT is now standard FS for SDXC cards > 32GB size. Although drivers for this are included in Linix Kernel 5.4, most linux distro don't have drivers for exFAT.
Misc:
7. ISO9660, Universal disc format(UDF) => optical disc file system for use in CD/DVD)
8. IBM DB2: database based file system. Instead of hier structured mgmt, files here are identified by rich metadata as type, topic, etc.
9. NFS :network file system in which one machine (client) requires access to data stored on another machine (NFS server). It's an open std, and was developed by SUN in 1984. server runs nfsd daemon on some port, client connects to that port and requests for data, which is passed to client by nfsd.

Making FS: Before a partition or disk can be used as a filesystem, it needs to be initialized, and the bookkeeping data structures need to be written to the disk. This process is called making a filesystem. Various data structures such as superblock, inode , data block, directory block , and indirection block are kept in various sectors of partition to allow Linux OS to retrieve files.

mkfs: This cmd used as a front end i/f for making various FS. Most linux distro use mkfs wrapper which calls mke2fs cmd, which does the real FS creation.

If we type mkfs and hit tab, we see all supported FS. i.e mkfs.ext2 creates ext2 FS, similarly for others. Their option differ slightly, so read doc for each of them when using.

ex: mkfs.ext2 -c /dev/fd0H1440 => -c searches for bad blocks, and initializes the bad block list.

ext2 FS has following structure: https://www.nongnu.org/ext2-doc/ext2.html

The best way to learn making a FS, and see what contents get created in it in various sectors, is to follow this link: https://www.howtogeek.com/443342/how-to-use-the-mkfs-command-on-linux/

 ex: First create a image file with all 0 in it.Then create a FS by using mkfs.ext2 cmd. Then we can mount this image file just like any other FS.

> dd if=/dev/zero of=~/fs.img bs=1M count=50 => This creates a 50MB image file (with 1MB block size) called fs.img with all 0s in it.

> ls -al ~/fs.img => To show size of file
-rw-rw-r--. 1 kailash kailash 52428800 Dec 10 03:56 /home/kailash/fs.img => 50MB (=50*1024*1024Bytes=52428800 bytes)

> file ~/fs.img
/home/rakesh/fs.img: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=1ca78acd-c8c4-4e02-b4db-10d76395f252 => assigns a random 16 byte UUID

> mkfs.ext2 ~/fs.img => asks for confirmation, and then creates ext2 FS

> sudo mkdir /mnt/tmp_dev
> sudo mount ~/fs.img /mnt/tmp_dev => mounts the FS at /mnt/tmp_dev

> sudo cp ~/tmp.txt /mnt/tmp_dev/. => this copies tmp.txt file to newly mounted FS. This FS now behaves like any other dir on our hard disk

> hexdump -n2048 ~/fs.img => this dumps first 2048 bytes of FS. As can be seen, first 1024 bytes (block 0) are all 0, implying no boot record is present. then next 1024 bytes (block 1) has superblock, and then other data in rest of the blocks. The superblock is always located at byte offset 1024 from the beginning of the file, block device or partition formatted with Ext2 and later variants (Ext3, Ext4).  

NOTE: Not all disks or partitions are used as filesystems. A swap partition, for example, will not have a filesystem on it. Linux boot floppies don't contain a filesystem, only the raw kernel. Not having a FS saves space. Raw disks are used to make image copies of them (using dd cmd).

Linux cmds:

1. lsblk = list block: lists information about all available block devices, however, it does not list information about RAM disks. Examples of block devices are a hard disk, flash drives, CD-ROM etc. So, this is a very useful cmd to see all available storgae devices.

$ lsblk => Shows all devices with thier major:minor number, RM=1 implies removable device, RO=1 implies readonly, TYPE implies whether it's disk, partition within a disk (part), rom memory, etc. We'll talk about mount point later. option -p prints full device path, as /dev/sda etc, else it only shows sda, sdb, etc.

prompt> lsblk ( on my dual boot linux/windows laptop)
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk => sda usually is the main hard disk from which the OS boots. At Linux isntallation time, we usually divide this hard drive into separate partitions (over here in 6 partitions, some of which are Windows partitions, 4 are primary partitions, 2 are logical partition)
├─sda1            8:1    0   500M  0 part /run/media/rajesh/System => on Linux Mint, it's mounted on /media/rajesh/System. It's partition1, the Windows bootable partition in MBR table.
├─sda2            8:2    0  78.7G  0 part /run/media/rajesh/Windows => It's partiton2, where windows OS is insatlled
├─sda3            8:3    0  1000M  0 part => It's partition3, windows recovery partition
├─sda4            8:4    0     1K  0 part
├─sda5            8:5    0     1G  0 part /boot
└─sda6            8:6    0  38.1G  0 part
  ├─centos-root 253:0    0  34.2G  0 lvm  /
  └─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
sr0              11:0    1  1024M  0 rom  

 

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk
├─sda1   8:1    0   260M  0 part /boot/efi => sda1, sda2 etc refer to partition within the disk sda
├─sda2   8:2    0    16M  0 part
├─sda3   8:3    0 246.7G  0 part /media/rajesh/Windows => This is windows partition, since we store Windows OS in a separate partiton than Linux OS, although both are residing on same physical disk.
├─sda4   8:4    0   980M  0 part
├─sda5   8:5    0   7.5G  0 part [SWAP] => here 7.5G of sda was allocated for SWAP and separate partition called "sda5" was created for it.
└─sda6   8:6    0 676.1G  0 part / => Here almost all of disk, 676G, was allocated to root file system "/". This is where everything in linux is stored, starting from root dir.

sdb               8:16   0 953.9G  0 disk  => This is external ssd drive connected via usb
└─sdb1            8:17   0 953.9G  0 part /run/media/rajesh/samsung-ssd => It has 1 partition mounted on path shown

sr0     11:0    1  1024M  0 rom  => This is another device "rom" (usually cd drive on computer) named as sr0. On almost all computers, we'll see atleast these 2 devices, sda and sr0.

lsblk -f => This lists the FS for each partition as well as the UUID of each device. UUID is 128 bit universal unique id, assigned

Mounting under linux:

In linux, you see devies under /dev/* (i.e lsblk devices listed as sda etc are in /dev/sda ....). However, if we try to access /dev/sda contents directly, we see that it's just a link, and we get a message "not a regular file". All these  refer to a device file. For ex /dev/cdrom refers to CD ROM device. This is not the contents of whatever disc you might wish to insert into your optical drive, but rather it is a reference to the bit of hardware (and probably software drivers) that you might call on to show that to you. We can use "dd" cmd to read the contents of all of this device as a big string of bytes (known as disk image), however it's not very meaningful info. FS type tells us how to interpret that string of bytes. In linux, we use cmd "mount" to ask OS to figure out FS of this device and interpret contents based on that. mount attches FS found on some device to the big file tree, so that we can access it as if it's one tree at /somedir/. When you mount /dev/cdrom to some path in your tree you attach its contents to your file system.

ex: mount-t iso9660 /dev/cdrom /media/cdrom => mount cmd tells the system: "take this very long string of bytes that you have in /dev/cdrom, interpret it as a directory tree in the iso9660 format (boot sector of device/partition has necessary info to help interpret the FS on the device), and allow me to access it under the location /media/cdrom. We create this dir "/media/cdrom". It can be any dir anywhere on the system. By convention, FS are usually mounted in /media dir. -t is optional, as mount can itself figure out the FS by reading first few bytes of that device/partition,

mount cmd uses a lot of heuristics to figure out FS of device, which may not always work. That's why it's sometimes necessary to provide -t option to specify the FS explicitly.

ex: sudo umount /media/cdrom => This unmounts whatever was mounted at mount point "/media/cdrom, so that the FS is no more acccessible


ex: mount => shows all FS mounted on this device (FS starting at /)
/dev/hda1           on /       type ext3 (rw,acl,user_xattr) => shows that / FS is mounted on hda1 physicaly attached to m/c (hard drive 1), i.e all of partition /dev/sda1 is a FS accessible with "/"
/dev/cciss/c0d0 on /tmp type ext3 (rw,acl,user_xattr) => /tmp is mounted on another drive c0d0 physicaly attached to m/c.
duke4.abc.com:/vol/fvol528/kagr on /home/rakesh type nfs (rw, ..) => /home/rakesh is mounted on diff m/c duke4.abc.com. This is nfs FS (as it's on diff m/c)

ex: mount => on all laptop shows a lot of FS mounted. imp ones are:

/dev/sda1 on /run/media/rakesh/System type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)
/dev/sda2 on /run/media/rakesh/Windows type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)

/dev/sda5 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota) => /centos-root is mounted on Root dir "/".  

/dev/mmcblk0p1 on /media/sd_card type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096) => This is sd card that I mounted by using "mount" cmd

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) => shows proc is mounted on /proc (even though /roc is not a FS)

 Partitioning HD:

Usually we want to partition our HD into sevral partitions to keep them safe from each other, i.e crash in one partition won't damage the other partition. General practice is to have separate partitions for /, /boot, and swap. You cannot create separate partitions for the following directories: /bin, /etc, /dev, /initrd, /lib, and /sbin. The contents of these directories are required at bootup and must always be part of the / partition.

It is also recommended that you create separate partitions for /var and /tmp. This is because both directories typically have data that is constantly changing. Not creating separate partitions for these filesystems puts you at risk of having log file fill up our / partition.

-------

disk usage cmds

1. df => shows free disk space (df=disk free)
df -kT =>shows amount of diskspace available on file system (for all of the filesystem). -T option shows file system type too. -k shows size in 1K blocks (default in RHEL)
Ex: /home/rajesh> df -T | grep kagrawal => df shows all filesystems, to see diskspace for kagrawal only, we do a grep
near13.srv.abc.com:/vol/fvol156/kagrawal => implies kagrawal has home dir on this server.
nfs 1024000 512416 511584 51% /home/kagrawal
#nfs shows that file system type is nfs => shown only with -T option
#the first column is space allocated yo your unix home dir the second column is space you have used
#the third column is space which is available to you and the percentage you have used
Ex: /home/rajesh> df . => shows usage for current dir. To see usage for some other dir, type: df dir1/dir2
Ex: /proj/dsp/Testbenches $ df .
Filesystem 1K-blocks Used Available Use% Mounted on
coupe.abc.com:/vol/fvol32/proj1 => shows the root dir for the current dir and where it's mounted
5242880 5242848 32 100% /proj/name2 => size is 5.2GB

ex: /home/rajesh> df => on a laptop, this is what it looks like
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  35789748 18501240  17288508  52% / => centOS-root FS is mounted on /

/dev/sda5                 1038336   174224    864112  17% /boot
tmpfs                      770336       68    770268   1% /run/user/1000
/dev/sda1                  511996    54848    457148  11% /run/media/kailash/System
/dev/sda2                82536444 44197628  38338816  54% /run/media/kailash/Windows
/dev/mmcblk0p1           62504960  1622400  60882560   3% /media/sd_card

2. du => disk usage

du -skh dir1/* => Summarize disk usage of each FILE, recursively for directories. Reports for current dir and below.
-k says report in block_size=1K, while -h says to report it in human readable format (as 234M, etc)
-s summarizes directories (reports only 1 line with total size for each matching dir)
du -sk * .??* | sort -n => to sort all files/dir (including dot files) in your current dir
du -ch | grep total => lists 1 line with total size of dir

Installing File system drivers on Linux: Each of these devices or partitons within a device can have it's own separate FS. However, the OS has to know how to read/wrt these FS, else it may not work on partitons with different FS, than what it knows. Usually Linux OS know ext and FAT/NTFS, and work pretty well with them. Since most devices already come formatted with NTFS, Linux has no problems readingwriting to these. However, we may need to install drivers for certain FS if they are not installed by default.

installing NTFS drivers:

sudo yum install epel-release => Nux repository depends on the EPEL software repository. If the EPEL repository is not enabled, enable it using this cmd

sudo yum install ntfs-3g -y; => available in yum repo

Once installed, linux OS should automatically be able to mount the NTFS drive. If not, we can always manually mount by using mount cmd

installing exFAT drivers: 

Most linux distro don't provide support for exFAT FS. So, we can get an error "cannot mount exFAT" when we insert a device which has exFAT FS. To be able to mount exFAT filesystem on CentOS you’ll need to install the free FUSE exFAT module and tools which provide a full-featured exFAT file system implementation for Unix-like systems. However, yum repository for CentOS don't haave these exFAT pacakages available. However, these pkg are available from Nux Dextop (3rd party) repository, and installed using yum with steps as below:

sudo yum install epel-release => Nux repository depends on the EPEL software repository. If the EPEL repository is not enabled, enable it using this cmd
sudo rpm -v --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro  => import the repository GPG key
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm => enable the Nux repository by installing rpm pkg
sudo yum install exfat-utils fuse-exfat => now install the exfat-fuse and exfat-utils packages from nux repo

Once installed, linux OS should automatically be able to mount the exFAT drive. If not (i.e we don't see any response on inserting SD card), we can always manually mount by using mount cmd:

> lsblk => This shows that SD acrd is being recognized by system, but it's not able to read it's contents (as we don't see it under devices in gui)

mmcblk0         179:0    0  59.6G  0 disk
└─mmcblk0p1     179:1    0  59.6G  0 part /media/sd_card

> sudo mount -t exfat /dev/mmcblk0p1 /media/sd_card => As soon as we run this cmd, we see SD card shows up under devices in gui (sometimes it's necessary to specify FS using -t, as OS may still have trouble identifying the FS of the device, even though the FS drivers might be installed, this is due to various heuristics being used to figure out the file system)
FUSE exfat 1.3.0

> sudo umount /media/sd_card => once done, we should unmount the sd card, before ejecting it out.

 

---------------------------

 

 

Chemistry:

Chemistry deals with all elements, molecules, compounds, their properties and their reactions with each other. Basically, chemistry is the only field of science which deals with things that we cannot see with our eyes

Few good links for chemistry:

This section will deal with many topics in the link above. We'll talk about atoms, molecules, compounds and then complex compounds.