中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

兼職網(wǎng)站開發(fā)全部視頻支持代表手機瀏覽器

兼職網(wǎng)站開發(fā),全部視頻支持代表手機瀏覽器,模板網(wǎng)站缺點,軟件外包開發(fā)保密協(xié)議文章目錄 [GParted 中已清除的分區(qū)與未格式化的分區(qū)](https://superuser.com/questions/706624/cleared-vs-unformatted-partition-in-gparted)創(chuàng)建加密分區(qū)解密創(chuàng)建的加密分區(qū)以便掛載格式化設備未具體的格式(這里為ext4格式)創(chuàng)建掛載點目錄掛載加密的文…

文章目錄

  • [GParted 中已清除的分區(qū)與未格式化的分區(qū)](https://superuser.com/questions/706624/cleared-vs-unformatted-partition-in-gparted)
          • 創(chuàng)建加密分區(qū)
          • 解密創(chuàng)建的加密分區(qū)以便掛載
          • 格式化設備未具體的格式(這里為ext4格式)
          • 創(chuàng)建掛載點目錄
          • 掛載加密的文件系統(tǒng)
          • 查看映射設備的狀態(tài)
          • 查看是否掛載成功
      • 設置開機自動掛載
      • 解除開機自動掛載
    • 關閉自動掛載,并且重啟系統(tǒng)后
      • 理論
      • 具體操作 (驗證加密)
        • 剛開機的時候查看加載卷
        • 解鎖(打開設備)
        • 重新掛載
        • 查看掛載目錄
        • 在掛載目錄寫一個文件
        • 卸載掛載文件夾 和關閉映射設備
        • 全部操作一覽
      • 如果是文件,如何驗證cryptsetup的加密功能
        • **創(chuàng)建一個加密卷**:
        • **打開加密卷并掛載**:
        • **寫入和讀取數(shù)據(jù)**:
        • **卸載并關閉加密卷**:
        • **驗證加密**:
        • **重新打開和驗證數(shù)據(jù)**:
        • 補充

假設A分區(qū)是系統(tǒng)分區(qū)100G,剩余70G,我想將剩余其中的10G空間擇出來,創(chuàng)建 一個新分區(qū)。 可以使用 gparted-live-1.5.0-6-amd64 (1).iso

要使用 gparted-live-1.5.0-6-amd64 (1).iso,你可以按照以下步驟操作:

  1. 下載 ISO 文件
    如果你還沒有下載 gparted-live-1.5.0-6-amd64 (1).iso 文件,首先從官方源或其他可信源下載。

  2. 創(chuàng)建可啟動媒介
    創(chuàng)建一個可啟動的 USB 或 DVD,將 gparted-live-1.5.0-6-amd64 (1).iso 文件寫入其中。以下是使用 Rufus(在 Windows 上)和 dd(在 Linux 上)創(chuàng)建可啟動 USB 的方法:

    • 使用 Rufus(Windows)

      • 插入一個空白的 USB 驅動器。
      • 打開 Rufus 工具。
      • 在 “設備” 列表中選擇你的 USB 驅動器。
      • 點擊 “選擇” 按鈕,瀏覽并選擇 gparted-live-1.5.0-6-amd64 (1).iso 文件。
      • 確保 “boot selection” 選擇了 “DD Image”。
      • 點擊 “開始” 按鈕,等待過程完成。
    • 使用 dd(Linux)

      • 插入一個空白的 USB 驅動器。
      • 找到你的 USB 驅動器設備名,通常為 /dev/sdX,其中 X 是代表驅動器的字母(如 sdb)。
      • 使用以下命令寫入 ISO 文件,替換 X 為你的實際設備名:
        sudo dd if=gparted-live-1.5.0-6-amd64\ \(1\).iso of=/dev/sdX bs=4M status=progress oflag=sync
        
        注意:確保你正確識別了 USB 設備名,錯誤的操作可能會導致數(shù)據(jù)丟失。
  3. 設置 BIOS/UEFI 啟動順序

    • 重啟電腦,并在開機時進入 BIOS/UEFI 設置界面(通常是按 F2、F10、Delete 或其他特定鍵,具體取決于你的電腦型號)。
    • 在 BIOS/UEFI 設置中找到 “啟動選項” 或類似的菜單。
    • 將 USB 驅動器設置為優(yōu)先啟動設備。
    • 保存更改并退出 BIOS/UEFI 設置。
  4. 啟動 GParted Live

    • 電腦將會從 USB 驅動器啟動,并加載 GParted Live 環(huán)境。
    • 選擇合適的語言和其他選項(如果有)。
    • 等待 GParted 圖形界面加載。

現(xiàn)在,你已經(jīng)在 GParted Live 環(huán)境中,可以使用 GParted 工具來管理你的磁盤分區(qū),包括創(chuàng)建、調整大小、刪除、格式化等操作。請注意,在進行任何修改之前,最好先備份重要數(shù)據(jù),以防意外情況發(fā)生。

在 VMware 虛擬機中的 Linux 系統(tǒng)中使用 GParted Live,可以按照以下步驟操作:

  1. 下載 GParted Live ISO 文件
    從 GParted 官方網(wǎng)站或其他可信源下載 gparted-live-1.5.0-6-amd64 (1).iso 文件。

  2. 在 VMware 中添加虛擬光驅

    • 關閉你的 Linux 虛擬機。
    • 在 VMware 中,選擇你的 Linux 虛擬機,然后點擊 “設置”(或 “Configuration”)按鈕。
    • 在設置窗口中,選擇 “硬件”(或 “Hardware”)選項卡。
    • 找到并點擊 “添加”(或 “Add”)按鈕,然后選擇 “CD/DVD 驅動器”(或 “CD/DVD Drive”)。
    • 在新出現(xiàn)的 CD/DVD 驅動器設置中,選擇 “使用 ISO 映像文件”(或 “Use ISO image file”),然后瀏覽并選擇你下載的 gparted-live-1.5.0-6-amd64 (1).iso 文件。
    • 確保在連接選項中選擇了 “啟動時連接”(或 “Connect at power on”)。
  3. 配置虛擬機引導順序

    • 在相同的設置窗口中,找到并選擇 “硬盤”(或 “Hard Disk”)選項。
    • 確保你的虛擬機硬盤位于引導設備列表的首位。
  4. 啟動虛擬機并進入 GParted Live

    • 啟動你的 Linux 虛擬機。
    • 在開機過程中,虛擬機應該會自動從 GParted Live ISO 文件啟動。
    • 選擇合適的語言和其他選項(如果有)。
    • 等待 GParted 圖形界面加載。

現(xiàn)在,你已經(jīng)在 GParted Live 環(huán)境中,可以使用 GParted 工具來管理你的虛擬機磁盤分區(qū)。請注意,在進行任何修改之前,最好先備份重要數(shù)據(jù),以防意外情況發(fā)生。由于你在虛擬機環(huán)境中,你可以輕松地創(chuàng)建快照或備份整個虛擬機以確保數(shù)據(jù)安全。

延長vmware 虛擬機的啟動時間,方便我們按鍵進入bios

虛擬機啟動時,等到它顯示press F2 to enter setup …
它顯示太快,我們根本看不清它顯示的什么,也來不及按F2就過去了, 我們需要延長虛擬機啟動時間,讓我們有一個反應時間

方法如下:
1、關閉虛擬機,找到虛擬機系統(tǒng)的存放目錄(注:不是虛擬機這個軟件的安裝目錄),然后進入到相應系統(tǒng)的文件夾。
舉例:例如WIN7系統(tǒng),找到win7的文件夾,
2. 用記事本打開一個.vmx的文件(win7.vmx),在最后加入一行
bios.bootDelay = “5000”,其中5000為5秒的意思。

關于 如何格式化新分區(qū)作為待加密分區(qū)

GParted 中已清除的分區(qū)與未格式化的分區(qū)

我正在運行一個類似數(shù)據(jù)庫的應用程序,它直接在原始塊設備中寫入和讀取數(shù)據(jù)。我想為此創(chuàng)建一個新分區(qū),我正在使用 GParted。我已經(jīng)成功地縮小了我的常規(guī) linux 分區(qū),現(xiàn)在我可以看到可用空間列為“未分配”。Gparted 允許您選擇將此空間格式化為“未格式化”或“清除”。我不明白他們的區(qū)別。

在GParted手冊中,是這樣說的:

  • cleared 可用于清除任何現(xiàn)有的文件系統(tǒng)簽名,并確保將分區(qū)識別為空。
  • unformatted 可用于創(chuàng)建分區(qū)而不編寫文件系統(tǒng)。

我找不到任何關于它們差異的詳細說明。有人可以解釋一下嗎?此外,在寫入和讀取分區(qū)時,是否會對分區(qū)的可靠性或性能產(chǎn)生任何影響?其中一個更適合我的目的嗎?將分區(qū)保持“未分配”狀態(tài)是否有任何影響?謝謝!

添加評論

不幸的是,這兩個選項與其他以不同方式起作用的選項一起列出。其他選項是所有文件系統(tǒng)格式,其中新分區(qū)是使用所選格式創(chuàng)建的。這兩個感興趣的選項實質上是兩個空選項。

  • 如果將分區(qū)“未格式化”,則根本不會嘗試將文件系統(tǒng)數(shù)據(jù)結構寫入其中。但它可能已經(jīng)擁有它們,無論是偶然的還是有意的。
  • 如果“清除”了一個分區(qū),那么操作系統(tǒng)用來檢測文件系統(tǒng)類型的已知位置的各種簽名就會被擦除。

因此,頗具諷刺意味的是,清除分區(qū)將保證它因此未格式化,而未格式化的分區(qū)可能會像以前一樣保持格式化。

創(chuàng)建加密分區(qū)
x@x:~$ ls /dev/sda*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4

其中sda4是之前創(chuàng)建的分區(qū)(未掛載)

x@x:~$ sudo su
root@x:/home/x# cryptsetup luksFormat /dev/sda4WARNING!
========
This will overwrite data on /dev/sda4 irrevocably.Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for /dev/sda4: 
Verify passphrase: 
root@x:/home/x# 
解密創(chuàng)建的加密分區(qū)以便掛載
x@x:~$ sudo su
root@x:/home/x# cryptsetup luksFormat /dev/sda4WARNING!
========
This will overwrite data on /dev/sda4 irrevocably.Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for /dev/sda4: 
Verify passphrase: 
root@x:/home/x# cryptsetup luksOpen /dev/sda4 my_encrypted_fs
Enter passphrase for /dev/sda4: 
root@x:/home/x# 

這將創(chuàng)建一個名為my_encrypted_fs的映射設備(映射到 /dev/mapper),你可以像對待普通磁盤分區(qū)一樣對其進行格式化和掛載。

格式化設備未具體的格式(這里為ext4格式)
root@x:/home/x# mkfs.ext4 /dev/mapper/my_encrypted_fs 
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 2617088 4k blocks and 655360 inodes
Filesystem UUID: 5c6e9946-d58d-42cd-adbb-b0dc0a4404ce
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 
創(chuàng)建掛載點目錄

mkdir /mnt/encrypted_fs_mntroot@x:/home/x# ls /mnt
encryped_fs  encrypted_fs_mnt
掛載加密的文件系統(tǒng)
root@x:/home/x# mount /dev/mapper/my_encrypted_fs  /mnt/encrypted_fs_mnt/
查看映射設備的狀態(tài)
root@x:/home/x# cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is active and is in use.type:    LUKS2cipher:  aes-xts-plain64keysize: 512 bitskey location: keyringdevice:  /dev/sda4sector size:  512offset:  32768 sectorssize:    20936704 sectorsmode:    read/write
root@x:/home/x# 

知識點補充:

/dev/mapper/my_encrypted_fs 是一個邏輯設備文件,它代表了一個使用 cryptsetup 工具和 LUKS 加密格式加密的存儲設備。

當一個物理存儲設備(如硬盤分區(qū))被用 LUKS 格式加密后,它會被映射到一個 /dev/mapper/ 下的邏輯設備名。在這個例子中,邏輯設備名為 my_encrypted_fs

" /dev/mapper/my_encrypted_fs is inactive. " 這個消息表示當前這個加密的邏輯設備并未被解鎖和激活。也就是說,雖然物理存儲設備存在,但由于它處于加密狀態(tài)且未提供正確的解鎖密碼或密鑰,操作系統(tǒng)無法訪問其上的數(shù)據(jù)。

要訪問這個加密卷上的數(shù)據(jù),你需要先使用 cryptsetup 提供正確的密碼或密鑰來解鎖它,然后將其掛載到一個目錄下才能進行讀寫操作。

當使用 cryptsetup luksOpen 輸入密碼打開后, /dev/mapper/my_encrypted_fs is inactive. 就變成 /dev/mapper/my_encrypted_fs is active

root@x:/home/x# cryptsetup luksOpen /dev/sda4 my_encrypted_fs
Enter passphrase for /dev/sda4: 
root@x:/home/x# cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is active.type:    LUKS2cipher:  aes-xts-plain64keysize: 512 bitskey location: keyringdevice:  /dev/sda4sector size:  512offset:  32768 sectorssize:    20936704 sectorsmode:    read/write
查看是否掛載成功
root@x:/home/x# df -Th | tail -1 
/dev/mapper/my_encrypted_fs ext4   9.8G   24K  9.3G   1% /mnt/encrypted_fs_mnt

設置開機自動掛載

  1. 打開 /etc/crypttab 文件

    sudo vim /etc/crypttab
    
  2. 添加新的映射關系
    在文件中添加一個新的行,指定加密設備、映射名稱、密碼和任何其他選項。例如:

    my_encrypted_fs /dev/sda4 none luks,discard
    

    這里,

    • encrypted_fs 是映射名稱。
    • /dev/sda4 是加密設備。
    • none 表示密碼將通過交互式提示輸入。
    • luks,discard 是選項,luks 指定了 LUKS 加密格式,discard 則啟用 TRIM 支持(如果硬件支持)。
  3. 更新 initramfs
    更新 initramfs 以包含新的加密卷配置:

    sudo update-initramfs -u
    
    root@x:/home/x# vim /etc/crypt
    cryptsetup-initramfs/ crypttab              
    root@x:/home/x# vim /etc/crypttab 
    root@x:/home/x# sudo update-initramfs -u
    update-initramfs: Generating /boot/initrd.img-6.2.0-39-generic
    root@x:/home/x# 
    
  4. 重啟系統(tǒng)并驗證掛載
    重啟你的系統(tǒng),然后檢查加密卷是否已經(jīng)被自動解鎖和掛載:

    mount | grep my_encrypted_fs
    

通過修改 /etc/crypttab 并更新 initramfs,

外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳

外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳

解除開機自動掛載

要取消開機自動掛載一個之前設置為自動掛載的加密卷,你可以按照以下步驟操作:

  1. 編輯 /etc/crypttab 文件

    sudo vim /etc/crypttab
    
  2. 注釋或刪除對應的行
    /etc/crypttab 文件中,找到與你想取消自動掛載的加密卷相關的行。通常,這行會包含映射設備名(如 encrypted_fs)、物理設備路徑(如 /dev/sda4)以及可能的密碼或選項。要取消自動掛載,你可以選擇以下任一方法:

    • 注釋該行:在該行前面添加 # 字符,將這一行變?yōu)樽⑨屝?#xff0c;例如:
      #my_encrypted_fs /dev/sda4 none luks,discard
      
    • 刪除該行:如果你確定不再需要自動掛載這個加密卷,可以直接刪除整行。
  3. 更新 initramfs
    在修改 /etc/crypttab 文件后,你需要更新 initramfs 以反映這些更改:

    sudo update-initramfs -u
    
    x@x:~$ sudo vim /etc/crypttab 
    [sudo] password for x: 
    x@x:~$ sudo update-initramfs  -u
    update-initramfs: Generating /boot/initrd.img-6.2.0-39-generic
    x@x:~$ cat /etc/crypttab 
    # <target name>	<source device>		<key file>	<options>
    #my_encrypted_fs /dev/sda4 none luks,discard
    x@x:~$ 
  4. 重啟系統(tǒng)并驗證更改
    重啟你的系統(tǒng),然后檢查是否還在啟動時自動解鎖和掛載該加密卷。你可以通過以下命令查看已掛載的文件系統(tǒng):

    mount | grep my_encrypted_fs
    

    如果該加密卷不再出現(xiàn)在列表中,說明取消自動掛載成功。

請注意,如果你在 /etc/fstab 中也有關于這個加密卷的掛載配置,你也應該相應地更新或刪除那個配置,以防止在手動解鎖和掛載加密卷后系統(tǒng)再次自動掛載它。


關閉自動掛載,并且重啟系統(tǒng)后

理論

如果你關閉了開機自動掛載一個加密卷,并且隨后重啟了系統(tǒng),以下將會發(fā)生:

  1. 啟動過程中不會解鎖和掛載加密卷
    由于你在 /etc/crypttab 文件中取消了自動掛載設置,并更新了 initramfs,系統(tǒng)在啟動過程中將不再嘗試自動解鎖和掛載該加密卷。

  2. 加密卷保持鎖定狀態(tài)
    加密卷將繼續(xù)保持鎖定狀態(tài),這意味著數(shù)據(jù)在沒有正確密碼或密鑰的情況下是不可讀的。

  3. 無法直接訪問加密卷上的數(shù)據(jù)
    由于加密卷未被掛載,你將無法直接訪問其上的文件和目錄。如果你嘗試掛載該加密卷,你需要首先使用 cryptsetup 提供正確的密碼或密鑰來解鎖它。

  4. 手動解鎖和掛載加密卷
    如果你需要訪問加密卷上的數(shù)據(jù),你需要手動執(zhí)行以下步驟:

    cryptsetup luksOpen /dev/sda4 my_encrypted_fs
    mkdir -p /mnt/encrypted_fs_mnt
    mount /dev/mapper/my_encrypted_fs /mnt/encrypted_fs_mnt
    

    這里,/dev/sda4 是你的加密設備,my_encrypted_fs 是你的映射設備名,/mnt/encrypted_fs_mnt 是你希望掛載加密卷的目錄。

  5. 使用加密卷
    在手動解鎖和掛載加密卷后,你現(xiàn)在可以像平常一樣訪問和操作 /mnt/encrypted_fs_mnt 下的數(shù)據(jù)。

  6. 卸載和關閉加密卷
    當你完成對加密卷的訪問后,記得卸載并關閉它以確保數(shù)據(jù)安全:

    umount /mnt/my_encrypted_fs
    cryptsetup luksClose my_encrypted_fs
    

總的來說,關閉開機自動掛載后重啟系統(tǒng),會導致系統(tǒng)不再自動處理加密卷的解鎖和掛載,你需要手動進行這些操作來訪問加密卷上的數(shù)據(jù)。


具體操作 (驗證加密)

剛開機的時候查看加載卷
x@x:~$ cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is inactive.

當你在剛開機的時候執(zhí)行 cryptsetup status /dev/mapper/my_encrypted_fs 并得到 “is inactive” 的結果,這表示 /dev/mapper/my_encrypted_fs 這個加密卷當前并未被打開或掛載。

在系統(tǒng)啟動過程中,如果一個加密卷沒有設置為自動解鎖和掛載,那么它會保持鎖定狀態(tài),直到你使用正確的密碼或密鑰通過 cryptsetup 手動解鎖它。

解鎖(打開設備)
x@x:~$ cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is inactive.
x@x:~$ cryptsetup luksOpen /dev/sda4 my_encrypted_fs
Device /dev/sda4 does not exist or access denied.
x@x:~$ sudo su
[sudo] password for x: 
root@x:/home/x# cryptsetup luksOpen /dev/sda4 my_encrypted_fs
Enter passphrase for /dev/sda4: 
root@x:/home/x# cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is active.type:    LUKS2cipher:  aes-xts-plain64keysize: 512 bitskey location: keyringdevice:  /dev/sda4sector size:  512offset:  32768 sectorssize:    20936704 sectorsmode:    read/write
root@x:/home/x# 
重新掛載
root@x:/home/x# mkdir -p /mnt/encrypted_fs_mnt
root@x:/home/x# mount /dev/mapper/my_encrypted_fs /mnt/encrypted_fs_mnt
root@x:/home/x# 
查看掛載目錄
root@x:/mnt# tree /mnt
/mnt
└── encrypted_fs_mnt└── lost+found
`lost+found` 是一個在 Linux 文件系統(tǒng)中常見的目錄,它存在于每個文件系統(tǒng)的根目錄下。這個目錄的主要目的是存儲在文件系統(tǒng)發(fā)生錯誤(如突然斷電、系統(tǒng)崩潰或其他可能導致文件系統(tǒng)損壞的情況)時恢復的不完整或孤立的文件。當文件系統(tǒng)在掛載時進行檢查(例如通過 `fsck` 命令),如果檢測到任何不完整的數(shù)據(jù)塊或者無法定位到其原始位置的文件,這些數(shù)據(jù)會被移動到 `lost+found` 目錄中。這樣,用戶或者系統(tǒng)管理員就有機會檢查這些文件,看看是否能恢復其中的重要數(shù)據(jù)。在你的例子中,`/mnt/encrypted_fs_mnt/lost+found` 目錄是在 `/mnt/encrypted_fs_mnt` 文件系統(tǒng)根目錄下創(chuàng)建的。即使這個文件系統(tǒng)是加密的,`lost+found` 目錄仍然會被創(chuàng)建,以備在文件系統(tǒng)出現(xiàn)錯誤時恢復可能丟失的數(shù)據(jù)。通常情況下,如果你的系統(tǒng)運行正常且沒有經(jīng)歷過導致文件系統(tǒng)損壞的事件,`lost+found` 目錄應該是空的。但是,建議定期備份重要數(shù)據(jù),并在必要時檢查 `lost+found` 目錄中的內容,以確保沒有重要的文件被錯誤地移動到這里。
在掛載目錄寫一個文件
root@x:/mnt# vim testfile
root@x:/mnt/encrypted_fs_mnt# tree
.
├── lost+found
└── testfileroot@x:/mnt/encrypted_fs_mnt# cat testfile 
1
2
3
4
5
6
7
8
9
0
卸載掛載文件夾 和關閉映射設備
root@x:/mnt# umount /mnt/encrypted_fs_mnt/
root@x:/mnt# cryptsetup luksClose my_encrypted_fs
Device encrypted_fs_mnt/ is not active.
root@x:/mnt# 

當你處在該卷中時,你將無法卸載改卷

root@x:/mnt/encrypted_fs_mnt# umount /mnt/encrypted_fs_mnt/
umount: /mnt/encrypted_fs_mnt/: target is busy.
root@x:/mnt/encrypted_fs_mnt# umount /mnt/encrypted_fs_mnt/
umount: /mnt/encrypted_fs_mnt/: target is busy.
root@x:/mnt/encrypted_fs_mnt# cd ..
root@x:/mnt# umount /mnt/encrypted_fs_mnt/
root@x:/mnt# 

卸載之后

root@x:/mnt# tree encrypted_fs_mnt/
encrypted_fs_mnt/0 directories, 0 files
全部操作一覽
x@x:~$ cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is inactive.
x@x:~$ sudo su
[sudo] password for x: 
root@x:/home/x#  cryptsetup luksOpen /dev/sda4 my_encrypted_fs
Enter passphrase for /dev/sda4: 
root@x:/home/x# cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is active.type:    LUKS2cipher:  aes-xts-plain64keysize: 512 bitskey location: keyringdevice:  /dev/sda4sector size:  512offset:  32768 sectorssize:    20936704 sectorsmode:    read/write
root@x:/home/x# mount /dev/mapper/my_encrypted_fs /mnt/encrypted_fs_mnt
root@x:/home/x# tree /mnt
/mnt
└── encrypted_fs_mnt├── lost+found└── testfile2 directories, 1 file
root@x:/home/x# cd /mnt/encrypted_fs_mnt/
root@x:/mnt/encrypted_fs_mnt# ls
lost+found  testfile
root@x:/mnt/encrypted_fs_mnt# rm testfile
root@x:/mnt/encrypted_fs_mnt# ls
lost+found
root@x:/mnt/encrypted_fs_mnt# 
root@x:/mnt/encrypted_fs_mnt# vim testfile.c
root@x:/mnt/encrypted_fs_mnt# ls
lost+found  testfile.c
root@x:/mnt/encrypted_fs_mnt# cat testfile.c 
#include<>
{
int a;}
root@x:/mnt/encrypted_fs_mnt# tree
.
├── lost+found
└── testfile.c1 directory, 1 file
root@x:/mnt/encrypted_fs_mnt# cd ../
root@x:/mnt# ls
encrypted_fs_mnt
root@x:/mnt# cryptsetup status /dev/mapper/my_encrypted_fs 
/dev/mapper/my_encrypted_fs is active and is in use.type:    LUKS2cipher:  aes-xts-plain64keysize: 512 bitskey location: keyringdevice:  /dev/sda4sector size:  512offset:  32768 sectorssize:    20936704 sectorsmode:    read/write
root@x:/mnt# umount /mnt/encrypted_fs_mnt/
root@x:/mnt# cryptsetup luksClose my_encrypted_fs
root@x:/mnt# tree encrypted_fs_mnt/
encrypted_fs_mnt/0 directories, 0 files
root@x:/mnt# cd encrypted_fs_mnt/
root@x:/mnt/encrypted_fs_mnt# ls
root@x:/mnt/encrypted_fs_mnt# 

如果是文件,如何驗證cryptsetup的加密功能

驗證 cryptsetup 的加密功能可以通過以下幾個步驟進行:

創(chuàng)建一個加密卷

首先,使用 cryptsetup 創(chuàng)建一個新的加密卷。這可以是一個文件或一個磁盤分區(qū)。以下是一個創(chuàng)建基于文件的加密卷的例子:

dd if=/dev/zero of=myencryptedfile bs=1M count=1000
cryptsetup luksFormat myencryptedfile

這將創(chuàng)建一個名為 myencryptedfile 的 1 GB 大小的文件,并使用 LUKS 格式對其進行加密。

root@x:/mnt# cd encrypted_fs_mnt/
root@x:/mnt/encrypted_fs_mnt# ls
root@x:/mnt/encrypted_fs_mnt# 
root@x:/mnt/encrypted_fs_mnt# cd ~
root@x:~# dd if=/dev/zero of=myencryptedfile bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.878107 s, 1.2 GB/s
root@x:~# cryptsetup luksFormat myencryptedfileWARNING!
========
This will overwrite data on myencryptedfile irrevocably.Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for myencryptedfile: 
Verify passphrase: 
root@x:~# ls
Desktop  myencryptedfile  snap  Templates  模板
root@x:~# 
打開加密卷并掛載

使用 cryptsetup 打開加密卷,并將其映射到一個新的設備(例如 /dev/mapper/myencrypted),然后格式化并掛載這個新設備:

cryptsetup luksOpen myencryptedfile myencrypted
mkfs.ext4 /dev/mapper/myencrypted
mkdir /mnt/encryptedvolume
mount /dev/mapper/myencrypted /mnt/encryptedvolume
root@x:~# ls
Desktop  myencryptedfile  snap  Templates  模板
root@x:~# cryptsetup luksOpen myencryptedfile myencrypted
Enter passphrase for myencryptedfile: 
root@x:~# mkfs.ext4 /dev/mapper/myencrypted
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 251904 4k blocks and 62976 inodes
Filesystem UUID: d7f76557-c6d2-4b1e-af4e-91409e067a17
Superblock backups stored on blocks: 32768, 98304, 163840, 229376Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: doneroot@x:~# mkdir /mnt/encryptedvolume
root@x:~# mount /dev/mapper/myencrypted /mnt/encryptedvolume
root@x:~# 
寫入和讀取數(shù)據(jù)

在掛載點 /mnt/encryptedvolume 寫入一些測試數(shù)據(jù):

echo "This is a test message." > /mnt/encryptedvolume/testfile.txt
cat /mnt/encryptedvolume/testfile.txt

確保你可以正確地讀取寫入的數(shù)據(jù)。

root@x:~# echo "This is a test message." > /mnt/encryptedvolume/testfile.txt
root@x:~# cat /mnt/encryptedvolume/testfile.txt
This is a test message.
root@x:~#  
卸載并關閉加密卷

卸載加密卷,并使用 cryptsetup 關閉它:

umount /mnt/encryptedvolume
cryptsetup luksClose myencrypted
root@x:~# umount /mnt/encryptedvolume
root@x:~# cryptsetup luksClose myencrypted
root@x:~# cryptsetup stat
root@x:~# cryptsetup status /dev/mapper/myencrypted
/dev/mapper/myencrypted is inactive.
root@x:~# 
驗證加密

現(xiàn)在,嘗試直接讀取加密文件的內容,你應該看到亂碼或者無法解析的數(shù)據(jù),因為文件是加密的:

hexdump -C myencryptedfile

如果你看到的是不可讀的亂碼,那么加密功能正在正常工作。

0017faa0  a8 8f 40 6d e9 e9 26 70  b3 24 1b da e4 52 a6 e3  |..@m..&p.$...R..|
0017fab0  b9 8a 8a 56 52 f9 ca c0  1b 72 1c 7a 4a 2e 30 f8  |...VR....r.zJ.0.|
0017fac0  65 2c 32 9e f5 0f 8d 66  f0 d9 ba ea 74 dc b5 d1  |e,2....f....t...|
0017fad0  d3 35 82 74 1a 3f f4 1d  a8 13 73 2d 09 bb 73 64  |.5.t.?....s-..sd|
0017fae0  51 64 f7 ce 24 ff c4 65  d9 2c 0e 6f 27 f0 09 ff  |Qd..$..e.,.o'...|
root@x:~# cat /mnt/encryptedvolume/testfile.txt
cat: /mnt/encryptedvolume/testfile.txt: No such file or directory
root@x:~# 
重新打開和驗證數(shù)據(jù)

再次打開加密卷并掛載它,然后驗證之前寫入的數(shù)據(jù)是否仍然可以訪問:

cryptsetup luksOpen myencryptedfile myencrypted
mount /dev/mapper/myencrypted /mnt/encryptedvolume
cat /mnt/encryptedvolume/testfile.txt

如果你能正確地讀取之前寫入的消息,那么加密、解密和掛載過程都工作正常。

root@x:~# cat  /mnt/encryptedvolume/testfile.txt
This is a test message.
root@x:~# 

通過以上步驟,你可以驗證 cryptsetup 的加密、解密和掛載功能是否正常工作。

補充

hexdump -C myencryptedfile 為什么是這樣處理來判斷亂碼,不是處理/mnt/encryptedvolume/testfile.txt 來判斷亂碼

使用 hexdump -C myencryptedfile 來判斷亂碼的原因在于,你想要檢查的是原始加密文件的內容,而不是解密后掛載在 /mnt/encryptedvolume 下的文件。

當你對一個文件或分區(qū)進行加密時,其原始內容會被加密算法轉換成看似隨機的、無法直接理解的數(shù)據(jù)。這些加密后的數(shù)據(jù)在沒有正確密鑰和解密過程的情況下看起來就像是亂碼。

因此,通過 hexdump -C myencryptedfile 命令,你可以查看加密文件的十六進制和 ASCII 表示。如果顯示的輸出大部分是不可讀的字符和非打印字符,那么這通常表明文件已經(jīng)被成功加密,并且在沒有解密的情況下無法直接訪問其原始內容。

相比之下,如果你已經(jīng)解密并掛載了加密卷到 /mnt/encryptedvolume,然后在這個掛載點下訪問 testfile.txt,你應該能看到可讀的文本內容,因為文件已經(jīng)在解密過程中被轉換回其原始格式。

所以,使用 hexdump -C myencryptedfile 來判斷亂碼是為了驗證加密文件是否包含預期的加密數(shù)據(jù),而處理 /mnt/encryptedvolume/testfile.txt 則是為了驗證解密和掛載過程是否正常工作。這兩個操作分別用于檢查加密和解密狀態(tài)下的文件內容。

testfile.txt 和 myencryptedfile 的關系是什么

testfile.txtmyencryptedfile 的關系取決于你的具體操作和目標。

在使用加密的上下文中,通常情況下:

  1. 原始未加密文件
    testfile.txt 可能是你想要加密的原始文本文件。它包含可讀的、未加密的數(shù)據(jù)。

  2. 加密后的文件
    myencryptedfile 則是經(jīng)過加密處理后的文件。當你使用 cryptsetup 或其他加密工具對 testfile.txt 進行加密時,加密后的數(shù)據(jù)將被寫入到 myencryptedfile。

在這種情況下,testfile.txtmyencryptedfile 之間的關系就是原始數(shù)據(jù)和加密后數(shù)據(jù)的關系。當你需要訪問 testfile.txt 中的原始內容時,你需要先解密 myencryptedfile,然后將解密后的數(shù)據(jù)恢復到一個新文件或原文件名(如果已刪除原始文件)。

請注意,這只是一個常見的場景示例。在實際應用中,你可能直接對整個分區(qū)或硬盤進行加密,而不是單個文件。在這種情況下,myencryptedfile 將代表整個加密的存儲設備,而 testfile.txt 是存儲在該設備上眾多文件中的一個。
lume,然后在這個掛載點下訪問 testfile.txt`,你應該能看到可讀的文本內容,因為文件已經(jīng)在解密過程中被轉換回其原始格式。

所以,使用 hexdump -C myencryptedfile 來判斷亂碼是為了驗證加密文件是否包含預期的加密數(shù)據(jù),而處理 /mnt/encryptedvolume/testfile.txt 則是為了驗證解密和掛載過程是否正常工作。這兩個操作分別用于檢查加密和解密狀態(tài)下的文件內容。

testfile.txt 和 myencryptedfile 的關系是什么

testfile.txtmyencryptedfile 的關系取決于你的具體操作和目標。

在使用加密的上下文中,通常情況下:

  1. 原始未加密文件
    testfile.txt 可能是你想要加密的原始文本文件。它包含可讀的、未加密的數(shù)據(jù)。

  2. 加密后的文件
    myencryptedfile 則是經(jīng)過加密處理后的文件。當你使用 cryptsetup 或其他加密工具對 testfile.txt 進行加密時,加密后的數(shù)據(jù)將被寫入到 myencryptedfile。

在這種情況下,testfile.txtmyencryptedfile 之間的關系就是原始數(shù)據(jù)和加密后數(shù)據(jù)的關系。當你需要訪問 testfile.txt 中的原始內容時,你需要先解密 myencryptedfile,然后將解密后的數(shù)據(jù)恢復到一個新文件或原文件名(如果已刪除原始文件)。

請注意,這只是一個常見的場景示例。在實際應用中,你可能直接對整個分區(qū)或硬盤進行加密,而不是單個文件。在這種情況下,myencryptedfile 將代表整個加密的存儲設備,而 testfile.txt 是存儲在該設備上眾多文件中的一個。

http://www.risenshineclean.com/news/48890.html

相關文章:

  • 三河建設局網(wǎng)站熱門seo推廣排名穩(wěn)定
  • 網(wǎng)站備案 修改優(yōu)化seo廠家
  • 網(wǎng)站制作 徐州晉江怎么交換友情鏈接
  • 怎樣到國外做合法博彩法網(wǎng)站河南鄭州最新消息
  • 錦州做網(wǎng)站全網(wǎng)營銷與seo
  • 幫別人做設計圖的網(wǎng)站渠道推廣策略
  • 旺旺號查詢網(wǎng)站怎么做百度推廣個人怎么開戶
  • 公司網(wǎng)站怎么做才能有官網(wǎng)二字推廣營銷軟件app
  • 上海網(wǎng)站建設公司介紹seo關鍵詞排名軟件流量詞
  • 免費軟件網(wǎng)站下載深圳靠譜網(wǎng)站建設公司
  • 品牌網(wǎng)站建設的要點培訓心得體會1000字通用
  • wordpress的小程序網(wǎng)站優(yōu)化哪家好
  • iis php服務器搭建網(wǎng)站杭州優(yōu)化外包
  • 國內免費saas crm正在seo sem
  • 愛城市網(wǎng)官方下載武漢網(wǎng)站推廣優(yōu)化
  • wordpress登陸鏈接seo兼職
  • 微信公眾號接口開發(fā)西安seo關鍵詞排名
  • 吉林網(wǎng)站模板系統(tǒng)優(yōu)化助手
  • c 網(wǎng)站開發(fā)商城網(wǎng)站建設
  • 內江市網(wǎng)站建設如何發(fā)布自己的html網(wǎng)站
  • 室內在線設計網(wǎng)站今日最新消息新聞報道
  • 阜陽html5網(wǎng)站建設貴陽做網(wǎng)絡推廣的公司
  • 用php做網(wǎng)站需要什么湖南競價優(yōu)化專業(yè)公司
  • 母嬰網(wǎng)站怎么做百度聯(lián)盟怎么賺錢
  • 溫州網(wǎng)站建設咨詢谷歌app官方下載
  • 太原網(wǎng)站建設信息推薦精準營銷平臺
  • 怎樣用java 做網(wǎng)站泰州百度seo
  • 深圳做網(wǎng)站600新聞源發(fā)稿平臺
  • 臨時工找工作網(wǎng)站做美縫成都網(wǎng)站優(yōu)化排名
  • 好看的網(wǎng)站模板2022當下社會熱點話題