In paper ballot states, for example California, there seem to be a "standard" way of getting a ballot (from what I was told in comments, you get mailed one when you register to vote).
My understanding is that in-person voting is the default in California, and one must specifically request a Vote By Mail ballot. However, there are occasionally small elections (for instance, someone on a city council resigns and they have to have an election just for that office) where they don't want to spend the money for a full-fledged election, so VBM is the only option.
The question is, if you're a scatterbrained person and lost your mailed ballot, can you obtain a ballot on your own initiative
You can go to your normal polling place and surrender your ballot to get a new one. If you do not have your ballot, or you are at polling place other than the one you are registered for, you can vote provisionally: your vote is put aside, they check whether they have received any other votes from you, and if that's your only vote, then it's counted.
You can, through this method, get a ballot other than the "correct" one; for instance, if you go to a polling place in another city, the ballot might have candidates for a city council you are not eligible to vote for. In that case, all of your votes for races you are not eligible to vote for are discarded.
The other variable as to what ballot you should receive is party. California has an open primary system, which means that generally speaking, voters are not restricted by party as to for whom they can vote. There are two main exceptions. First, unless the party decides otherwise, no one not registered for a party may vote in national races, of which the presidential one is the only one in the US. As far as I know, no party has allowed people registered for other parties to vote in their primaries, only people registered for no party. The second exception is that it doesn't apply to positions within a party. That is, voting for leadership of a party (not a party's nominee) is restricted to party members. For instance, only members of the Democratic Party may vote for the Chairman of the California Democratic Party.
Thus, in a presidential primary, there are several different types of ballots for a precinct. There is the No Party Preference ballot, which has no party-specific races. There are ballots for each party. Then, for each party that allows it, there are NP ballots. A NP ballot for a party allows a vote for the presidential nominee, but does not allow votes for party leadership positions.
and if so, how much flexibility is there as far as which specific ballot you get?
You can change your party affiliation before the election, allowing free choice of any one of the party ballots. If you want, you can change your party affiliation every election. If you do not declare a party affiliation, you can choose during the election which of the NP ballots to receive. You can do this by going to your polling place and requesting the ballot. When a NP voter comes in, the Precinct Officers are supposed to ask whether they want a NP party ballot, but they often do not do so, and the voter has to actively request one. If you have a VBM ballot and it is not the one you want, you can surrender it in exchange for a new ballot.
Or does someone check which ballot you personally are entitled to, based on some database and your IDs?
Each precinct has a Roster Index, which is several sheets of paper listing the people eligible to vote in that precinct and their party. A voter comes in, gives their name, their name is looked up on the Roster Index, and they sign the Roster Index. If they have a party listed, they are given that party's ballot. If they don't have a party listed, they are allowed to choose a NP ballot. If they are not listed on the Roster Index, or they want to vote a party ballot for which the Roster Index says they are not eligible, they vote provisionally.
Another way to frame this question (and I'll accept answers in this frame) is, is there a way to get an "incorrect" ballot in California, e.g. a Dem primary ballot though you're registered as Libertarian party and not a Democrat.
If you are not registered for any party, and the Democratic Party allows it, you can get a No Party Preference Democratic Party ballot (this name may seem contradictory, but it is used to refer to a ballot that allows you to vote for the party nominees, but not party leadership positions). If you are registered for another party, such as the Libertarian Party, you are not eligible for any Democratic Party ballot. However, if you insist, you can be given a Democratic Party ballot, it will be set aside as a Provisional Ballot, and the partisan races will almost certainly not be counted.
California did try voting machines, and they are still an option (every precinct has a voting machine, and you can request to use it, but paper ballots are the default), and it works somewhat similarly, in that the election officers give voters a card that activates the voting machine, and the type of ballot is recorded on that card. It is somewhat simpler in that the card can be reprogrammed by the election officers, so it's not necessary to keep piles of different types of ballots.