According to the Bushido Shoshinshu (the Code of the Samurai), a samurai was supposed to commit seppuku (also "hara kiri" - ritual suicide) upon the loss of his master.
Because the former samurai could not legally take up a new trade, or because of pride were loath to do so, many rōnin looked for other ways to make a living with their swords.