{"id":6174,"date":"2012-12-13T16:58:02","date_gmt":"2012-12-13T16:58:02","guid":{"rendered":"https:\/\/noi3.org\/site\/?p=6174"},"modified":"2012-12-13T16:58:02","modified_gmt":"2012-12-13T16:58:02","slug":"shell-script-opens-luks-partition-and-sets-up-a-mapping-mounting-encrypted-partition","status":"publish","type":"post","link":"https:\/\/site.noi3.org\/?p=6174","title":{"rendered":"Shell script: Opens LUKS Partition and Sets Up a Mapping [ Mounting Encrypted Partition ]"},"content":{"rendered":"<p> \tLinux comes with the cryptsetup command. It is used to setup dm-crypt (transparent disk encryption subsystem in Linux kernel) managed device-mapper mappings.<\/p>\n<p>  <!--more-->  <\/p>\n<p> \tLinux comes with the cryptsetup command. It is used to setup dm-crypt (transparent disk encryption subsystem in Linux kernel) managed device-mapper mappings. This shell script can be used to mount dm-crypt based partitions with passphrase:<\/p>\n<blockquote>\n<ul>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\">#!\/bin\/bash<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># A simple shell to <span style=\"color: #c20cb9; font-weight: bold;\">mount<\/span> disk encryption based parition under Linux.<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># Tested on Debian and Ubuntu base NAS servers.<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># &#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;-<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># Written by Vivek Gite &lt;http:\/\/www.cyberciti.biz\/&gt;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># <span style=\"color: #7a0874; font-weight: bold;\">(<\/span>c<span style=\"color: #7a0874; font-weight: bold;\">)<\/span> <span style=\"color: #000000;\">2008<\/span> nixCraft under GNU GPL v2<span style=\"color: #000000;\">.0<\/span>+<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># &#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;-<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># Last updated: <span style=\"color: #000000;\">05<\/span>\/Dec\/<span style=\"color: #000000;\">2011<\/span><\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\"># &#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;-<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t\u00a0<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\">### commands ###<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_crypt=<\/span><span style=\"color: #ff0000;\">&#8222;\/sbin\/cryptsetup&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_vg=<\/span><span style=\"color: #ff0000;\">&#8222;\/sbin\/vgscan&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_vgc=<\/span><span style=\"color: #ff0000;\">&#8222;\/sbin\/vgchange&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_mnt=<\/span><span style=\"color: #ff0000;\">&#8222;\/bin\/mount&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t\u00a0<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\">### SET ME FIRST ###<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\">### Partition specific settings ###<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #808080; font-style: italic;\">### SET ME FIRST ###<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_device=<\/span><span style=\"color: #ff0000;\">&#8222;\/dev\/md3&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_name=<\/span><span style=\"color: #ff0000;\">&#8222;securebackup&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_mnts=<\/span><span style=\"color: #ff0000;\">&#8222;\/dev\/cryptvg\/mybackup &#8222;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">_mntd=<\/span><span style=\"color: #ff0000;\">&#8222;\/securebackup\/&#8221;<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t\u00a0<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #7a0874; font-weight: bold;\">echo<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_crypt<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span> luksOpen <span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_device<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span> <span style=\"color: #007800;\">$_name<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t\u00a0<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #7a0874; font-weight: bold;\">echo<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_vg<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span> &#8211;mknodes<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_vgc<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span> -ay<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t\u00a0<\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #7a0874; font-weight: bold;\">echo<\/span><\/div>\n<\/li>\n<li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\">\n<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\t\t<span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_mnt<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span> <span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_mnts<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span> <span style=\"color: #007800;\">$<span style=\"color: #7a0874; font-weight: bold;\">{<\/span>_mntd<span style=\"color: #7a0874; font-weight: bold;\">}<\/span><\/span><\/div>\n<\/li>\n<\/ul>\n<div style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;font-family: 'Courier New', Courier, monospace; font-weight: normal;\"> \t\t\u00a0<\/div>\n<\/blockquote>\n<div style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;font-family: 'Courier New', Courier, monospace; font-weight: normal;\">\n<p> \t\tThis script is stored on our nas server. All backups are on RAID-6 disks are encrypted. The nas server is online 24&#215;7. After rebooting the server you need to run this script to mount the dm-crypt based partition. A sample session is as follows:<\/p>\n<blockquote>\n<p> \t\t\t<code>$ ssh vivek@nas112.backup.lan.nixcraft.co.in<br \/> \t\t\t$ sudo \/usr\/local\/sbin\/mount.crypt<\/code><\/p>\n<\/blockquote>\n<p> \t\tSample outputs:<\/p>\n<blockquote>\n<pre> Enter passphrase for \/dev\/md3:   Reading all physical volumes.  This may take a while...   Found volume group \"cryptvg\" using metadata type lvm2   1 logical volume(s) in volume group \"cryptvg\" now active <\/pre>\n<\/blockquote>\n<p> \t\tVerify disk space and newly mounted partition:<\/p>\n<blockquote>\n<p> \t\t\t<code>$ df -H<\/code><\/p>\n<\/blockquote>\n<p> \t\tSample outputs:<\/p>\n<blockquote>\n<pre> Filesystem             Size   Used  Avail Use% Mounted on \/dev\/md0               127G   930M   120G   1% \/ tmpfs                  1.1G      0   1.1G   0% \/lib\/init\/rw udev                   1.1G   267k   1.1G   1% \/dev tmpfs                  1.1G      0   1.1G   0% \/dev\/shm \/dev\/md2               1.6T    88G   1.5T   6% \/data \/dev\/mapper\/cryptvg-mybackup                        635G    59G   544G  10% \/securebackup <\/pre>\n<\/blockquote><\/div>\n<p> \t\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux comes with the cryptsetup command. It is used to setup dm-crypt (transparent disk encryption subsystem in Linux kernel) managed device-mapper mappings.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[180,1108,1107,1106],"class_list":["post-6174","post","type-post","status-publish","format-standard","hentry","category-informatica","tag-cript","tag-disk","tag-mount","tag-script"],"_links":{"self":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/6174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6174"}],"version-history":[{"count":0,"href":"https:\/\/site.noi3.org\/index.php?rest_route=\/wp\/v2\/posts\/6174\/revisions"}],"wp:attachment":[{"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/site.noi3.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}