- فرض کنید یک هارد دیسک دوم به سیستم اضافه کردهاید
- مسیر این هارد دیسک دوم به صورت dev/sdb/ است.
- به منظور رمزنگاری این هارد دیسک دوم توسط استاندارد luks از پکیج cryptsetup استفاده میکنیم.
- به صورت پیشفرض این بسته بر روی اکثر توزیعها نصب است.
- با توجه به این که فرض شده است هارد دیسک دوم به صورت خادم و نو به سیستم متصل شده است، لذا باید عمل پارتیشنبندی را روی آن در نظر گرفت.
- فرض ما بر این است که یک پارتیشن برای این هارد دیسک دوم در نظر بگیریم.
- برای این منظور از fdisk استفاده میکنیم.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# fdisk /dev/sdb Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x213b6805. Command (m for help): <span style="color: #ff0000;"><strong>n</strong></span> Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p):<span style="color: #ff0000;"><strong> p</strong></span> Partition number (1-4, default 1): <span style="color: #ff0000;"><strong>1</strong></span> First sector (2048-16777215, default 2048): <span style="color: #ff0000;"><strong>2048</strong></span> Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-16777215, default 16777215): <span style="color: #ff0000;"><strong>16777215</strong></span> Created a new partition 1 of type 'Linux' and of size 8 GiB. Command (m for help): <span style="color: #ff0000;"><strong>w</strong></span> The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. |
- به منظور بررسی پارتیشن ساخته شده به صورت زیر عمل نمایید.
|
1 2 3 4 5 |
# fdisk -l /dev/sdb1 Disk /dev/sdb1: 7.102 GiB, 8588886016 bytes, 16775168 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 |
- به منظور بررسی پارتیشن ساخته شده به صورت زیر عمل نمایید.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 55.3M 1 loop /snap/core18/1885 loop1 7:1 0 55.4M 1 loop /snap/core18/1932 loop2 7:2 0 70.6M 1 loop /snap/lxd/16926 loop3 7:3 0 29.9M 1 loop /snap/snapd/8790 loop4 7:4 0 69.8M 1 loop /snap/lxd/18402 loop5 7:5 0 31M 1 loop /snap/snapd/9721 sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1M 0 part └─sda2 8:2 0 40G 0 part / <span style="color: #ff0000;"><strong>sdb 8:16 0 8G 0 disk </strong></span> <span style="color: #ff0000;"><strong>└─sdb1 8:17 0 8G 0 part</strong></span> |
- به منظور رمزنگاری دیسک به صورت زیر عمل نمایید.
|
1 2 3 4 5 6 7 8 9 |
# cryptsetup -y luksFormat /dev/sdb1 WARNING! ======== This will overwrite data on /dev/sdb1 irrevocably. Are you sure? (Type uppercase yes): <span style="color: #ff0000;"><strong>YES</strong></span> Enter passphrase for /dev/sdb1: Verify passphrase: |
- به منظور رمزگشایی دیسک به صورت زیر عمل نمایید.
|
1 2 |
# cryptsetup luksOpen /dev/sdb1 <span style="color: #ff0000;"><strong>secretfs1</strong></span> Enter passphrase for /dev/sdb1: |
- عبارت secretfs1 نامی است که به منظور MAP شدن مسیر dev/sdb1/ به درون پروندهای با نام secretfs1 در مسیر dev/mapper/ استفاده میشود.
- با اجرای دستور بالا ، هارد دیسک dev/sdb1/ به مسیر dev/mapper/secretfs1/ مپ (MAP) میشود.
- عبارت secretfs1 متغیر میباشد.
- به منظور بررسی دیواس Map شده به صورت زیر عمل نمایید.
|
1 2 3 4 5 6 7 8 9 10 11 |
# cryptsetup status secretfs1 /dev/mapper/secretfs1 is active. type: LUKS2 cipher: aes-xts-plain64 keysize: 512 bits key location: keyring device: /dev/sdb1 sector size: 512 offset: 32768 sectors size: 16742400 sectors mode: read/write |
- حال دیسک ما آمادهی فرمت و تخصیص File System بر روی آن است.
- به عبارت دیگر حال باید برای dev/mapper/secretfs1/ فایل سیستم در نظر گرفته باشیم.
|
1 2 3 4 5 6 7 8 9 10 11 |
# mkfs -t ext3 /dev/mapper/secretfs1 mke2fs 1.45.5 (07-Jan-2020) Creating filesystem with 2092800 4k blocks and 523264 inodes Filesystem UUID: d595f6b1-f188-4a55-8d40-9b958934e7e5 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done |
- به منظور بررسی بیشتر فایل سیستم در نظر گرفته شده به صورت زیر عمل نمایید.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# tune2fs -l /dev/mapper/secretfs1 tune2fs 1.45.5 (07-Jan-2020) Filesystem volume name: <none> Last mounted on: <not available> Filesystem UUID: d595f6b1-f188-4a55-8d40-9b958934e7e5 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype sparse_super large_file Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 523264 Block count: 2092800 Reserved block count: 104640 Free blocks: 2038953 Free inodes: 523253 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 510 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8176 Inode blocks per group: 511 Filesystem created: Tue Dec 1 09:47:01 2020 Last mount time: n/a Last write time: Tue Dec 1 09:47:03 2020 Mount count: 0 Maximum mount count: -1 Last checked: Tue Dec 1 09:47:01 2020 Check interval: 0 (<none>) Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: 4a234552-0ca3-46ee-9ee5-98c121d2326b Journal backup: inode blocks |
- به منظور Mount کردن دیسک Map شده به صورت زیر عمل نمایید.
|
1 2 3 4 |
# mkdir -p /mnt/secretfs1 root@ubuntu:~# mount /dev/mapper/secretfs1 /mnt/secretfs1 root@ubuntu:~# ls /mnt/secretfs1 lost+found |
- به منظور رمزنگاری مجدد دیسک کافیست ابتدا اتصال Mount را قطع کرده سپس دیسک را Close کنید.
|
1 2 |
# umount /mnt/secretfs1 # cryptsetup luksClose secretfs1 |