Have a VM disk image that you need to pull a few files from, but you don't want to spin it up into a VM? Here's the simplest way I've found to get at the files inside it:
First, convert whatever format it's in to .raw using qemu-img - you'll need a good bit of disk space for this to work. If your source virtual disk is a qcow2, for example, the command might look like this:
me@box$ qemu-img convert -f qcow2 -O raw var/lib/libvirt/images/own.qcow2 /mnt/thevault/everything/backups/own.raw
Then find the offset of the primary partition inside the image with fdisk:
me@box$ fdisk -l /mnt/thevault/everything/backups/own.raw
Disk /mnt/thevault/everything/backups/own.raw: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x0008fa87
Device Boot Start End Blocks Id System
/mnt/thevault/everything/backups/own.raw1 * 2048 40136703 20067328 83 Linux
/mnt/thevault/everything/backups/own.raw2 40138750 41940991 901121 5 Extended
/mnt/thevault/everything/backups/own.raw5 40138752 41940991 901120 82 Linux swap / Solaris
The partition we are interested in is raw1, the Linux (type 83) partition. If you installed Debian on the disk and went with standard default partitioning options, putting everything under / in the same partition, yours will be the same.
Pull your unit size from the output as well, which in this case is 512 bytes, and then multiply that by the start sector (2048) to get 1048576.
Now we mount the .img file as a loopback device, starting with our calculated offset:
me@box$ mount -o loop,offset=1048576 /mnt/thevault/everything/backups/own.raw /mnt/own
And now you can access your files inside the old VM disk! Don't forget to clean up, now.
Monday, October 27, 2014
Wednesday, October 1, 2014
systemd hate - console autologin on Jessie
Quick tip - systemd sucks.
Just kidding, I actually have no opinion on the matter. I haven't noticed much of a difference yet, except that all the old snippets I find on the internet seem to apply mostly to sysv, and from what I hear, grepping over all of /var/log won't return systemd log results, as they're a binary format.
But I'm a fan of progress, and if systemd fixes some obscure problems deep inside Linux that will eventually bubble up and result in better stuff in my world, then I'm all for it.
The one particular problem I was looking to solve was how to autologin at the console. Arch's wiki was helpful in this regard. Unfortunately for me, I failed to realize that Arch and Debian Jessie are different distros, and so when I rebooted to test my console autologin, I instead got a blinking cursor on an empty, unresponsive screen shortly after the kernel messages began their scroll.
After some live booting and poking around, I came to the realization that while agetty is at /usr/bin/ on Arch, it's at /sbin on Debian. Quick fix, problem solved.
Here's all you have to do to get autologin on Debian Jessie:
Then, inside the file type this stuff, substituting $username for the name of the user you want to be automatically logged in:
If you're actually typing, note the tricky little dash in front of the agetty path, that matters. Enjoy not having to type two dozen characters the once a year you actually use that physical console on your server!
Just kidding, I actually have no opinion on the matter. I haven't noticed much of a difference yet, except that all the old snippets I find on the internet seem to apply mostly to sysv, and from what I hear, grepping over all of /var/log won't return systemd log results, as they're a binary format.
But I'm a fan of progress, and if systemd fixes some obscure problems deep inside Linux that will eventually bubble up and result in better stuff in my world, then I'm all for it.
The one particular problem I was looking to solve was how to autologin at the console. Arch's wiki was helpful in this regard. Unfortunately for me, I failed to realize that Arch and Debian Jessie are different distros, and so when I rebooted to test my console autologin, I instead got a blinking cursor on an empty, unresponsive screen shortly after the kernel messages began their scroll.
After some live booting and poking around, I came to the realization that while agetty is at /usr/bin/ on Arch, it's at /sbin on Debian. Quick fix, problem solved.
Here's all you have to do to get autologin on Debian Jessie:
root@serv$ mkdir -pv /etc/systemd/system/getty@tty1.service.d/ root@serv$ vi /etc/systemd/system/getty@tty1.service.d/autologin.conf
Then, inside the file type this stuff, substituting $username for the name of the user you want to be automatically logged in:
[Service] ExecStart= ExecStart=-/sbin/agetty --autologin $username --noclear %I 38400 linux
If you're actually typing, note the tricky little dash in front of the agetty path, that matters. Enjoy not having to type two dozen characters the once a year you actually use that physical console on your server!
Subscribe to:
Posts (Atom)