The period of sefirat ha-omer (between Pesach and Shavuot) is considered a period of mourning, but there is great confusion as to what are the periods of mourning and why there is mourning at all.
In the Torah, the Mishnah, the Talmud and the Rambam there is no mention of any type of mourning in reference to the period of sefirat ha-omer. The Talmud (Yevamot 62b) records that 12,000 pairs of students of Rabbi Akiva died between Pesach and Shavuot, but the Talmud does not mention that any mourning was instituted in this period for these scholars who died.
The first reference to mourning in this period is from the Geonim. Otzar ha-Geonim (7:141, on Yevamot 62b) quotes Rav Natronai Gaon, (9th century) and R. Hai Gaon (939-1038) that one does not marry during the entire period from Pesach to Shavuot, though one can become engaged in this period. Similarly, the Otzar Ha-Geonim (also quoted in Tur, Orah Chayyim 493) quotes R. Yitzhak ibn Giat (Spain, 1020-1089) who also mentions the custom of not marrying the entire period of sefirat ha-omer. The reason recorded for this custom is the deaths of R. Akiva's students, but Trachtenberg (2004, p. 255) notes "that according to some, the Roman superstition which forbade marriages in May" was the source of this custom not to marry. In addition, Rav Hai Gaon refers to a custom not to work at night from Pesach to Shavuot, also due to the deaths of R. Akiva's students. As noted by Sperber (1990, p.102), in all of the Geonic literature, the mourning in the period of sefirat ha-omer was for the entire period, and it consisted just of not getting married and not working at night.
This custom from the Geonim, was not mentioned by the Rambam, why not? It is difficult to believe that the Rambam was unaware of this custom of not getting married, which suggests that the Rambam rejected the custom, but why? Did the Rambam think that the deaths of R. Akiva's students were not "sufficient" to justify people not getting married during sefirat ha-omer? Or, did he think that the source of the custom not to get married was based on the Roman superstition and hence he left it out?
In the same period of the Rambam, R. Avraham Hayarchi (1155, Provence, to 1215 Toledo, Spain) writes in the Sefer ha-Manhig (quoted in Abudarham, 1995, pp. 271,272, and by Zevin, 1956, p. 299) that in some places (Provence?) the custom was to marry from Lag Ba-omer onwards. This change was based on a claim that in a text in Spain it was recorded that R. Akiva's students died until "peros" Shavuot. R. Hayarchi writes that peros means half, and as the word half appears with regard to the law of learning the laws of Pesach 30 days before Pesach, then peros means half of 30 or 15. Thus, he writes that the mourning stopped 15 days prior to Shavuot, namely on Lag Ba-omer, the 33rd day of sefirat ha-omer, and the 18th of Iyar. Similarly, in the 13th century, the Meiri (1249-1306, commentary on Yevamot 62a) who was also from Provence, writes that the custom was not to marry just from Pesach to Lag Ba-omer. According to these sources, there is still no mention of not cutting one's hair during sefirat ha-omer. In addition, with this development of the holiday of Lag Ba-omer, the custom of mourning was shortened, and became a major factor for why there are some many customs since it was not obvious how to integrate Lag Ba-omer and the shortened period of mourning into the forty nine day period of sefirat ha-omer. For a discussion of the development of the holiday of Lag Ba-omer and the drasha of peros see our discussion above on Lag Ba-omer, "You do the math," https://lobashamayim.blogspot.co.il/2009/05/lag-ba-omer.html
Also in the 13th century, the Shibolei Haleket (Italy, 1230-1300, quoted in Sperber, 1990, p. 109) writes that people do not get married during the entire period from Pesach to Shavuot, but in some places people would get married until Rosh Chodesh Iyar. Sperber suggests that the basis for this custom was that that the first Crusaders in 1096 began massacring Ashkenazi Jewry in Iyar, and hence Ashkenazi Jewry started mourning only in Iyar. According to the kinah, mi yiten mayim by R. Kalonymos ben Yehuda (12th century, Germany) that we recite on Tisha B'av, on the 8th of Iyar the Jews of Speyer were killed, on the 23rd of Iyar and on the 1st day of Sivan, the Jews of Worms were killed and on the 3rd day of Sivan, the Jews of Mainz were killed. A different possibility unrelated to the suffering due to the Crusades is that this custom of having marriages until Rosh Chodesh Iyar was a way of reducing the period of no marriages, just like the idea of allowing people to marry on and after Lag Ba-omer, again see our discussion on Lag Ba-omer, "You do the math."
The book, Sefer Minhag Tov (anonymous, apparently from Italy, end of the 13th century) quotes customs from France and Germany, and the author mentions new customs of mourning for the period. He writes (61, in Sperber, 1990, p. 107) that it is a good custom not to cut one's hair and nails, not to wear new clothing, and not to enjoy bathing from Pesach to Shavuot excluding Lag Ba-omer. Furthermore, he writes that these customs are because of the righteous who died in this period, which Sperber explains refers to the German Jews who were massacred by the Crusaders. We see that the custom of not cutting your hair during sefirat ha-omer is both a later development and not related to the custom of not getting married during this same period. Presumably it developed from the idea of not cutting one's hair by the mourning for the destruction of the Bet ha-Mikdash since the mourning for the massacres of the communities in Germany by the Crusaders was made equivalent in some ways to the mourning for the destruction of the Bet ha-Mikdash (see the kinot we recite on Tisha B'av).
The Tur (1275, Germany to 1340, Spain, Orah Chayyim 493) writes that in all places people do not marry from Pesach to Shavuot, which follows the custom from the Geonim. He also writes that some people do not cut their hair for the entire period and some people cut their hair after Lag Ba-omer. This implies that he knew of three customs with regard to cutting one's hair, see the Bach's comments on the Tur. One, some people cut their hair during the entire period of sefirat ha-omer, two, some people refrained from cutting their hair for the entire period, and three, some people did not cut their hair from Pesach to Lag Ba-omer. The Tur did not specify which places followed which custom. However, following Sperber's argument that the custom of not cutting one's hair was due to the massacres by the Crusaders, then it is likely that in Germany more people kept the custom of not cutting their hair in the entire period, as recorded by the Sefer Minhag Tov, while in Spain more people either cut their hair or just refrained from cutting their hair until Lag Ba-omer.
The Tur also refers to the custom from the Geonim of not working at night during the period from Pesach to Shavuot, but he writes that only women had this custom to not work after sunset. The Shulchan Arukh (493:4) quotes this custom, again just with regard to women. The Taz (Poland, 1586-1667, 493:3) limits it even more, as he writes that after one counts the omer, then one can work. The Arukh Hashulchan (Russia, 1829-1908, 493:9, also Chayyei Adam 131:11) writes that in his time some women kept this custom of not working until after maariv, but I am unaware of women who keep this custom today.
At around the same time as the Tur, R. Yehoshua ibn Shuiv (Spain, 14th century, quoted in Bet Yosef, 493 and Sperber, 1990, p. 104) writes that on the 34th day of the omer, people would shave apparently after not having shaven since Pesach. He might be the first person to mention not shaving during this period.
Abudarham (Abudirham?, Seville, early 14th century, laws between Pesach and Shavuot, 1985 version, p. 271) quotes two customs. One, to not get married and to not have a haircut the entire sefirat ha-omer (one possibility in the Tur), and two, to not marry and not cut one's hair from Pesach until (not including) Lag Ba-omer.
The Maharil (Germany, 1365-1437, Sefer Maharil, 1989, pp.154,157, quoted in Darkei Moshe 493:3 and Sperber, 1990, p. 110, footnote 37) writes that the custom in all places (Germany?) was not to marry for the entire period between Pesach and Shavuot and this apparently included Lag Ba-omer. With regard to hair cutting, he personally also did not shave for the entire period. However, he told his students that they could shave on and after Lag Ba-omer, and that he also accepted that some people shaved until Rosh Chodesh Iyar. It is not clear to me, whether he shaved on Lag Ba-omer or not. He writes that one cannot shave on erev Shabbat when Lag Ba-omer is on Sunday, which implies that one can shave on Lag Ba-omer itself, though maybe this was only according to his instructions to his students whom he told that they could shave on Lag Ba-omer.
Rav Yosef Caro (1488, Spain - 1575, Israel, Bet Yosef and Shulchan Arukh, 493) quotes that the custom is to equate the mourning of not getting married with the custom of not cutting one's hair, and that both are not done from Pesach through (including) Lag Ba-omer. In the Shulchan Arukh, he writes explicitly that haircuts are only permitted on the 34th day of the omer (the day after Lag Ba-omer), as stated by R. Yehoshua ibn Shuiv, and this apparently is also his view in reference to getting married. It seems that for R. Yosef Caro, Lag Ba-omer was not a special day.
Yaakov Gliss (1994, p.140) writes that the custom in Israel was to keep the mourning from Pesach until Lag Ba-omer, but starting from Lag Ba-omer people would marry and cut their hair. This differs from the Shulchan Arukh since according to the Shulchan Arukh it is only from the 34th day of the omer that it is permitted to cut one's hair and to marry. R. Chayyim David HaLevi (Mekor Chayyim 195:18-20) writes that the custom of Sefardim today with regard to getting married is not to marry from Pesach until Lag Ba-omer, while from Lag Ba-omer onwards it is permitted to marry. With regard to hair cutting, R. Chayyim David HaLevi first writes that the custom of Sefardim is not to cut one's hair until the 34th day of the omer like the Shulchan Arukh, but then he writes that some people cut their hair on Lag Ba-omer, the 33rd day of the omer.
The opinion of the Rama (Poland, d. 1572) is not clear. First, with regard to the Shulchan Arukh's comment about not getting married until the 34th day of the omer, he writes (493:1) that it is permitted to marry from Lag Ba-omer onwards. Afterwards, in reference to the Shulchan Arukh's comment that one cannot cut their hair until the 34th day of the omer, he writes (493:2) that this too is permitted on the day of Lag Ba-omer, though not the night of Lag Ba-omer. He also writes that if Lag Ba-omer is on Sunday, then one can cut their hair on erev Shabbat, the 31st day of the omer because of kavod Shabbat. Afterwards, he writes (493:3), that the custom in most places (in the Darkei Moshe, a few places?) was that one would not cut one's hair from after Rosh Chodesh Iyar until Shavuot excluding Lag Ba-omer (and Rosh Chodesh Sivan, see Darkei Moshe). This period of mourning corresponds to the attacks by the Crusaders on the Jewish communities in Germany in 1096. In this third comment, he only refers to not cutting one's hair, but does he also mean not to get married in this period? The question is does his first comment (493:1) about getting married from Lag Ba-omer onwards apply only for people who also do not cut their hair from Pesach to Lag Ba-omer or was the Rama stating that with regard to not getting married the period is from Pesach until Lag Ba-omer, but with regard to not cutting one's hair the period starts from Rosh Chodesh Iyar until Shavuot excluding Lag Ba-omer (and maybe Rosh Chodesh Sivan). Accordingly it not clear if the Rama himself thought that the two prohibitions of not getting married and not cutting one's hair were for the same time periods.
The Bach (1561-1640, Poland, 493), agrees with Rav Yosef Caro that the customs with regard to not getting married and not cutting one's hair are for the same time periods, and he writes that in his time, there were two customs amongst Ashkenazim. One custom was to mourn until (not including) Lag Ba-omer, while the second custom was to start the mourning the day after Rosh Chodesh Iyar and continue until Shavuot, just excluding Lag Ba-omer. He writes that according to the second custom one should not cut one's hair on Rosh Chodesh Sivan.
The Taz (1586-1667, the Bach's son-in-law, 493:2) explicitly writes that there was a difference between the customs of not getting married and of not cutting one’s hair. He writes that the custom in all places (amongst Ashkenazim? Poland?) was not to get married throughout the entire period from Pesach to Shavuot except for Lag Ba-omer. With regard to not cutting the hair, the Taz writes that this prohibition was only until Lag Ba-omer. He explains that the mourning until Lag Ba-omer is due to the deaths of the students of R. Akiva, while afterwards the mourning is due to the suffering during the Crusades. In addition, he suggests that the mourning due to the suffering during the Crusades was only to curtail great happiness like a wedding, but would not prohibit hair cutting. This is a difficult explanation since the custom not to marry for the entire period is from the time of the Geonim who lived before the time of the Crusades. In any event, the custom as stated by the Taz was soon changed by the Magen Avraham.
The Magen Avraham (Poland, 1637-1683, 493:2,5) also equates the times for the two types of mourning, but he changed the Bach's second custom since he allows people to marry in the three day period before Shavuot (the 3rd-5th days of Sivan). He records that the mourning should begin on the first day of Rosh Chodesh Iyar (the 30th day in Nisan) and include Rosh Chodesh Sivan, which gives 33 days (1 in Nissan, 29 in Iyar including the little bit on Lag Ba-omer and three in Sivan including a little bit on the 3rd day of Sivan). This dating started the mourning two earlier than by the Bach in order that it would end two days earlier, on the third of Sivan instead of the fifth of Sivan. One problem with this dating is that this custom is invoking the principle that if one mourns a little it is like a full day twice, once by Lag Ba-omer and once on the third day of Sivan.
The Magen Avraham (see also Biur Halacha 493: Yesh nohagim) also quotes an idea to mourn the entire period except for Pesach, Shabbat, Rosh Chodesh Iyar, Rosh Chodesh Sivan and Lag Ba-omer. This idea is based on the explanation of the Maharil that the students of Rabbi Akiva did not die on the days when tachanun is recited. This explanation was theoretical for the Maharil to justify the holiday of Lag Ba-omer, but was not the custom of the Maharil. The Magen Avraham notes that as the Rama did not quote this custom it seems that he rejected it. It is unclear to me if this custom was ever followed.
The Chayyei Adam (1748-1820, Vilna, 131:11) wrote that the custom in Vilna was to follow the custom recorded by the Magen Avraham to start the mourning on the first day of Rosh Chodesh Iyar until the third day of Sivan (a little bit on the third day) and during this period one did not marry or cut their hair. He does not state that one has to mourn a little bit on Lag Ba-omer, which might imply that people cut their hair at night on Lag Ba-omer.
The Mishnah Berurah (1907, Poland, 493:14,15) and Arukh Hashulchan (1829-1908, 493:6) both write that their custom was like the Magen Avraham. The Mishnah Berurah also quotes (end of 493:15) a custom to mourn the entire period except for Rosh Chodesh Iyar, Lag Ba-omer, and all the days of Sivan.
I have been told that the Magen Avraham's dates for the mourning was the dominant Ashkenazi Eastern European custom prior to WWII. Nowadays, this custom appears to have lost its popularity since most people, especially in Israel, follow the custom of mourning from Pesach until Lag Ba-omer, with Sefardim waiting to cut their hair until the 34th (except by the chalakah?) and Ashkenazim cutting their hair on Lag Ba-omer itself. However, I have been told (in April 2014) that Jews in Switzerland and South Africa still follow this custom.
After the founding of the state of Israel, a new variation developed that Yom Ha-atzmaut became a break in the period of mourning. Thus, in Israel, where almost everybody follows the period of mourning as being from Pesach to Lag Ba-omer, many of the people who are Zionists shave (cut their hair? get married on Yom Ha-atzmaut?). After 1967, Yom Yerushalayim (the 28th of Iyar) also became a break for some people, though this was only relevant if a person kept the mourning until the third day of Sivan.
Finally, as I discuss below, "The law/ custom of not cutting one's hair in the nine days and three weeks," https://lobashamayim.blogspot.co.il/2009/07/cutting-ones-hair-in-three-weeks-and.html, I strongly believe that a person who shaves throughout the year for Shabbat, has to shave for Shabbat during the sefirat ha-omer period. To summarize the discussion there, I believe that the idea that one should not cut their hair/ shave for Shabbat during the mourning periods of the three weeks and sefirat ha-omer is from the Karaites who had no concern for kavod/ oneg Shabbat, and really the rule of the Mishnah, the Rambam, Tosafot and others is that Shabbat takes precedence over the mourning of the Bet ha-Mikdash and certainly Shabbat takes precedence over the mourning for the students of Rabbi Akiva and the suffering during the period of the Crusades. If a person normally shaves for Shabbat, and does not do so during the sefirah period (and the three weeks), then he is making the mourning more important than Shabbat and this is wrong.
To summarize all the different periods of mourning, if we exclude the Rambam's opinion of no mourning and the custom not to work at night, we see that there were at least sixteen different customs from the time of the Geonim until today with regard to getting married and cutting one's hair during sefirat ha-omer.
One, from the Geonim, the custom was not to get married throughout the entire period from Pesach to Shavuot but there was no prohibition of cutting one's hair.
Two, from Sefer ha-Manhig (12th century), the custom was not to marry until Lag Ba-omer, and there was no prohibition of cutting one's hair.
Three, mentioned by the Shibolei Haleket (13th century) was not to marry from Rosh Chodesh Iyar until Shavuot, but there was no prohibition of cutting one's hair. This does not appear to have been a wide spread custom, but it might have influenced the later Ashkenazi practice.
Four, one custom quoted by the Tur and Abudarham (both early 14th century) was not to marry or to cut one's hair for the entire period of sefirat ha-omer. This custom did not allow any exception even for Lag Ba-omer. It seems the Maharil followed this custom, though he might have cut his hair/ shaved on Lag Ba-omer.
Five, also in the Tur, was the custom not to marry the entire period, but to cut one's hair on and after Lag Ba-omer. This custom accords with the Maharil's instruction to his students.
Six, a second custom in the Abudarham, was to not get married or to cut one's hair from Pesach until Lag Ba-omer, but from Lag Ba-omer onwards, both are permitted. I think this is the dominant custom today.
Seven, mentioned by the Maharil (15th century), was the custom not to get married the entire period of sefirat ha-omer and not to cut one's hair from Rosh Chodesh Iyar until Shavuot.
Eight, the Shulchan Arukh (16th century) writes that one does not get married or cut one's hair until the 34th day of the omer. This custom ignores Lag Ba-omer.
Nine, the Shulchan Arukh's practice is varied slightly by some (many?) Sefardim today. They wait until the 34th day of the omer to cut their hair, but will get married on the 33rd day (Mekor Chayyim).
Ten, one way of understanding the Rama (combining 493:1,2,3) is that the custom is not to marry from Pesach until Lag Ba-omer, but to start the prohibition of not getting a hair cut from the day after Rosh Chodesh Iyar until Shavuot, excluding the daytime of Lag Ba-omer (and the 31st day of the omer if Lag Ba-omer is on Sunday and maybe also Rosh Chodesh Sivan). I am not sure if this is the correct way to understand the Rama and whether this possibility was ever followed.
Eleven, from the Bach (end of 16th century, beginning of 17th century) was the custom not to marry or cut one's hair from after Rosh Chodesh Iyar until Shavuot excluding Lag Ba-omer but including Rosh Chodesh Sivan.
Twelve, quoted by the Taz (middle 17th century) was the custom not to marry the entire period of sefirat ha-omer except for Lag Ba-omer, and not to cut one's hair until Lag Ba-omer. This custom is the same as number five, except that with this custom one could marry on Lag Ba-omer, while according to custom five one did not get married on Lag Ba-omer.
Thirteen, from the Magen Avraham (middle to late 17th century) was the custom that one does not marry or cut one's hair starting from the first day of Rosh Chodesh Iyar until the morning of the third day of Sivan, excluding Lag Ba-omer. The Magen Avraham writes that even by Lag Ba-omer there is some mourning at night, but it seems from the Chayyei Adam that the adherents to this custom did not mourn at all on Lag Ba-omer. I believe that this was the main Ashkenazi custom in Europe before the holocaust.
Fourteen, also mentioned by Magen Avraham, was the custom not to get married or to cut one's hair on all the days of sefirat ha-omer except for Pesach, Shabbat, Rosh Chodesh Iyar, Rosh Chodesh Sivan, and Lag Ba-omer (excluding a little bit).
Fifteen, mentioned by the Mishnah Berurah, though he seems to have followed possibility thirteen, is not get married or cut one's hair for the entire omer period until Rosh Chodesh Sivan, excluding Rosh Chodesh Iyar, and Lag Ba-omer. This is a slight variation (adding days 2-5 of Sivan) from possibility fourteen.
Sixteen, in Israel today (2017) amongst the dati leumi community, the mourning is from Pesach up to Lag Ba-omer, but on Yom Ha-atzmaut people attend festive celebrations, and shave. Also many people in this group shave on erev Yom Ha-atzmaut to look "clean" at the start of Yom Ha-atzmaut.
From this review, we see that the two main customs of the period of sefirat ha-omer, not to marry and not to cut one's hair, are independent of each other even though today both are observed for the same period of time. The custom not to marry might have been due to the death of the students of R. Akiva, while the custom not to cut one's hair was due to the deaths of the Jews in Germany in 1096 during the first Crusades. Also the advent of the holiday of Lag Ba-omer in the Middle Ages reduced the period of mourning from the entire period from Pesach to Shavuot to being around 33 days, and has led to many variations as to how to make this reduction.