mount掛載小技巧

   用文件掛載目錄,將目錄的數據寫入該文件中,文件拷貝出來後,可在其餘機器上再次進行掛載後,就會看到該文件中的數據。
node

 

[root@localhost file]# dd if=/dev/zero of=/test/part bs=1M count=500   #首先建立一個500M的                                                       文件,寫入0,將文件變爲分區app

500+0 records inide

500+0 records outoop

524288000 bytes (524 MB) copied, 5.15719 s, 102 MB/sui

  


[root@localhost file]# mkfs.ext4 /test/part              #指定分區格式,進行格式化spa

mke2fs 1.41.12 (17-May-2010)orm

/test/part is not a block special device.ip

Proceed anyway? (y,n) y   ci

Filesystem label=同步

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

128016 inodes, 512000 blocks

25600 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67633152

63 block groups

8192 blocks per group, 8192 fragments per group

2032 inodes per group

Superblock backups stored on blocks: 

8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409


Writing inode tables: done                            

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 34 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@localhost file]# mount /test/part /test/file                

mount: /test/part is not a block device (maybe try `-o loop'?)

[root@localhost file]# mount -o loop /test/part /test/file      #將文件掛載時,會提示loop                                                          選項,用此選項


/test/part              /test/file              ext4    loop            0 0

                                                                #若是在/etc/fstab下掛載                                                             時,將loop寫入掛載模式中


[root@localhost file1]# blkid /test/part                    #指定查看該文件,可看到UUID

/test/part: UUID="44f2f514-c291-4ce1-a9ab-7b5b631664cc" TYPE="ext4"



[root@localhost file]# touch 123.txt                #爲方便觀察,咱們建立123.txt文件

                    

[root@localhost test]# mount -o loop /test/part /test/file1  #咱們將該文件掛載到file1目錄


[root@localhost file1]# ls                        #此時,咱們看到file1目錄中有file目錄中                                              的123.txt,這就是part文件中的數據起了                                              做用

123.txt  lost+found



[root@localhost file]# ls                       #此時,file目錄中沒有了任何數據

[root@localhost file]# 


使用此方法,要注意,數據是寫在文件中,而不是在目錄上,隨着文件的轉移掛載,數據更改目錄,能夠把該文件當作一種移動存儲的介質。

注意:7版本的不須要添加loop選項。



[root@localhost file]# losetup /dev/loop3 /test/part      #指定part爲loop3

[root@localhost file]# losetup -a                         #查看loop

/dev/loop3: [fd00]:524294 (/test/part)

[root@localhost file]# mkdir /test/part2

[root@localhost file]# mount /dev/loop3 /test/part2        #將loop3掛載到part2目錄上

[root@localhost file]# mount                                #查看掛載結果

/dev/mapper/vg0-root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

/dev/mapper/vg0-usr on /usr type ext4 (rw)

/dev/mapper/vg0-var on /var type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

/dev/sdb1 on /test/ceshi type ext4 (rw,nosuid,acl)

/dev/loop3 on /test/part2 type ext4 (rw)









目錄掛載目錄方法:

mount -B或者--bind /test/file  /test/file1  








分區啓用swap

fdisk /dev/sdb

mkswap -L SWAP_SDB1 /dev/sdb1                  #-L是建立卷標

vi /etc/fstab

LABEL=SWAP_SDB1 swap swap defaults 0 0

swapon -s                                     #查看swap分區

swapon -a                                     #掛載寫入與mount -a效果同樣


swapon /dev/sdb1                              #臨時掛載


文件啓用swap

dd if=/dev/zero of=/testdir/swapfile bs=1M count=1024      #將文件改成分區

mkswap  /testdir/swapfile 

vi /etc/fstab

/testdir/swapfile   swap swap defaults 0 0

swapon -s cat /proc/swaps

swapon -a


刪除swap

swapoff /dev/sdb1 或swapoff /testdir/swapfile

刪除/etc/fstab相應記錄

刪除分區和文件



U盤掛載:

lsmod | grep usb   # 查看U盤模塊

sync     #同步三次

sync

sync

umount /mnt/usb  卸載U盤

相關文章
相關標籤/搜索