実行中のUbuntuシステムを暗号化されたドライブに転送する

すでに実行中のLinuxオペレーティングシステムを暗号化する方法について説明します。 サイトが既に実行されているサーバー、または多くの個人情報が保存されているサーバーがあるとします。 もちろん、これが間違った手に落ちるのは望ましくありません。 また、サーバーをストレージとして使用する場合、ハードドライブを取り外すときに、このデータを誰かが使用することは望ましくありません。 多くの状況が存在する可能性があります...したがって、コンテンツをprotect索好きな目から保護する必要があります。



新しいUbuntu 12.04を仮想マシンにインストールし、別の1 GBディスク(/ dev / sdb)を追加しました。これに、/ブートフォルダーのあるブートパーティションが転送されます。 前回の記事ですでに書いたように、暗号化されていない要素はブート情報(カーネルイメージ、initramfs、grubなど)だけです。これは、ルートファイルシステムをマウントする前にディスクを復号化するために必要です。

root@test-winxp-ie7d:~# cat /etc/issue Ubuntu 12.04.1 LTS \n \l root@test-winxp-ie7d:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.0G 1.2G 7.4G 14% / udev 486M 4.0K 486M 1% /dev tmpfs 198M 304K 198M 1% /run none 5.0M 0 5.0M 0% /run/lock none 495M 0 495M 0% /run/shm root@test-winxp-ie7d:~# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders, total 20971520 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: 0x000649ec Device Boot Start End Blocks Id System /dev/sda1 * 2048 18874367 9436160 83 Linux /dev/sda2 18876414 20969471 1046529 5 Extended /dev/sda5 18876416 20969471 1046528 82 Linux swap / Solaris Disk /dev/sdb: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 Disk /dev/sdb doesn't contain a valid partition table root@test-winxp-ie7d:~#
      
      







最初に、ディスクをマウントする必要があります。これは、新しいboot-aの役割になり、すべてを/ブートフォルダーからそこに転送します。



 root@test-winxp-ie7d:~# mkfs.ext4 /dev/sdb mke2fs 1.42 (29-Nov-2011) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done root@test-winxp-ie7d:~# mkdir /mnt/newboot root@test-winxp-ie7d:~# mount /dev/sdb /mnt/newboot/ root@test-winxp-ie7d:~# cp -R /boot/* /mnt/newboot/ root@test-winxp-ie7d:~# mv /boot /boot_old root@test-winxp-ie7d:~# mkdir /boot
      
      







この段階で、ブートフォルダーを新しいドライブに移動しました。 ここで、適切にマウントするために必要な設定をfstabに登録する必要があります。



 root@test-winxp-ie7d:~# echo "/dev/sdb /boot ext4 defaults 0 0" >> /etc/fstab
      
      







これで、grub設定を更新し、システムを安全に再起動できます。



 root@test-winxp-ie7d:~# update-grub Generating grub.cfg ... Found linux image: /boot/vmlinuz-3.2.0-29-generic Found initrd image: /boot/initrd.img-3.2.0-29-generic Found memtest86+ image: /memtest86+.bin done root@test-winxp-ie7d:~# grub-install /dev/sda Installation finished. No error reported. root@test-winxp-ie7d:~# reboot root@test-winxp-ie7d:~# Broadcast message from alex@test-winxp-ie7d (/dev/pts/0) at 6:06 ... The system is going down for reboot NOW!
      
      







再起動後、ファイルシステムで何が起こっているのかを確認します。



 root@test-winxp-ie7d:~# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 9.0G 1.2G 7.4G 14% / udev devtmpfs 486M 4.0K 486M 1% /dev tmpfs tmpfs 198M 304K 198M 1% /run none tmpfs 5.0M 0 5.0M 0% /run/lock none tmpfs 495M 0 495M 0% /run/shm /dev/sdb ext4 1021M 71M 900M 8% /boot root@test-winxp-ie7d:~# ls /boot/ abi-3.2.0-29-generic grub lost+found memtest86+_multiboot.bin vmlinuz-3.2.0-29-generic config-3.2.0-29-generic initrd.img-3.2.0-29-generic memtest86+.bin System.map-3.2.0-29-generic
      
      







ご覧のとおり、ブートローダー、カーネルイメージ、およびinitramfsは別のディスクにあります。

次に、ファイルシステム全体を暗号化されたディスクに転送する必要があります。このディスクは/にマウントされます。 これを行うために、/ dev / sda1の代わりに新しいルート(システム)ディスクの役割になる別のディスク(/ dev / sdc)を追加しました。

sdcドライブを暗号化し、マウントしてすべてのファイルを転送します。

 root@test-winxp-ie7d:~# mkdir /mnt/newroot root@test-winxp-ie7d:~# cryptsetup luksFormat /dev/sdc WARNING! ======== This will overwrite data on /dev/sdc irrevocably. Are you sure? (Type uppercase yes): YES Enter LUKS passphrase: Verify passphrase: root@test-winxp-ie7d:~# cryptsetup luksOpen /dev/sdc encryptroot Enter passphrase for /dev/sdc: root@test-winxp-ie7d:~# mkfs -t ext4 /dev/mapper/encryptroot mke2fs 1.42 (29-Nov-2011) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 196608 inodes, 785920 blocks 39296 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=805306368 24 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done root@test-winxp-ie7d:~# mount -t ext4 /dev/mapper/encryptroot /mnt/newroot/
      
      







ここで、fstab、crypttabを変更し、initramfsも更新し、古いルートディスク/ dev / sda1から暗号化されたsdcディスクにすべてを転送します。



 root@test-winxp-ie7d:~# ls -l /dev/disk/by-uuid/ total 0 … lrwxrwxrwx 1 root root 10 Sep 16 06:46 5e5fac1c-080b-437a-96ff-d9e4e3b04759 -> ../../sda1 lrwxrwxrwx 1 root root 9 Sep 16 06:47 d08aab55-a935-4155-aea0-b6fd5da8bed3 -> ../../sdc … root@test-winxp-ie7d:~# cat /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). # # proc /proc proc nodev,noexec,nosuid 0 0 # / was on /dev/sda1 during installation #UUID=5e5fac1c-080b-437a-96ff-d9e4e3b04759 / ext4 errors=remount-ro 0 1 /dev/mapper/encryptroot / ext4 errors=remount-ro 0 1 # swap was on /dev/sda5 during installation UUID=eae26cf5-303a-4c17-ac63-d7dd82891c09 none swap sw 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0 /dev/sdb /boot ext4 defaults 0 0 root@test-winxp-ie7d:~# cat /etc/crypttab # encryptroot UUID=d08aab55-a935-4155-aea0-b6fd5da8bed3 none luks root@test-winxp-ie7d:~# sed -i -e "s|root=UUID=5e5fac1c-080b-437a-96ff-d9e4e3b04759|root=/dev/mapper/encryptroot|" /boot/grub/grub.cfg root@test-winxp-ie7d:~# ln -s /boot/vmlinuz-3.2.0-29-generic /mnt/newroot/vmlinuz root@test-winxp-ie7d:~# update-initramfs -u update-initramfs: Generating /boot/initrd.img-3.2.0-29-generic root@test-winxp-ie7d:~# rsync -aHx / /mnt/newroot root@test-winxp-ie7d:~# rsync -aHx /dev /mnt/newroot/ root@test-winxp-ie7d:~# reboot
      
      







再起動後に次のウィンドウが表示された場合は、すべてうまくいきました。 カーネルパニックになった場合は、コメントを書いて、何が問題で、どのステップで失敗したかを教えてください。

画像



承認後-取得したものを見てみましょう。



 root@test-winxp-ie7d:~# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/encryptroot ext4 3.0G 1.1G 1.8G 38% / udev devtmpfs 485M 4.0K 485M 1% /dev tmpfs tmpfs 198M 312K 198M 1% /run none tmpfs 5.0M 0 5.0M 0% /run/lock none tmpfs 495M 0 495M 0% /run/shm /dev/sdb ext4 1021M 74M 897M 8% /boot root@test-winxp-ie7d:~# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders, total 20971520 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: 0x000649ec Device Boot Start End Blocks Id System /dev/sda1 * 2048 18874367 9436160 83 Linux /dev/sda2 18876414 20969471 1046529 5 Extended /dev/sda5 18876416 20969471 1046528 82 Linux swap / Solaris Disk /dev/sdb: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 Disk /dev/sdb doesn't contain a valid partition table Disk /dev/sdc: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders, total 6291456 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: 0x08040000 Disk /dev/sdc doesn't contain a valid partition table Disk /dev/mapper/encryptroot: 3219 MB, 3219128320 bytes 255 heads, 63 sectors/track, 391 cylinders, total 6287360 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 Disk /dev/mapper/encryptroot doesn't contain a valid partition table root@test-winxp-ie7d:~#
      
      







ご覧のとおり、暗号化されたディスクはルートファイルシステムにマウントされています。 また、古い/ dev / sdaディスクが残っているため、削除できます。

インストール中の暗号化から始まり、luksボリュームのリモートロック解除で終わる、AからZまでのシステムの完全な暗号化に興味がある場合は、 ここですべてを詳しく説明しました



All Articles