Tag Archives: mount

mounting ftp in bash

In english
Kaip prijungti ftp serveri kaip lokalų katalogą?
Paieškojus radau keletą sprendimų, juos visus išbandžiau, ir priėjau išvadų, kad lyg ir patogiausias būdas tai pasinaudojus curlftpfs. Įdiekite jį pasinaudodami aptitude ar betkokį kitą paketų valdymo įrankį. (Papildomai apie curlftpfs_*.deb)
Taigi, mes jau galime prisijungti direktoriją prie ftp serveriuko, kaip tai padaryti?

Prijungimui per fstab įgyvendinti mums reikia atlikti 2 veiksmus:

  • pridėti įrašą į /etc/fstab
  • sukurti mount.curlftpfs

Taigi pridedame įrašą į /etc/fstab


ftpusername:ftppassword@ftp.site.address /path/to/mountpoint curlftpfs rw,allow_other,uid=userid,gid=groupid 0 0


ir tuomet sukuriame mount.curlftpfs tam, kad mount suprastų ką ir kaip reikia prijungti naudojant curlftpfs failų sistemą.


# ln -s `which curlftpfs` /sbin/mount.curlftpfs


Ir antrasis būdas tiesiog kiekvieną kartą paleidžiant OS prijungti pasinaudojant curlftpfs ftp direktoriją, deja jeigu mes neturėsime krovimosi metu tinklo, mum nepavyks prisijungti šio resurso. Taigi paprasčiausiai įdedame eilutę:


curlftpfs ftpusername:ftppassword@ftp.site.address /path/to/mountpoint/


Žinoma, neturint tinklo abiem atvejais negalėsime prisijungti prie ftp resurso, bet pirmuoju būdu atsiradus tinklui, galėsime tiesiog įrašyti: mount /path/to/mountpoint
ir resursas bus automatiškai prijungtas.


How to mount some ftp resource to my Debian box?
After doing some searches i have found some ways, i have tried them and wrote down the way i liked using curlftpfs. aptitude or apt-get it from curlftpfs_*.deb repositories or compile it from sources, what ever you like. After you have installed these you may choose howto mount our ftp to /path/to/mountpoint.

connecting using fstabwe wil need to make 2 steps:

  • add a row to /etc/fstab
  • create mount.curlftpfs

So let’s add some line to /etc/fstab


ftpusername:ftppassword@ftp.site.address /path/to/mountpoint curlftpfs rw,allow_other,uid=userid,gid=groupid 0 0


last step is to let mount recognize the filesystem type


# ln -s `which curlftpfs` /sbin/mount.curlftpfs


And the second one is just to add a row to /etc/rc.local file.


curlftpfs ftpusername:ftppassword@ftp.site.address /path/to/mountpoint/


Of course both ways will not work if we will not have active connection at startup. But using fstab way you can easily mount it: mount /path/to/mountpoint

External links:
some more info on forums

fstab

fstab – kas tai? kam tai?

Ši byla aprašo skirsnius ir kuriose direktorijas mūsų bylų sistemoje bus prijungti šie skirsniai ir kokiais parametrais.

/etc/fstab naudojamas prijungti mūsų particijas ir FS, šios bylos turinys nuskaitomas įkrovos metu.

Skaitydami toliau, tikiuosi mokate naudotis mount komanda. Nes iiš esmės bus naudojamos tos pačios nuostatos ir principas.

  • Autorius: Nana Långstedt < nana.langstedt at gmail.com >
  • tuXfile sukurtas: 2003 m. Spalio mėn. 12 d.
  • Atnaujinta: 2009 m. Rugsėjo mėn. 5 d.

Kas yra fstab ir kodėl tai naudinga

fstab yra konfigūracinė byla, kurioje įrašyta informacija apie visus skirsnius ir kaupiklius prijungtus prie jūsų kompiuterio. Byla patalpinta /etcdirektorijoje, taigi pilnas kelias būtų /etc/fstab.

Byloje /etc/fstab yra informacija kaip ir kur turėtų būti prijungti mūsų kaupikliai ir particijos. Jeigu jūs negalite pasiekti savo Windows skirsnio ar negalite prisijungti CD/DVD-ROM/RW, ar įrašyti standžiojo diskelio paprasto/kasdienio naudotojo teisėmis, gan didelė tikimybė, kad ka-kas pažaidė su jūsų /etc/fstab. Dažniausiai tokios problemos gai būti ištaisytos pataisius šią vienintele bylą.

/etc/fstab – tai tiosiog pliko teksto byla, taigi jums nereikia jokios specialios programos norint atidaryti šią bylą – užteks paprasto redaktoriaus, kad ir vim, cream, gedit, nano, kedit, kwrite ar kitas. Vieninteis reikalavimas, turime turėti root’o teises norint jį redaguoti ar net skaityti. Taigi norėdami šią bylą redaguoti, galite prisijungti kaip root ar pasinaudoti su komanda ar sudo.

Bylos peržiūra

Žinoma visi turime skirtingas /etc/fstab bylas, nes skiriasi mūsų skirsniai ir jų išdėstymas, diskai ir t.t. Bet struktūra bylos, esmė, visur ta pati. Štai pavyzdukas tokios bylos:

#Įrenginys Direktorija FS Opcijos Dump fsck
/dev/hda2 / ext3 defaults 1 1
/dev/hda1 /boot ext3 defaults 1 1
/dev/hda3 swap swap pri=42 0 0
/dev/hdb1 /home ext3 defaults 1 2
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
proc /proc proc defaults 0 0

Ką visas šis šlamštas reiškia? Kaip jau pamatėte kiekviena eilutė neša informaciją apie įrenginį arba skirsnį. Pirmame stulpelyje išdėstyti įrenginių bylos/vardai, antrame, kur šie bus prijungti, trečiame jų bylųsistemos tipai, ketvirtame prijungimo opcijos, penktame (skaičius) dump opcijos, šeštame (kitas skaičius) bylų sistemos tikrinimo nustatymai. Nagi pasižiūrėkime šiektiek iš arčiau.

1-as ir 2-as stulpeliai: Įrenginiai ir nutylėtosios prijungimo direktorijos (default mount point’s)

The first and second columns should be pretty straightforward. They tell the mount command exactly the same things that you tell mount when you mount stuff manually: what is the device or partition, and what is the mount point. The mount point specified for a device in /etc/fstab is its default mount point. That is the directory where the device will be mounted if you don’t specify any other mount point when mounting the device.

Like you already learned from the Mounting tuXfile, most Linux distros create special directories for mount points. Most distros create them under /mnt, but some (at least SuSE) under /media. As you probably noticed when looking at the example fstab, I use SuSE’s mount points as an example.

What does all this mean? If I type the following command: $ mount /dev/fd0 … my floppy will be mounted in /media/floppy, because that’s the default mount point specified in /etc/fstab. If there is no entry for /dev/fd0 in my fstab when I issue the command above, mount gets very confused because it doesn’t know where to mount the floppy.

You can freely change the default mount points listed in /etc/fstab if you’re not satisfied with the defaults your distro has given you. Just make sure the mount point is a directory that already exists on your system. If it doesn’t, simply create it.

Some partitions and devices are also automatically mounted when your Linux system boots up. For example, have a look at the example fstab above. There are lines that look like this:

/dev/hda2 / ext2 defaults 1 1 /dev/hdb1 /home ext2 defaults 1 2

As you’ve learned, these lines mean that /dev/hda2 will be mounted to / and /dev/hdb1 to /home. This is done automatically when your Linux system boots up… if it wouldn’t, you’d have a hard time using your cool Linux system because all the programs you use are in / and you wouldn’t be able to run them if / wasn’t mounted! But how does the system know where you want to mount /dev/hda2 and /dev/hdb1? By looking at the /etc/fstab file of course.

3rd column: Filesystem type

The third column in /etc/fstab specifies the filesystem type of the device or partition. Many different filesystems are supported but we’ll take a look at the most common ones only.

ext2 and ext3 Very likely your Linux partitions are Ext3. Ext2 used to be the standard filesystem for Linux, but these days, Ext3 and ReiserFS are usually the default filesystems for almost every new Linux distro. Ext3 is a newer filesystem type that differs from Ext2 in that it’s journaled, meaning that if you turn the computer off without properly shutting down, you shouldn’t lose any data and your system shouldn’t spend ages doing filesystem checks the next time you boot up.

reiserfs Your Linux partitions may very well be formatted as ReiserFS. Like Ext3, ReiserFS is a journaled filesystem, but it’s much more advanced than Ext3. Many Linux distros (including SuSE) have started using ReiserFS as their default filesystem for Linux partitions.

swap The filesystem name is self-explanatory. The filesystem type “swap” is used in your swap partitions.

vfat and ntfs Your USB stick is most likely formatted as Vfat (more widely known as FAT32). Your Windows partitions are probably either Vfat or NTFS. The 9x series (95, 98, ME) all use Vfat, and the NT series (NT, 2000, XP, Vista, 7) use NTFS but they may be formatted as Vfat, too.

auto No, this isn’t a filesystem type 🙂 The option “auto” simply means that the filesystem type is detected automatically. If you take a look at the example fstab above, you’ll see that the floppy and CD-ROM both have “auto” as their filesystem type. Why? Their filesystem type may vary. One floppy might be formatted for Windows and the other for Linux’s Ext2. That’s why it’s wise to let the system automatically detect the filesystem type of media such as floppies and cdroms.

4th column: Mount options

The fourth column in fstab lists all the mount options for the device or partition. This is also the most confusing column in the fstab file, but knowing what some of the most common options mean, saves you from a big headache. Yes, there are many options available, but I’ll take a look at the most widely used ones only. For more information, check out the man page of mount.

auto and noauto With the auto option, the device will be mounted automatically (at bootup, just like I told you a bit earlier, or when you issue the mount -a command). auto is the default option. If you don’t want the device to be mounted automatically, use the noauto option in /etc/fstab. With noauto, the device can be mounted only explicitly.

user and nouser These are very useful options. The user option allows normal users to mount the device, whereas nouser lets only the root to mount the device. nouser is the default, which is a major cause of headache for new Linux users. If you’re not able to mount your cdrom, floppy, Windows partition, or something else as a normal user, add the user option into /etc/fstab.

exec and noexec exec lets you execute binaries that are on that partition, whereas noexec doesn’t let you do that. noexec might be useful for a partition that contains binaries you don’t want to execute on your system, or that can’t even be executed on your system. This might be the case of a Windows partition.

exec is the default option, which is a good thing. Imagine what would happen if you accidentally used the noexec option with your Linux root partition…

ro Mount the filesystem read-only.

rw Mount the filesystem read-write. Again, using this option might cure the headache of many new Linux users who are tearing their hair off because they can’t write to their floppies, Windows partitions, or something else.

sync and async How the input and output to the filesystem should be done. sync means it’s done synchronously. If you look at the example fstab, you’ll notice that this is the option used with the floppy. In plain English, this means that when you, for example, copy a file to the floppy, the changes are physically written to the floppy at the same time you issue the copy command.

However, if you have the async option in /etc/fstab, input and output is done asynchronously. Now when you copy a file to the floppy, the changes may be physically written to it long time after issuing the command. This isn’t bad, and may sometimes be favorable, but can cause some nasty accidents: if you just remove the floppy without unmounting it first, the copied file may not physically exist on the floppy yet!

async is the default. However, it may be wise to use sync with the floppy, especially if you’re used to the way it’s done in Windows and have a tendency to remove floppies before unmounting them first.

defaults Uses the default options that are rw, suid, dev, exec, auto, nouser, and async.

5th and 6th columns: Dump and fsck options

Dump and, uh, what options? Well, dump is a backup utility and fsck is a filesystem check utility. I won’t discuss them in great length here (they would both need their own tuXfile), but I’ll mention them, because otherwise you’d spend the rest of the day wondering what on God’s green Earth do these things mean.

The 5th column in /etc/fstab is the dump option. Dump checks it and uses the number to decide if a filesystem should be backed up. If it’s zero, dump will ignore that filesystem. If you take a look at the example fstab, you’ll notice that the 5th column is zero in most cases.

The 6th column is a fsck option. fsck looks at the number in the 6th column to determine in which order the filesystems should be checked. If it’s zero, fsck won’t check the filesystem.

Example /etc/fstab entries

As an example, we’ll take a look at a couple of fstab entries that have been a source of endless frustration for new Linux users: floppy and CD-ROM (although these days floppies aren’t that important anymore).

/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0

This line means that the floppy is mounted to /media/floppy by default and that its filesystem type is detected automatically. This is useful because the type of the floppy may wary. Note especially the rw and user options: they must be there if you want to be able to mount and write to the floppy as a normal user. If you have trouble with this, check your fstab file to see if these options are there. Also note the sync option. It can be async just as well, but it’s sync because of reasons discussed a bit earlier.

/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0

Note, again, the user option that enables you to mount the CD as a normal user. The CD-ROM has the ro option because it’s no use mounting a CD-ROM read-write because you wouldn’t be able to write to it anyway. Also note the exec option. It’s especially useful if you’d like to be able to execute something from your CD.

Also note that the noauto option is used with the floppy and CD-ROM. This means that they won’t be automatically mounted when your Linux system boots up. This is useful for removable media, because sometimes there won’t be any floppy or CD-ROM when you boot up your system, so there isn’t any reason to try to mount something that doesn’t even exist.