Ubuntu/Linux

Server Upgrade

Find Used and Free RAM Info Command

You need to use the free command: $ free
$ free -m

Find Out Ram Speed, Make, Form Factor, Type and Other Information. You need to use the dmidecode command:

$ dmidecode --type 17

You can backup your harddrive with dd:

$ dd if=/dev/sda of=/somedir/sda.img bs=1M

If you run ```file''' against the image file you made, you should see something like this:


$file harddrive.img
harddrive.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2
address 0x2000, stage2 segment 0x200, GRUB version 0.97; partition 1: ID=0x83,
active, starthead 1, startsector 63, 33640047 sectors, code offset 0x48

What if you want to pull some files from this image without writing it out to another disk? Mounting it like a loop file isn’t going to work:

$ mount harddrive /mnt/temp
mount: you must specify the filesystem type

The key is to mount the file with an offset specified. In the output from file, there is a particular portion of the output that will help you:

... startsector 63 ...

This means that the filesystem itself starts on sector 63. You can also view this with fdisk -l:

$ fdisk -l harddrive.img
Device Boot Start End Blocks Id System
harddrive.img * 63 33640109 16820023+ 83 Linux

Since we need to scoot 63 sectors ahead, and each sector is 512 bytes long, we need to use an offset of 32,256 bytes. Fire up the mount command and you’ll be on your way:

$ mount -o ro,loop,offset=32256 harddrive.img /mnt/loop

How do I change the UUID? This isn’t hard at all. First find the device path, and you can find the device path using the following command:

$ sudo blkid

Your output will look something like this:

$sudo blkid
/dev/sdb1: UUID="aabe7e48-2d11-421f-8609-7ea9d75e7f9b" TYPE="swap"
/dev/sdc1: UUID="9467f4de-4231-401f-bcaa-fee718d49e85" TYPE="ext4"
/dev/sdc3: UUID="93a54a4a-e0f5-4152-ae59-2245e8d16ee4" TYPE="ext4"
/dev/sde5: UUID="9467f4de-4231-401f-bcaa-fee718d49e85" TYPE="ext4"
/dev/sde6: LABEL="var" UUID="30433f28-1b79-4b4d-9985-fef5b1c886b5" TYPE="ext4"

Here you can see that /dev/sdc1 and /dev/sde5 have the same UUID. The path of the partition I want to change is /dev/sde5.

Secondly, generate a UUID. This is simple, the following command will output a UUID like below:

$ uuidgen
f0acce91-a416-474c-8a8c-43f3ed3768f9

Finally apply the new UUID to the partition. This is also another command, tune2fs, which will apply our new UUID to our device path:

$sudo tune2fs /dev/sde5 -U f0acce91-a416-474c-8a8c-43f3ed3768f9

Done, now you can update your grub to include the correct UUID’s to reduce any risk of your system confusing the partitions.

To create a swap partition after installation, create an empty partition that should have no holes. You can then format this partition with:

$sudo mkswap /dev/sdX

replacing /dex/sdX with your partition. Mount this partition as swap with

$sudo swapon -U UUID

where UUID is that of your /dev/sdX as read from this:

$blkid /dev/sdX

Bind your new swap in /etc/fstab by adding this line:

UUID=xxx none swap sw 0 0

If you want to use your swap for hibernating then you need to update the UUID in

/etc/initramfs-tools/conf.d/resume

with this content

RESUME=UUID=xxx

Don't forget to

$ sudo update-initramfs -u.

To complete things: it would also be possible to create a swap file in case we do not have a spare partition. This answer gives you an idea on how to create such a file and enable it on boot.

Clone special directories using rsync (alternatively you can just create empty dirs with mkdir)

$rsync -vd /sys /mnt/newroot/sys
$rsync -vd /proc /mnt/newroot/proc
$rsync -vd /dev /mnt/newroot/dev
$rsync -vd /tmp /mnt/newroot/tmp

Mount special dirs

$mount -t proc proc /mnt/newroot/proc
$mount -t sysfs sysfs /mnt/newroot/sys
$mount -t devtmpfs devtmpfs /mnt/newroot/dev

Copy root using rsync, excluding special dirs and /mnt.

$ update-grub
$ grub-install --recheck /dev/sdb
$ update-grub

How To Backup “crontab -e” Files?

You could just backup the entire /var/spool/cron directory. It contains all crontables of all users and more.

Hot to change the temporary server name and IP address? change these three files:

/etc/network/interfaces
/etc/hostname
/etc/hosts

where you should change the network config and hostname+alias.

Instalation of Ubuntu

SSH Tunnel

Existem muitas páginas na internet (a maioria confusa ou errada mesmo) falando sobre como fazer uma conexão ssh através de um tunel em outra máquina. A melhor que encontrei foi essa aqui. Fiz um tutorial rápido de como fazer isso está aqui:

SSH Tunnel

VNC + SSH Tunnel

Existem muitas páginas na internet que mostram como acessar uma máquina com VNC usando uma conexão segura do tipo SSH. Entretanto quase ninguém explica como fazer isso através de um firewall.

Tutorial VNC + SSH Tunnel

NFS + UFW Firewall

Outro tópico bem confuso, então aqui vai mais um tutorial:

Tutorial NFS UFW

Page last modified on June 19, 2015, at 03:02 PM
Powered by PmWiki