Text
Accessing partition inside LVM volume
I accidentally corrupted suders file and wasn’t able to become root again.
Idea Mount guest filesystem’s root partition and correct the mistake.
How to fix sudoers Check partitions $ fdisk -lu
Disk /dev/mapper/vg_decrypted-web01.loc_system: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 1048576 bytes / 1048576 bytes Disklabel type: dos Disk identifier: 0x4f728ef4
Device Boot Start End Sectors Size Id Type /dev/mapper/vg_decrypted-web01.loc_system-part1 63 15623046 15622984 7.5G 83 Linux /dev/mapper/vg_decrypted-web01.loc_system-part2 15624192 19529727 3905536 1.9G 82 Linux swap / Solaris So now I know I need /dev/mapper/vg_decrypted-web01.loc_system-part1 but it’s not mapped.
Run kpartx to create the device mapper entries for these partitions $ kpartx -a /dev/vg_decrypted/web01.loc_system
This will create:
/dev/mapper/vg_decrypted-web01.loc_system1 /dev/mapper/vg_decrypted-web01.loc_system2 Power off the guest and mount filesystem $ mount /dev/mapper/vg_decrypted-web01.loc_system1 /mnt
Edit /etc/sudoers files $ vim /mnt/etc/sudoers
Unmount and remove device mapper entries $ umount /mnt
$ kpartx -d /dev/vg_decrypted/web01.loc_system
Happy! ;-)
0 notes
Text
DDRESCUE to the rescue
On a nice and shiny day, a friend called and said he can’t boot up his notebook anymore.
After he brought the notebook to my place, there was some strange problem with hard drive. Well as a Linux user I had no doubt that I will easily mount his hard drive and get the data out.
But I wasn’t. The drive refused to mount even in read-only mode. So the next thing that came into my mind was ddrescue. Not sure what really happened to the drive as the recovery process went pretty fast, only 6 dead sectors.
How the ddrescue recovery process works Create image with ddrescue $ ddrescue -d -r0 -v /dev/sda4 master_sda4.img master_sda4.log Mount and remove unneeded data $ mount -t ntfs ./master_sda4.img /mnt/master/ Size after data removed
$ df -h /dev/loop0 455G 77G 378G 17% /mnt/master
Unmount $ umount /dev/loop0 Resize partition $ ntfsresize -s 100G -f /media/tom/Bck1/master_sda4.img Partition in the image after removing data was about 77GB. Resizing it to something like 78 would most likely fail, because ntfsresize has to relocate data (same as if you are doing defrag on a full drive - it won’t work). So that’s why I shrinked to 100GB.
ntfsresize v2015.3.14AR.1 (libntfs-3g) Device name : /media/tom/Bck1/master_sda4.img NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 487703179776 bytes (487704 MB) Current device size: 487703183360 bytes (487704 MB) New volume size : 99999998464 bytes (100000 MB)
Some say you need to add 1 sector more, as some tools like cfdisk might think that your partition is outside the boundaries.
Check the sector size $ parted /media/tom/Bck1/master_sda4.img 'print' Model: (file) Disk /media/tom/Bck1/master_sda4.img: 488GB Sector size (logical/physical): 512B/512B Partition Table: loop Disk Flags:
Number Start End Size File system Flags 1 0,00B 488GB 488GB ntfs
It’s 512B in most case. Add it to the size we get from ntfsresize. So my new size is 99999998976B.
Shrink the image file $ truncate --size=99999998976 ./master_sda4.img Mount again and check.
Note. I wasn’t using and ignored output from fdisk, as it was a complete crap. As in my case, I only dumped one partition, that was too much for him I guess.
Disk /dev/loop0: 93,1 GiB, 99999998976 bytes, 195312498 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 Disklabel type: dos Disk identifier: 0x73736572 Device Boot Start End Sectors Size Id Type /dev/loop0p1 1920221984 3736432267 1816210284 866G 72 unknown /dev/loop0p2 1936028192 3889681299 1953653108 931,6G 6c unknown /dev/loop0p3 0 0 0 0B 0 Empty /dev/loop0p4 27722122 27722568 447 223,5K 0 Empty Partition table entries are not in disk order.
You can look at the shrinked partition with gparted
$ gparted /dev/loop0
0 notes
Text
Public key is not available while doing ‘apt update’
Same question over and over again. So how to add the missing public key for APT to work?
The error you might get looks like this:
W: GPG error: http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY C2518248EEA14886 W: The repository 'http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease' is not signed. N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use. N: See apt-secure(8) manpage for repository creation and user configuration details.
To make this work, do:
$ apt-key adv --keyserver keys.gnupg.net --recv-key C2518248EEA14886
Which will produce output like:
Executing: /tmp/apt-key-gpghome.fIvHaUQJg2/gpg.1.sh --keyserver keys.gnupg.net --recv-key C2518248EEA14886 gpg: requesting key EEA14886 from hkp server keys.gnupg.net gpg: key EEA14886: public key "Launchpad VLC" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1)
0 notes
Text
Rsyslogd imuxsock begins to drop messages from pid due to rate limiting
I was setting up filesystem auditing with logger and was getting lots of
rsyslogd-2177: imuxsock begins to drop messages from pid 48885 due to rate-limiting
messages. It appears that rsyslog by default has limit 200 messages per 5 seconds.
You can change the limits or disable by editing (adding) the following lines to /etc/rsyslog.conf
$SystemLogRateLimitInterval 0 $SystemLogRateLimitBurst 200
In my configuration LimitBurst doesn’t mean anything as I have set LimitInterval to 0, which means disabled.
0 notes
Text
MySQL Cheat Sheet
This is meant to be like a MySQL Workbench Snippets
Update table data from other table
UPDATE target INNER JOIN source ON (target.value = source.value) SET target.id = source.id
UPDATE target INNER JOIN source USING (value) SET target.id = source.id
UPDATE target SET id = (SELECT source.id FROM source WHERE target.value = source.value LIMIT 1)
Insert table data from another table
INSERT INTO target (SELECT * FROM source WHERE status=2);
0 notes