<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 練習 22:文件系統:移動數據,`tar`,`dd` > 原文:[Exercise 22. Filesystems: moving data around: tar, dd](https://archive.fo/JSknE) > 譯者:[飛龍](https://github.com/wizardforcel) > 協議:[CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/) > 自豪地采用[谷歌翻譯](https://translate.google.cn/) 現在是時候自己看看了,Linux 中的所有東西只是一個文件。 這個練習是一個很大的練習,但是看看你學到了什么。完成之后,在`man`中查看所有故意不解釋的程序參數,,并試圖自己解釋每個命令的作用。 現在你將學習如何玩轉數據。 ## 這樣做 ``` 1: tar -czvf root.tgz /opt/root/ 2: tar -tzvf root.tgz 3: cd /tmp 4: tar -zxvf ~/root.tgz 5: ls -al 6: dd_if=$(mount | grep /tmp | cut -d ' ' -f 1) && echo $dd_if 7: sudo dd if=$dd_if of=~/tmp.img bs=10M 8: cd && ls -alh 9: sudo losetup /dev/loop1 ~/tmp.img && sudo mount /dev/loop1 /mnt/ 10: ls -al /mnt 11: sudo umount /mnt && sudo losetup -d /dev/loop1 12: sudo umount $dd_if && sudo mkfs.ext3 $dd_if 13: new_uuid=$(sudo tune2fs -l $dd_if | awk '/UUID/{print $3}') && echo $new_uuid 14: grep '/tmp' /etc/fstab 15: sed "s/^UUID=.*\/tmp\s\+ext3\s\+defaults\s\+[0-9]\s\+[0-9]\s\?/UUID=$new_uuid \/tmp ext3 defaults 0 2/" /etc/fstab ``` 現在使用`sudo tune2fs -l`和`sudo blkid`檢查輸出。如果`/etc/fstab`中的 UUID 替換看起來正常,執行實際的替換。 ``` 16: sudo sed -i'.bak' "s/^UUID=.*\/tmp\s\+ext3\s\+defaults\s\+[0-9]\s\+[0-9]\s\?/UUID=$new_uuid \/tmp ext3 defaults 0 2/" /etc/fstab 17: sudo mount -a && ls /tmp 18: sudo umount /tmp && pv ~/tmp.img | sudo dd of=$dd_if bs=10M 19: new_uuid=$(sudo tune2fs -l $dd_if | awk '/UUID/{print $3}') && echo $new_uuid 20: sudo sed -i'.bak' "s/^UUID=.*\/tmp\s\+ext3\s\+defaults\s\+[0-9]\s\+[0-9]\s\?/UUID=$new_uuid \/tmp ext3 defaults 0 2/" /etc/fstab 21: sudo mount -a 22: rm -v tmp.img ``` 輸入`y`并按下`<ENTER>`。 ## 你會看到什么 ``` user1@vm1:~$ tar -czvf root.tgz /opt/root/ tar: Removing leading '/' from member names /opt/root/ /opt/root/bin/ /opt/root/bin/bash /opt/root/lib64/ /opt/root/lib64/ld-linux-x86-64.so.2 /opt/root/lib/ /opt/root/lib/libdl.so.2 /opt/root/lib/libncurses.so.5 /opt/root/lib/libc.so.6 user1@vm1:~$ tar -tzvf root.tgz drwxr-xr-x root/root 0 2012-07-05 03:14 opt/root/ drwxr-xr-x root/root 0 2012-07-05 03:14 opt/root/bin/ -rwxr-xr-x root/root 926536 2012-07-05 03:14 opt/root/bin/bash drwxr-xr-x root/root 0 2012-07-05 03:14 opt/root/lib64/ -rwxr-xr-x root/root 128744 2012-07-05 03:14 opt/root/lib64/ld-linux-x86-64.so.2 drwxr-xr-x root/root 0 2012-07-05 03:14 opt/root/lib/ -rw-r--r-- root/root 14696 2012-07-05 03:14 opt/root/lib/libdl.so.2 -rw-r--r-- root/root 286776 2012-07-05 03:14 opt/root/lib/libncurses.so.5 -rwxr-xr-x root/root 1437064 2012-07-05 03:14 opt/root/lib/libc.so.6 user1@vm1:~$ cd /tmp user1@vm1:/tmp$ tar -zxvf ~/root.tgz opt/root/ opt/root/bin/ opt/root/bin/bash opt/root/lib64/ opt/root/lib64/ld-linux-x86-64.so.2 opt/root/lib/ opt/root/lib/libdl.so.2 opt/root/lib/libncurses.so.5 opt/root/lib/libc.so.6 user1@vm1:/tmp$ ls -al total 19 drwxrwxrwt 6 root root 1024 Jul 5 04:17 . drwxr-xr-x 22 root root 1024 Jul 3 08:29 .. drwxrwxrwt 2 root root 1024 Jul 3 08:41 .ICE-unix drwx------ 2 root root 12288 Jul 3 07:47 lost+found drwxr-xr-x 3 user1 user1 1024 Jul 5 03:24 opt -rw-r--r-- 1 root root 489 Jul 3 10:14 sources.list -r--r----- 1 root root 491 Jul 3 10:21 sudoers drwxrwxrwt 2 root root 1024 Jul 3 08:41 .X11-unix user1@vm1:/tmp$ dd_if=$(mount | grep /tmp | cut -d ' ' -f 1) && echo $dd_if /dev/sda8 user1@vm1:~$ cd && ls -alh total 243M drwxr-xr-x 3 user1 user1 4.0K Jul 5 04:27 . drwxr-xr-x 4 root root 4.0K Jul 3 08:39 .. -rw------- 1 user1 user1 22 Jul 3 10:45 .bash_history -rw-r--r-- 1 user1 user1 220 Jul 3 08:39 .bash_logout -rw-r--r-- 1 user1 user1 3.2K Jul 3 08:39 .bashrc -rw------- 1 user1 user1 52 Jul 5 04:12 .lesshst drwxr-xr-x 3 user1 user1 4.0K Jul 5 03:23 opt -rw-r--r-- 1 user1 user1 675 Jul 3 08:39 .profile -rw-r--r-- 1 user1 user1 1.3M Jul 5 04:25 root.tgz -rw-r--r-- 1 root root 241M Jul 5 04:36 tmp.img user1@vm1:~$ sudo losetup /dev/loop1 ~/tmp.img && sudo mount /dev/loop1 /mnt/ user1@vm1:~$ ls -al /mnt total 19 drwxrwxrwt 6 root root 1024 Jul 5 04:17 . drwxr-xr-x 22 root root 1024 Jul 3 08:29 .. drwxrwxrwt 2 root root 1024 Jul 3 08:41 .ICE-unix drwx------ 2 root root 12288 Jul 3 07:47 lost+found drwxr-xr-x 3 user1 user1 1024 Jul 5 03:24 opt -rw-r--r-- 1 root root 489 Jul 3 10:14 sources.list -r--r----- 1 root root 491 Jul 3 10:21 sudoers drwxrwxrwt 2 root root 1024 Jul 3 08:41 .X11-unix user1@vm1:~$ sudo umount /mnt && sudo losetup -d /dev/loop1 user1@vm1:~$ sudo umount $dd_if && sudo mkfs.ext3 $dd_if mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 61752 inodes, 246784 blocks 12339 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 31 block groups 8192 blocks per group, 8192 fragments per group 1992 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. user1@vm1:~$ new_uuid=$(sudo tune2fs -l $dd_if | awk '/UUID/{print $3}') && echo $new_uuid f8288adc-3ef9-4a6e-aab2-92624276b8ba user1@vm1:~$ grep '/tmp' /etc/fstab # /tmp was on /dev/sda8 during installation UUID=011b4530-e4a9-4d13-926b-48d9e33b64bf /tmp ext3 defaults 0 2 user1@vm1:~$ sed "s/^UUID=.*\/tmp\s\+ext3\s\+defaults\s\+[0-9]\s\+[0-9]\s\?/UUID=$new_uuid \/tmp ext3 defaults 0 2/" /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # / was on /dev/sda1 during installation UUID=91aacf33-0b35-474c-9c61-311e04b0bed1 / ext3 errors=remount-ro 0 1 # /home was on /dev/sda9 during installation UUID=e27b0efb-8cf0-439c-9ebe-d59c927dd590 /home ext3 defaults 0 2 # /tmp was on /dev/sda8 during installation UUID=f8288adc-3ef9-4a6e-aab2-92624276b8ba /tmp ext3 defaults 0 2 # /usr was on /dev/sda5 during installation UUID=9f49821b-7f94-4915-b9a9-ed9f12bb6847 /usr ext3 defaults 0 2 # /var was on /dev/sda6 during installation UUID=b7e908a1-a1cd-4d5c-bc79-c3a99d003e7c /var ext3 defaults 0 2 # swap was on /dev/sda7 during installation UUID=292981d7-5a17-488f-8d9a-176b65f45d46 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0 sudo sed -i'.bak' "s/^UUID=.*\/tmp\s\+ext3\s\+defaults\s\+[0-9]\s\+[0-9]\s\?/UUID=$new_uuid \/tmp ext3 defaults 0 2/" /etc/fstab sudo mount -a && ls /tmp user1@vm1:~$ sudo umount /tmp && pv ~/tmp.img | sudo dd of=$dd_if bs=10M 241MB 0:00:04 [54.2MB/s] [===============================================================================================================>] 100% 0+1928 records in 0+1928 records out 252706816 bytes (253 MB) copied, 5.52494 s, 45.7 MB/s user1@vm1:~$ rm -v tmp.img rm: remove write-protected regular file `tmp.img'? y removed `tmp.img' user1@vm1:~$ ``` ## 解釋 1. 在你的主目錄中創建歸檔或`/opt/root/`。歸檔文件的擴展名是`.tgz`,因為這個歸檔實際上由兩部分組成,就像是俄羅斯套娃。第一部分由字母`t`指定,是一個大文件,其中所有歸檔文件由程序`tar`合并。第二部分由字母`gz`指定 ,意味著`tar`調用`gzip`程序來壓縮它。 1. 測試這個歸檔。 1. 將目錄更改為`/tmp`。 1. 解壓你的歸檔。 1. 打印目錄內容。 1. 提取掛載在`/tmp`上的分區的名稱,將其存儲在`dd_if`變量中,如果提取成功,打印出`dd_if`值。`if`代表輸入文件。 1. 將整個分區復制到你的主目錄中的`tmp.img`。dd 使用超級用戶調用,因為你正在訪問代表你的分區的文件`/dev/sda8`,該分區對普通用戶不可訪問。 1. 將目錄更改為你的主目錄并打印出其內容。 1. 告訴 Linux 將`tmp.img`文件用作(一種)物理分區并掛載它。 1. 打印出`tmp.img`的內容。你可以看到它真的是`/tmp`的精確副本 。 1. 1. 解除掛載`tmp.img`,并告訴 Linux 停止將其看做分區。 1. 解除掛載`/tmp`并在那里創建新的文件系統,刪除該過程中的所有東西。 1. 提取你的新`/tmp`文件系統的UUID ,將其存儲在`new_uuid`中,并打印出來。 1. 從`/etc/fstab`中打印描述舊的`/tmp`分區的一行。 1. 向你展示,修改后的`/etc/fstab`如何工作。通過使用正則表達式來完成,這個表達式用作掩碼,定義了這一行: ``` UUID=f8288adc-3ef9-4a6e-aab2-92624276b8ba /tmp ext3 defaults 0 2 ``` 完成這本書后,我會給你一個鏈接,讓你學習如何創建這樣的正則表達式。 1. 使用新的 UUID 實際替換`/tmp`舊的 UUID。 1. 掛載`/etc/fstab`中描述的所有文件系統,并列出新`/tmp`的內容 1. 解除掛載新的`/tmp`并從`tmp.img`恢復舊`/tmp`。 1. 獲取舊`/tmp`的 UUID,它實際上與創建新文件系統之前相同,因為`tmp.img`是舊的`/ tmp`的完美副本。 1. 在`/etc/fstab`中用舊的 UUID 替換新的 UUID 。 1. 從`/etc/fstab`掛載所有文件系統。如果此命令不會導致錯誤,你可能一切正常。恭喜。 1. 從你的主目錄中刪除`tmp.img`。 ## 附加題 + 嘗試詳細解釋每個命令的作用。拿出一張紙,把它全部寫出來。在`man`中查找在所有不能很好理解的命令和參數。 + 這個有些過早了,但為什么你能作為`user1`來發出刪除命令,從你的主目錄中刪除`tmp.img`,考慮到`tmp.img`由 root 創建?
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看