mount

最後更新: 2016-10-24

目錄

 

  • ISO 檔 (loop)
  • umount
  • 一般 mount options
  • mount a partition
  • remount readonly
  • mount by partitation label
  • 其他

 


loop mount

 

Usage:

mount /tmp/disk.img /mnt -t vfat -o loop=/dev/loop

-o loop

mount will try to find some unused loop device and use that

ISO 檔

  • iocharset (中文檔名 ), default 是 iso8859-1, 有時要改用 unicode 才不會亂碼

 


umount

 

-l         # does a "lazy" unmount
           (which means it keeps waiting until the device isn’t busy any longer before automatically unmounting it)

-k       # Kill processes accessing the file.

-f        # Force unmount
           (cause data loss for open files)

 


一般 mount options

 

# 常見的 default

  • defaults (equivalent to rw,suid,dev,exec,auto,nouser,async)

# mount -a 時是否 auto mount

  • auto
  • noauto

# 此 partition 上可否行 binary

  • exec  (default)
  • noexec

# readonly

  • ro
  • rw

# sync

  • sync
  • async

#  一般  user 可否 mount  此 partition

  • user ( noexec,nosuid,nodev )
  • nouser (default)

# suid 是否有效

  • suid
  • nosuid

#

  • noatime           # file 的 atime
  • nodiratime       # directory  的 atime
  • relatime           # update inode access times relative to modify or change time

 


mount a partition

 

查看 file 的 partition 結構

server:~# fdisk -l diags.img

Disk diags.img: 4 MB, 4644864 bytes
16 heads, 63 sectors/track, 9 cylinders, total 9072 sectors
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 identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
diags.img1   *          63        9071        4504+   4  FAT16 <32M

* 512 bytes per sector

* partition start from 63

N = mount partition = Start * block

Usage:

losetup /dev/loop0 disk.img -o N

mount /dev/loop0 /mnt/tmp

i.e.

# mount partition 1
# N = 63 x 512 = 32256

losetup /dev/loop0 disk.img -o 32256

mount /dev/loop0 /mnt/tmp

# END

umount /mnt

losetup -d /dev/loop0

 


bind mount

 

A bind mount is an alternate view of a directory tree.

A bind mount instead takes an existing directory tree and replicates it under a different point.

(除了 ro 外 owner, group 及 permission 都是一樣)

所以如果想用不同的 owner, group 及 permission, 就要用 bindfs

Usage

By fstab

/opt/var_log    /var/log    none    bind    0 0

By Cli - mount

mount --bind A C

mount --bind -o ro A B

 


Force un-mount

 

# -l – Lazy unmount. Detach the filesystem from the filesystem hierarchy now,

      and cleanup all references to the filesystem as soon as it is not busy anymore.

# -f – Force unmount

umount -f -l /mnt/myfolder

Opts

  • 0               成功 umount
  • 32             umount: /dev/sde: not mounted

 


remount

 

# 當 mount point 有人 Writer 時, 那不能 remount ro (即是對方不是 root)

mount -o remount,ro /mnt/data

mount: /mnt/data is busy

# 有 D opts 係唔可以 remount, i.e. xfs 的 pquota

mount -o remount,pquota /mnt/data

 

remount readonly

 

mount -o remount,ro /

"mount: / is busy"

解決多法

lsof /

vsftpd    10172 guwang    3w   REG    8,2 84310047 130941 /var/log/xferlog
screen     8100   root    5u   REG    8,2     4608 130823 /var/run/utmp
zabbix_ag  1433 zabbix    3w   REG    8,2        4 131579 /var/run/zabbix/zabbix_agentd.pid

找出有 "w" flag 的 proccess

lsof / | awk '$4 ~ /[0-9].*w/'

auditd      576       root    4w   REG  253,0    878458 17087583 /var/log/audit/audit.log
firewalld   628       root    3w   REG  253,0         0 33624257 /var/log/firewalld
rsyslogd    924       root    3w   REG  253,0     20050 33624258 /var/log/cron
rsyslogd    924       root    4w   REG  253,0    887146 33975068 /var/log/messages
rsyslogd    924       root    6w   REG  253,0     21831 33975069 /var/log/secure
rsyslogd    924       root    8w   REG  253,0      2574 33975070 /var/log/maillog
tuned       928       root    3w   REG  253,0     16971 17070394 /var/log/tuned/tuned.log

找出它們並 stop 它們

  • /etc/init.d/crond stop
  • /etc/init.d/rsyslog stop
  • /etc/init.d/mysqld stop
  • /etc/init.d/httpd stop
  • /etc/init.d/postfix stop
  • /etc/init.d/vsftpd stop

如果仍是 umount 唔到, 那問題是

This is caused by deleted files they are still used by a process.

To find out which processes use deleted files use the tool

You have to restart them to make the files are released.

 


check mountpoint

 

$ mountpoint /home

/home is a mountpoint

$ mountpoint /bin

/bin is not a mountpoint

 


mount by partitation label

 

[1]

tune2fs -L usb-disk1 /dev/sdh1

[2]

re-plug usb disk

[3]

ls -l /dev/disk/by-label/usb-disk1

/dev/disk/by-label/usb-disk1 -> ../../sdh1

 


其他

 

 

 

Creative Commons license icon Creative Commons license icon