15 managing disk - creating encrypted partition partprobe

[root@svn ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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 label type: dos
Disk identifier: 0xf12de6be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux

Command (m for help):

#sectors 10485760  and 206847  means there is free capacity

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2):
First sector (206848-10485759, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-10485759, default 10485759): +100M
Partition 2 of type Linux and of size 100 MiB is set

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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 label type: dos
Disk identifier: 0xf12de6be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      411647      102400   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@svn ~]#

#to update kernel partition we use
partprobe

[root@svn ~]# partprobe /dev/sdb
[root@svn ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0   31457280 sda
   8        1    1048576 sda1
   8        2   19921920 sda2
   8       16    5242880 sdb
   8       17     102400 sdb1
   8       18     102400 sdb2
  11        0    8086528 sr0
 253        0   17821696 dm-0
 253        1    2097152 dm-1
[root@svn ~]# 


[root@svn ~]# partprobe /dev/sdb
[root@svn ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0   31457280 sda
   8        1    1048576 sda1
   8        2   19921920 sda2
   8       16    5242880 sdb
   8       17     102400 sdb1
   8       18     102400 sdb2
  11        0    8086528 sr0
 253        0   17821696 dm-0
 253        1    2097152 dm-1
[root@svn ~]# 


OPEN PARTITION

[root@svn ~]# cryptsetup luksFormat /dev/sdb2

WARNING!
========
This will overwrite data on /dev/sdb2 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 
[root@svn ~]# mkdir /secret
[root@svn ~]# cryptsetup luksOpen /dev/sdb2 secretename
Enter passphrase for /dev/sdb2: 
[root@svn ~]# 

[root@svn ~]# cd /dev/mapper/
[root@svn mapper]# ls
cl-root  cl-swap  control  secretename
[root@svn mapper]# 

[root@svn mapper]# mkfs.ext4 /dev/mapper/secretename 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25168 inodes, 100352 blocks
5017 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1936 inodes per group
Superblock backups stored on blocks: 
8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@svn mapper]# 


[root@svn mapper]# mount /dev/mapper/secretename /secret/
[root@svn mapper]# 

[root@svn mapper]# dmsetup status
cl-swap: 0 4194304 linear 
cl-root: 0 35643392 linear 
secretename: 0 200704 crypt 

In order to close device
[root@svn mapper]# umount /secret/
[root@svn mapper]# ls /dev/mapper/
cl-root  cl-swap  control  secretename

[root@svn mapper]# cryptsetup luksClose /dev/mapper/secretename 
[root@svn mapper]# ls /dev/mapper/
cl-root  cl-swap  control

vim /etc/fstab
vim /etc/crypttab
reboot







Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all